HTMLify
Tic Tac Toe (C lang)
Views: 20 | Author: abh
#include <stdio.h>
#include <string.h>
#include "ttt.h"
#include "ui.h"
int main() {
char p1n[32], p2n[32], p1m, p2m;
int turn, players;
printf("Tic Tac Toe Game\n");
printf("----------------\n");
printf("Select Game Mode:\n");
printf("\t1: 1 Player\n");
printf("\t2: 2 Player\n");
printf(">>> ");
scanf("%d", &players);
if (players == 1) {
printf("Enter name: ");
scanf("%s", p1n);
printf("Enter mark [o/x]: ");
scanf(" %c", &p1m);
strcpy(p2n, "-<BOT>-");
p2m = p1m == 'o' ? 'x' : 'o';
} else if (players == 2) {
printf("Enter Player1 name: ");
scanf("%s", p1n);
printf("Enter mark [o/x]: ");
scanf(" %c", &p1m);
printf("Enter Player2 name: ");
scanf("%s", p2n);
printf("Enter mark [o/x]: ");
scanf(" %c", &p2m);
} else {
printf("Envalid number of players\nExiting...\n");
return 0;
}
if (p1m != 'o' && p1m != 'x') {
printf("Player1 mark is invaid\nExiting...");
return 0;
}
if (p2m != 'o' && p2m != 'x') {
printf("Player2 mark is invaid\nExiting...");
return 0;
}
TTT *game = TTT_init( p1n, p2n, p1m, p2m, 1 );
ui(game);
return 0;
}