|
|
|
|
#define _CRT_SECURE_NO_WARNINGS 1
|
|
|
|
|
#include "game.h"
|
|
|
|
|
void game()
|
|
|
|
|
{
|
|
|
|
|
char ret = 0;
|
|
|
|
|
char board[ROW][COL]={'0'};
|
|
|
|
|
initboard(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
playermove(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
ret = checkwin(board,ROW,COL);
|
|
|
|
|
if(ret == 'X')
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>Ӯ<EFBFBD>ˣ<EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (ret == 'Q')
|
|
|
|
|
{
|
|
|
|
|
printf ("ƽ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
computermove(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
ret = checkwin(board,ROW,COL);
|
|
|
|
|
if (ret == '0')
|
|
|
|
|
{
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void game2()
|
|
|
|
|
{
|
|
|
|
|
char ret = 0;
|
|
|
|
|
char board[ROW][COL]={'0'};
|
|
|
|
|
initboard(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
computermove(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
ret = checkwin(board,ROW,COL);
|
|
|
|
|
if (ret == '0')
|
|
|
|
|
{
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (ret == 'Q')
|
|
|
|
|
{
|
|
|
|
|
printf ("ƽ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
playermove(board,ROW,COL);
|
|
|
|
|
printboard(board,ROW,COL);
|
|
|
|
|
ret = checkwin(board,ROW,COL);
|
|
|
|
|
if(ret == 'X')
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>Ӯ<EFBFBD>ˣ<EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void menu2()
|
|
|
|
|
{
|
|
|
|
|
printf (" *****************************************\n");
|
|
|
|
|
printf (" ** 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> **\n");
|
|
|
|
|
printf (" *****************************************\n");
|
|
|
|
|
}
|
|
|
|
|
void menu()
|
|
|
|
|
{
|
|
|
|
|
printf ("--------------------<2D><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ--------------------\n");
|
|
|
|
|
printf (" *****************************************\n");
|
|
|
|
|
printf (" ** 1.play 0.exit **\n");
|
|
|
|
|
printf (" *****************************************\n");
|
|
|
|
|
}
|
|
|
|
|
void main2()
|
|
|
|
|
{
|
|
|
|
|
int input = 0;
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf ("%d",&input);
|
|
|
|
|
switch (input)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
game();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
game2();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main ()
|
|
|
|
|
{
|
|
|
|
|
int input = 0;
|
|
|
|
|
srand ((unsigned int)(time (NULL)));
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
menu();
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf ("%d",&input);
|
|
|
|
|
switch (input)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
menu2();
|
|
|
|
|
main2();
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
}while(input);
|
|
|
|
|
system("pause\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|