此程序的大体信息
- 编程语言:C
- 图形库:easyX
- 编译器:visual studio 2022
此程序的玩法
双人井字棋经典玩法。双方轮流下子,率先连成一行、一列或者斜线的玩家将会获胜
程序运行效果
- 初始界面
- 双方轮流下子
- 如果一方玩家获胜,那么获胜的那一行、列或者斜线将会用线段标记出。同时弹出对话框,询问用户是否重开一局。如果重开一局,那么获胜玩家的分数加一分;如果不重开,那么游戏结束,进程退出。
程序代码
#include<graphics.h>
#include<Windows.h>
#include<stdio.h>
void initBoard(int arr[][3], int boardWidth, int boardHeight)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] = -1;
}
}
setbkcolor(WHITE);
cleardevice();
int xGap = boardWidth / 3;
int yGap = boardHeight / 3;
setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 1);
setlinecolor(BLACK);
line(xGap, 0, xGap, boardHeight);
line(xGap * 2, 0, xGap * 2, boardHeight);
line(xGap * 3, 0, xGap * 3, boardHeight);
line(0, 0, boardWidth, 0);
line(0, yGap, boardWidth, yGap);
line(0, yGap * 2, boardWidth, yGap * 2);
}
void drawScore(int x, int y, int scoreWidth, int scoreHeight, int hook, int draw, int cross)
{
setbkcolor(WHITE);
clearrectangle(x + 1, y, x + scoreWidth - 1, y + scoreHeight);
char title[30] = {
"勾赢 : 平局 : 叉赢" };
settextstyle(25, 13, _T("黑体"));
settextcolor(BLACK);
outtextxy(x + 40, y + 5, title);
char scoreString[30];
snprintf(scoreString, 29