void initGame(void)
{
char c;
printf("Please input 'y' to enter the game:");
c = getchar();
if ('y'!= c && 'Y'!= c)
exit(0);
//Clear
system("clear");
//ここで再び、チェス盤を表示する機能を持つカスタム関数を呼び出します。
printChessboard();
}
initGame 関数では、exit 関数と system 関数を使用しているため、プログラムの先頭でヘッダファイル stdlib.h をインクルードする必要があります。
void playChess(void)
{
int i, j, winner;
// プレイヤー1の番かプレイヤー2の番かを判定し、その後配列の対応する要素に値を代入する。
if (1 == whoseTurn % 2)
{
printf("Turn to player 1, please input the position, the format is line number + space number + column number: ");
scanf("%d %d", &i, &j);
chessboard[i][j] = 1;
}
else
{
printf("Turn to player 2, please input the position, the format is line number + space number + column number: ");
scanf("%d %d", &i, &j);
chessboard[i][j] = 2;
}
// 盤面を再度表示する。
system("clear");
printChessboard(); // この関数を再度呼び出す。
/*
* 以下のセクションでは、カスタム関数(判定関数)を呼び出します。
* 現在のプレイヤーがその手番で勝利したかどうかを判定するために使用されます。
*/
if (judge(i, j, whoseTurn))
{
if (1 == whoseTurn % 2)
printf("Winner is player 1!\n");
else
printf("Winner is player 2!\n");
}
}
void playChess(void)
{
int i, j, winner;
if (1 == whoseTurn % 2)
{
printf("Turn to player 1, please input the position, the format is line number + space number + column number: ");
scanf("%d %d", &i, &j);
//debug
while(chessboard[i][j]!= 0)
{
printf("This position has been occupied, please input the position again: ");
scanf("%d %d",&i, &j);
}
//debug
chessboard[i][j] = 1;
}
else
{
printf("Turn to player 2, please input the position, the format is line number + space number + column number: ");
scanf("%d %d", &i, &j);
//debug
while(chessboard[i][j]!= 0)
{
printf("This position has been occupied, please input the position again: ");
scanf("%d %d",&i, &j);
}
//debug
chessboard[i][j] = 2;
}
system("clear");
printChessboard();
if (judge(i, j))
{
if (1 == whoseTurn % 2)
printf("The winner is player 1!\n");
else
printf("The winner is player 2!\n");
}
}
if (judge(i, j))
{
if (1 == whoseTurn % 2)
{
printf("Winner is player 1!\n");
exit(0); //debug
}
else
{
printf("Winner is player 2!\n");
exit(0); //debug
}
}
}