From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp | 385 +++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp (limited to 'Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp') diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp new file mode 100644 index 0000000..0b9693d --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp @@ -0,0 +1,385 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 14.01.2005 +// File: tictactoe.cpp +// Description: Implementation of class TicTacToe + +#include "tictactoe.h" +#include +#include +#include +using std::cout; +using std::endl; +using std::cin; + +TicTacToe::TicTacToe() +:nrFields(9) +{ + for (int i=0;i (i+49); + winner=""; + round=0; +} + +TicTacToe::~TicTacToe() +{ + cout << endl << "Game Over!" << endl; +} + +void TicTacToe::eraseField() +{ + for (int i=0;i> input; + switch (input) + { + case 'p': + case 'P': + nextPlayer="Player"; + break; + case 'c': + case 'C': + nextPlayer="Computer"; + break; + default: + cout << endl << "Bad selection! Enter new selection: "; + } + } while (input!='P' && input!='C' && input!='p' && input!='c'); +} +void TicTacToe::movePlayer() +{ + int draw=0; + cout << endl << "Enter your move: "; + //print(); + cin >> draw; + while (testField(draw-1)) + { + cout << endl << "Irregular move... please enter a new one" << endl; + cin >> draw; + } + field[draw-1]='X'; + setNext("Computer"); + round++; +} + +int TicTacToe::testField(int f) +{ + if (field[f]==' ') + return 0; + else + return 1; +} + +void TicTacToe::moveComputer() +{ + int move=4; + int vertX[3]={0}; + int horX[3]={0}; + int diagX[2]={0}; + int vertO[3]={0}; + int horO[3]={0}; + int diagO[2]={0}; + int n=0, + x=0, + y=0, + d=0; + + if (testField(move)) + { + while(testField(n) && n