我看到的井字棋都是输入坐标,但是题目要求用数字键盘中的数字代替坐标。请解决一下我图片中的问题。谢谢!
可以看一下这篇三子棋游戏教程博客,最后有源代码http://t.csdn.cn/Inm3H
看看这个链接
http://t.csdn.cn/Inm3H
可以参考一下这个:https://blog.csdn.net/crrrush/article/details/124739680
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define ROW 3
#define COL 3
void game();//游戏模块实现
void initi_board(char board[ROW][COL], int row, int col);//棋盘初始化
void Create_board(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);//电脑下棋
char judge_condition(char board[ROW][COL], int row, int col);//判断棋盘状态
int full_board(char board[ROW][COL], int row, int col);//判断棋盘是否下满
#define _CRT_SECURE_NO_WARNINGS
//#include"game.h"
void menu()
{
printf("*********************************\n");
printf("******* 1.play 0.exit ******\n");
printf("*********************************\n");
}
void game()//游戏模块实现
{
char board[ROW][COL];//创建一个棋盘
char recei = 0;//用于判断棋盘状态的变量
srand((unsigned int)time(NULL));//生成随机数起点
//初始化棋盘
initi_board(board, ROW, COL);
//生成棋盘
Create_board(board, ROW, COL);
printf("请输入您要下的棋的坐标,示例:第一行第二列1 2\n");
while (1)
{
//玩家下棋
Playermove(board, ROW, COL);
Create_board(board, ROW, COL);
//判断棋盘状态
recei = judge_condition(board, ROW, COL);
if (recei == '*' || recei == 'D')
break;
//电脑下棋
Computermove(board, ROW, COL);
Create_board(board, ROW, COL);
//判断棋盘状态
recei = judge_condition(board, ROW, COL);
if (recei == '#' || recei == 'D')
break;
}
if (recei == '*')
{
printf("游戏结束,玩家胜利!\n");
printf("请选择是否开始下一局游戏\n");
}
else if (recei == '#')
{
printf("游戏结束,电脑胜利!\n");
printf("请选择是否开始下一局游戏\n");
}
else
{
printf("游戏结束,平局!\n");
printf("请选择是否开始下一局游戏\n");
}
}
int main()
{
int input = 0;
do
{
menu();
scanf("%d", &input);
switch (input)
{
case 1:
printf("三子棋游戏\n");
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误,请重新选择!\n");
break;
}
} while (input);
return 0;
}