Browse Source

Hinzufügen der Spieler "O" und "X"

remotes/origin/tictactoedev
Sabina Grisi 11 months ago
parent
commit
f167ffd638
  1. 103
      src/TicTacToe.c

103
src/TicTacToe.c

@ -11,41 +11,44 @@ int main() {
int pos7 = 7; int pos7 = 7;
int pos8 = 8; int pos8 = 8;
int pos9 = 9; int pos9 = 9;
int o = 0;
int player = 10;
drawBoard(pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9); drawBoard(pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9);
// Spielschleife // Spielschleife
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
int in; int in;
printf("Choose a number: ");
printf("Player %c, enter your move (1-9): ", (player == 10) ? 'X' : 'O');
scanf("%d", &in); scanf("%d", &in);
printf("\n"); printf("\n");
if (pos1 == in) { if (pos1 == in) {
pos1 = o;
pos1 = player;
} else if (pos2 == in) { } else if (pos2 == in) {
pos2 = o;
pos2 = player;
} else if (pos3 == in) { } else if (pos3 == in) {
pos3 = o;
pos3 = player;
} else if (pos4 == in) { } else if (pos4 == in) {
pos4 = o;
pos4 = player;
} else if (pos5 == in) { } else if (pos5 == in) {
pos5 = o;
pos5 = player;
} else if (pos6 == in) { } else if (pos6 == in) {
pos6 = o;
pos6 = player;
} else if (pos7 == in) { } else if (pos7 == in) {
pos7 = o;
pos7 = player;
} else if (pos8 == in) { } else if (pos8 == in) {
pos8 = o;
pos8 = player;
} else if (pos9 == in) { } else if (pos9 == in) {
pos9 = o;
pos9 = player;
} else { } else {
printf("Try again. "); printf("Try again. ");
i--; // wiederholen i--; // wiederholen
continue; continue;
} }
drawBoard(pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9); drawBoard(pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9);
player = (player == 10) ? 11 : 10;
} }
return 0; return 0;
} }
@ -55,10 +58,82 @@ void drawBoard(int pos1, int pos2, int pos3, int pos4, int pos5, int pos6, int p
char horizontal[] = "---"; char horizontal[] = "---";
printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical); printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical);
printf("%c %d %c %d %c %d %c\n", vertical, pos1, vertical, pos2, vertical, pos3, vertical);
printf("%c", vertical);
if (pos1 == 10) {
printf(" X ");
} else if (pos1 == 11) {
printf(" O ");
} else {
printf(" %d ",pos1);
}
printf("%c", vertical);
if (pos2 == 10) {
printf(" X ");
} else if (pos2 == 11) {
printf(" O ");
} else {
printf(" %d ",pos2);
}
printf("%c", vertical);
if (pos3 == 10) {
printf(" X ");
} else if (pos3 == 11) {
printf(" O ");
} else {
printf(" %d ",pos3);
}
printf("%c\n", vertical);
printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical); printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical);
printf("%c %d %c %d %c %d %c\n", vertical, pos4, vertical, pos5, vertical, pos6, vertical);
printf("%c", vertical);
if (pos4 == 10) {
printf(" X ");
} else if (pos4 == 11) {
printf(" O ");
} else {
printf(" %d ",pos4);
}
printf("%c", vertical);
if (pos5 == 10) {
printf(" X ");
} else if (pos5 == 11) {
printf(" O ");
} else {
printf(" %d ",pos5);
}
printf("%c", vertical);
if (pos6 == 10) {
printf(" X ");
} else if (pos6 == 11) {
printf(" O ");
} else {
printf(" %d ",pos6);
}
printf("%c\n", vertical);
printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical); printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical);
printf("%c %d %c %d %c %d %c\n", vertical, pos7, vertical, pos8, vertical, pos9, vertical);
printf("%c", vertical);
if (pos7 == 10) {
printf(" X ");
} else if (pos7 == 11) {
printf(" O ");
} else {
printf(" %d ",pos7);
}
printf("%c", vertical);
if (pos8 == 10) {
printf(" X ");
} else if (pos8 == 11) {
printf(" O ");
} else {
printf(" %d ",pos8);
}
printf("%c", vertical);
if (pos9 == 10) {
printf(" X ");
} else if (pos9 == 11) {
printf(" O ");
} else {
printf(" %d ",pos9);
}
printf("%c\n", vertical);
printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical); printf("%c%s%c%s%c%s%c\n", vertical, horizontal, vertical, horizontal, vertical, horizontal, vertical);
} }
Loading…
Cancel
Save