目录
1 -> 模块简介
2 -> test.c
3 -> game.c
4 -> game.h
1 -> 模块简介
test.c:测试游戏逻辑
game.c: 函数的实现
game.h:函数的声明
2 -> test.c
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h";
void menu()
{
printf("****************************************n");
printf("************ 1.play ************n");
printf("************ 0.exit ************n");
printf("****************************************n");
}
void game()
{
//存放数据
char board[ROW][COL] = { 0 };
//初始化
InitBoard(board, ROW, COL);
//打印棋盘
DisplayBoard(board, ROW, COL);
char ret = 0;
while (1)
{
//玩家下棋
PlayerMove(board, ROW, COL);
//打印棋盘
DisplayBoard(board, ROW, COL);
//判断输赢
ret = IsWin(board, ROW, COL);
if ('C' != ret)
break;
//电脑下棋
ComputerMove(board, ROW, COL);
//打印棋盘
DisplayBoard(board, ROW, COL);
//判断输赢
ret = IsWin(board, ROW, COL);
if ('C' != ret)
break;
}
if ('*' == ret)
printf("恭喜玩家获得胜利!!!n");
else if ('#' == ret)
printf("恭喜电脑获得胜利!!!n");
else if ('Q' == ret)
printf("双方平局n");
}
int main()
{
int input = 0;
srand((unsigned int) time(NULL));
do
{
menu();
printf("请选择:>");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出游戏n");
break;
default:
printf("输入错误,请重新输入n");
break;
}
} while (input);
return 0;
}
3 -> game.c
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h";
//初始化棋盘
void InitBoard(char board[ROW][COL], int row, int col)
{
memset(&board[0][0], ' ', row * col * sizeof(board[0][0]));
}
//打印棋盘
void DisplayBoard(char board[ROW][COL], int row, int col)
{
for (int i = 0; i n");
printf("请输入所在坐标:>");
scanf("%d %d", &x, &y);
if (x >= 1 && x = 1 && y n");
while (1)
{
x = rand() % row;
y = rand服务器托管网() % col;
if (board[x][y] == ' ')
{
board[x][y] = '#';
break;
}
}
}
//棋盘填满平局
int IsFull(char board[ROW][COL], int row, int col)
{
for (int i = 0; i *
//电脑赢 -> #
//平局 -> Q
//继续 -> C
char IsWin(char board[ROW][COL], int row, int col)
{
//行判断
for (int i = 0; i
4 -> game.h
#pragma once
#include
#include
#include
#include
#define ROW 3
#define COL 3
//初始化棋盘
void InitBoard(char board[ROW][COL], int row, int col);
//打印棋盘
void DisplayBoard(char board[ROW][COL], int row, int col);
//玩家下棋
void PlayerMove(char board[ROW][COL], int row, int col);
//电脑下棋
void ComputerMove(char board[ROW][COL], int row, int col);
//棋盘填满平局
int IsFull(ch服务器托管网ar board[ROW][COL], int row, int col);
//判断输赢
char IsWin(char board[ROW][COL], int row, int col);
好久没写博客啦,以后会花更多时间写博客的,感谢各位大佬支持啦!!!
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
之前写过一篇关于 IDA 在无 dmp 文件下如何定位到崩溃点的文章,由于其中涉及到公司项目,就仅限自己看了 正好今天看到一篇关于火绒软件误杀 explorer 的文章,并且有相关的复现过程 文章已经概述的很清楚,不过缺少软件的调试步骤,借此机会补充一下 该调…