Browse Source

refactoring: revise comments

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
12168dd057
  1. 19
      src/main/c/Georg/tictactoe.c

19
src/main/c/Georg/tictactoe.c

@ -129,6 +129,7 @@ int startMenu( int code ){
} }
void printBoard(){ void printBoard(){
// calculate the size of the board and print the upper frame
for( int i = 0; i < BORAD_SIZE*4+1; i++ ){ for( int i = 0; i < BORAD_SIZE*4+1; i++ ){
printf("-"); printf("-");
} }
@ -147,6 +148,7 @@ void printBoard(){
printf( "\n" ); printf( "\n" );
} }
// calculate the size of the board and print the upper frame
for( int i = 0; i < BORAD_SIZE*4+1; i++ ){ for( int i = 0; i < BORAD_SIZE*4+1; i++ ){
printf("-"); printf("-");
} }
@ -165,8 +167,8 @@ int* getMarkerParameters( char* input ){
int firstArgument = input[index-1] - '0'; int firstArgument = input[index-1] - '0';
int secondArgument = 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; return array;
} }
@ -195,9 +197,9 @@ void handleGame(){
// gameCommand processing // gameCommand processing
if( gameCommand == 1 ) { // set marker in field 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(); printBoard();
@ -211,17 +213,16 @@ void handleGame(){
bool playerHasWon( bool board[BORAD_SIZE][BORAD_SIZE]){ bool playerHasWon( bool board[BORAD_SIZE][BORAD_SIZE]){
bool player = 1; bool player = 1;
// Überprüfe Zeilen und Spalten
for (int i = 0; i < 3; i++) { 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) || 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)) { (board[0][i] == player && board[1][i] == player && board[2][i] == player)) {
return true; // Spieler hat gewonnen 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) || 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)) { (board[0][2] == player && board[1][1] == player && board[2][0] == player)) {
return true; // Spieler hat gewonnen return true; // Spieler hat gewonnen

Loading…
Cancel
Save