Browse Source

Merge branch 'Ariana' into 'main'

refactoring: correct the errors

See merge request pmuw_projekt/pmuw_projekt_notebinder!26
remotes/origin/fdai7775-main-patch-54732
fdai7775 11 months ago
parent
commit
d2ecf296f7
  1. 9
      src/main/c/GameTic_Tac_Toe/game.c

9
src/main/c/GameTic_Tac_Toe/game.c

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
const int BOARD_SIZE = 3;
char board[3][3] = {{'1', '2', '3'}, char board[3][3] = {{'1', '2', '3'},
{'4', '5', '6'}, {'4', '5', '6'},
{'7', '8', '9'}}; {'7', '8', '9'}};
@ -52,8 +53,6 @@ char checkWinner() {
} }
// Funktion zur Überprüfung, ob das Spiel unentschieden ist // Funktion zur Überprüfung, ob das Spiel unentschieden ist
const int BOARD_SIZE = 3;
int isBoardFull() { int isBoardFull() {
for (int i = 0; i < BOARD_SIZE; i++) { for (int i = 0; i < BOARD_SIZE; i++) {
for (int j = 0; j < BOARD_SIZE; j++) { for (int j = 0; j < BOARD_SIZE; j++) {
@ -67,7 +66,7 @@ int isBoardFull() {
// Funktion zum Zug eines Spielers // Funktion zum Zug eines Spielers
enum switchPlayer(enum currentPlayer) {
char switchPlayer(char currentPlayer) {
return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X;
} }
@ -80,14 +79,14 @@ int isValidMove(int choice) {
void makeMove() { void makeMove() {
int choice; int choice;
printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O');
printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O');
scanf("%d", &choice); scanf("%d", &choice);
// Konvertiere die Zahl in Zeilen- und Spaltenindex // Konvertiere die Zahl in Zeilen- und Spaltenindex
if (isValidMove(choice)) { if (isValidMove(choice)) {
int row = (choice - 1) / BOARD_SIZE; int row = (choice - 1) / BOARD_SIZE;
int col = (choice - 1) % BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE;
board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O';
board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O';
currentPlayer = switchPlayer(currentPlayer); currentPlayer = switchPlayer(currentPlayer);
} else { } else {

Loading…
Cancel
Save