|
|
@ -9,15 +9,15 @@ |
|
|
|
#define ANSI_COLOR_RESET "\x1b[0m" |
|
|
|
|
|
|
|
int Runde = 1; |
|
|
|
// Funktion, um das Spielfeld zu initialisieren |
|
|
|
void initializeBoard(char Feld[3][3]) { |
|
|
|
// Funktion, um das Spielboard zu initialisieren |
|
|
|
void initializeBoard(char board[3][3]) { |
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
for (int j = 0; j < 3; j++) { |
|
|
|
Feld[i][j] = '_'; |
|
|
|
board[i][j] = '_'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
void Bild(char Feld[3][3]) { |
|
|
|
void Bild(char board[3][3]) { |
|
|
|
#ifdef _WIN32 |
|
|
|
system("cls"); |
|
|
|
#else |
|
|
@ -25,26 +25,26 @@ void Bild(char Feld[3][3]) { |
|
|
|
#endif |
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
for (int j = 0; j < 3; j++) { |
|
|
|
if (Feld[i][j] == '_') { |
|
|
|
printf(ANSI_COLOR_BRIGHT_YELLOW"%c "ANSI_COLOR_RESET, Feld[i][j]); |
|
|
|
if (board[i][j] == '_') { |
|
|
|
printf(ANSI_COLOR_BRIGHT_YELLOW"%c "ANSI_COLOR_RESET, board[i][j]); |
|
|
|
} |
|
|
|
else if (Feld[i][j] == 'X') { |
|
|
|
printf(ANSI_COLOR_BRIGHT_CYAN"%c "ANSI_COLOR_RESET, Feld[i][j]); |
|
|
|
else if (board[i][j] == 'X') { |
|
|
|
printf(ANSI_COLOR_BRIGHT_CYAN"%c "ANSI_COLOR_RESET, board[i][j]); |
|
|
|
} |
|
|
|
else { |
|
|
|
printf(ANSI_COLOR_BRIGHT_RED"%c "ANSI_COLOR_RESET, Feld[i][j]); |
|
|
|
printf(ANSI_COLOR_BRIGHT_RED"%c "ANSI_COLOR_RESET, board[i][j]); |
|
|
|
} |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int Winner(char Feld[3][3]) { |
|
|
|
int Winner(char board[3][3]) { |
|
|
|
// Überprüfen Sieg |
|
|
|
// Überprüfen Reihen |
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
if (Feld[i][0] == Feld[i][1] && Feld[i][1] == Feld[i][2] && Feld[i][0] != '_') { |
|
|
|
if (Feld[i][0] == 'X') { |
|
|
|
if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != '_') { |
|
|
|
if (board[i][0] == 'X') { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
else return 2; |
|
|
@ -52,17 +52,17 @@ int Winner(char Feld[3][3]) { |
|
|
|
} |
|
|
|
// Überprüfen Spalten |
|
|
|
for (int j = 0; j < 3; j++) { |
|
|
|
if (Feld[0][j] == Feld[1][j] && Feld[1][j] == Feld[2][j] && Feld[0][j] != '_') { |
|
|
|
if (Feld[0][j] == 'X') { |
|
|
|
if (board[0][j] == board[1][j] && board[1][j] == board[2][j] && board[0][j] != '_') { |
|
|
|
if (board[0][j] == 'X') { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
else return 2; |
|
|
|
} |
|
|
|
} |
|
|
|
// Überprüfen Diagonalen |
|
|
|
if ((Feld[0][0] == Feld[1][1] && Feld[1][1] == Feld[2][2]) || (Feld[0][2] == Feld[1][1] && Feld[1][1] == Feld[2][0])) { |
|
|
|
if (Feld[1][1] != '_') { |
|
|
|
if (Feld[1][1] == 'X') { |
|
|
|
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0])) { |
|
|
|
if (board[1][1] != '_') { |
|
|
|
if (board[1][1] == 'X') { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
else return 2; |
|
|
@ -71,7 +71,7 @@ int Winner(char Feld[3][3]) { |
|
|
|
//Überprüfe Runde |
|
|
|
for (int k = 0; k < 3; k++) { |
|
|
|
for (int l = 0; l < 3; l++) { |
|
|
|
if (Feld[k][l] == '_') { |
|
|
|
if (board[k][l] == '_') { |
|
|
|
return 9; |
|
|
|
} |
|
|
|
} |
|
|
@ -80,11 +80,11 @@ int Winner(char Feld[3][3]) { |
|
|
|
printf("Es ist ein Unendschieden\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
void Zuege(char Feld[3][3], int row, int col) { |
|
|
|
void Zuege(char board[3][3], int row, int col) { |
|
|
|
if (Runde < 10) { |
|
|
|
if (Runde % 2 == 0) { |
|
|
|
if (Feld[row][col] == '_') { |
|
|
|
Feld[row][col] = 'O'; |
|
|
|
if (board[row][col] == '_') { |
|
|
|
board[row][col] = 'O'; |
|
|
|
} |
|
|
|
else { |
|
|
|
printf("Das Feld ist schon besetzt. Gib ein anderes Feld ein:\n"); |
|
|
@ -94,12 +94,12 @@ void Zuege(char Feld[3][3], int row, int col) { |
|
|
|
scanf("%d", &col); |
|
|
|
row -= 1; |
|
|
|
col -= 1; |
|
|
|
Zuege(Feld, row, col); |
|
|
|
Zuege(board, row, col); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if (Feld[row][col] == '_') { |
|
|
|
Feld[row][col] = 'X'; |
|
|
|
if (board[row][col] == '_') { |
|
|
|
board[row][col] = 'X'; |
|
|
|
} |
|
|
|
else { |
|
|
|
printf("Das Feld ist schon besetzt. Gib ein anderes Feld ein:\n"); |
|
|
@ -109,7 +109,7 @@ void Zuege(char Feld[3][3], int row, int col) { |
|
|
|
scanf("%d", &col); |
|
|
|
row -= 1; |
|
|
|
col -= 1; |
|
|
|
Zuege(Feld, row, col); |
|
|
|
Zuege(board, row, col); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -118,7 +118,7 @@ void Zuege(char Feld[3][3], int row, int col) { |
|
|
|
int mainx() { |
|
|
|
int row; |
|
|
|
int col; |
|
|
|
char Feld[3][3]; |
|
|
|
char board[3][3]; |
|
|
|
char Spieler1[50], Spieler2[50]; |
|
|
|
int Punkte1 = 0, Punkte2 = 0; |
|
|
|
char Name1[50], Name2[50]; |
|
|
@ -129,7 +129,7 @@ int mainx() { |
|
|
|
scanf("%s", Name2); |
|
|
|
while (Nochmal[0] == 'W' || Nochmal[0] == 'w') { |
|
|
|
Runde = 1; |
|
|
|
initializeBoard(Feld); |
|
|
|
initializeBoard(board); |
|
|
|
printf("%s, Was willst du sein, X oder O: ", Name1); |
|
|
|
scanf("%s", Spieler1); |
|
|
|
if (Spieler1[0] != 'X' && Spieler1[0] != 'O') { |
|
|
@ -139,8 +139,8 @@ int mainx() { |
|
|
|
strcpy(Spieler2, (Spieler1[0] == 'X') ? Name2 : Name1); |
|
|
|
strcpy(Spieler1, (Spieler1[0] == 'X') ? Name1 : Name2); |
|
|
|
printf("\nWillkommen %s und %s. Eure Runde Beginnt jetzt.", Spieler1, Spieler2); |
|
|
|
while (Winner(Feld) == 9) { |
|
|
|
Bild(Feld); |
|
|
|
while (Winner(board) == 9) { |
|
|
|
Bild(board); |
|
|
|
if (Runde % 2 != 0) { |
|
|
|
printf("Spieler 1 gebe das Feld an wo du dein X setzen willst.\n"); |
|
|
|
} |
|
|
@ -157,15 +157,15 @@ int mainx() { |
|
|
|
row -= 1; //Für Index eins kleiner |
|
|
|
col -= 1; |
|
|
|
} |
|
|
|
Zuege(Feld, row, col); |
|
|
|
Zuege(board, row, col); |
|
|
|
Runde++; |
|
|
|
} |
|
|
|
Bild(Feld); |
|
|
|
if (Winner(Feld) == 1) { |
|
|
|
Bild(board); |
|
|
|
if (Winner(board) == 1) { |
|
|
|
printf("Der Sieger ist %s", Spieler1); |
|
|
|
Punkte1++; |
|
|
|
} |
|
|
|
else if (Winner(Feld) == 2) { |
|
|
|
else if (Winner(board) == 2) { |
|
|
|
printf("Der Sieger ist %s", Spieler2); |
|
|
|
Punkte2++; |
|
|
|
} |
|
|
|