diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 0818463..241ee34 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -129,6 +129,7 @@ int startMenu( int code ){ } void printBoard(){ + // calculate the size of the board and print the upper frame for( int i = 0; i < BORAD_SIZE*4+1; i++ ){ printf("-"); } @@ -147,6 +148,7 @@ void printBoard(){ printf( "\n" ); } + // calculate the size of the board and print the upper frame for( int i = 0; i < BORAD_SIZE*4+1; i++ ){ printf("-"); } @@ -165,8 +167,8 @@ int* getMarkerParameters( char* input ){ int firstArgument = input[index-1] - '0'; int secondArgument = input[index+1] - '0'; - array[0] = firstArgument-1; - array[1] = secondArgument-1; + array[0] = firstArgument-1; // return x + array[1] = secondArgument-1; // return y return array; } @@ -195,9 +197,9 @@ void handleGame(){ // gameCommand processing if( gameCommand == 1 ) { // set marker in field - int* params = getMarkerParameters( input ); - setBoardMarker( GAME.board, params ); - free(params); + int* params = getMarkerParameters( input ); // get the x and y values + setBoardMarker( GAME.board, params ); // apply the x and y values in the field + free(params); // prent memory leakage printBoard(); @@ -211,17 +213,16 @@ void handleGame(){ bool playerHasWon( bool board[BORAD_SIZE][BORAD_SIZE]){ bool player = 1; - // Überprüfe Zeilen und Spalten for (int i = 0; i < 3; i++) { - // Überprüfe Zeilen + // check the rows if ((board[i][0] == player && board[i][1] == player && board[i][2] == player) || - // Überprüfe Spalten + // check the columns (board[0][i] == player && board[1][i] == player && board[2][i] == player)) { return true; // Spieler hat gewonnen } } - // Überprüfe Diagonalen + // check the diagonal line if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) || (board[0][2] == player && board[1][1] == player && board[2][0] == player)) { return true; // Spieler hat gewonnen