C语言之三子棋游戏(棋盘)

test.c

#define _CRT_SECURE_NO_WARNINGS 1

//测试三子棋

#include"game.h"

void menu()

{

printf("**********************************\n");

printf("***** 1.play 0.exit ****\n");

printf("**********************************\n");

}

void game()//游戏实现

{

//数组-存放走出的棋盘信息

char board[ROW][COL] = { 0 };//全部是空格

//初始化棋盘

InitBoard(board,ROW,COL);

//打印棋盘

DisplayBoard(board, ROW, COL);

}

void test()

{

int input = 0;

do

{

menu();

printf("请选择:>");

scanf("%d", &input);

switch (input)

{

case 1:

game();

break;

case 0:

printf("退出游戏\n");

break;

default:

printf("选择错误,请重新选择!\n");

break;

}

} while (input);

}

int main()

{

test();

return 0;

}


game.h

#define ROW 3

#define COL 3

#include<stdio.h>

//声明

void InitBoard(char board[ROW][COL],int row,int col);

void DisplayBoard(char board[ROW][COL],int row,int col);


game.c

#include"game.h"

void InitBoard(char board[ROW][COL], int row, int col)

{

int i = 0;

int j = 0;

for (i = 0; i < row; i++)

{

for (j = 0; j < col; j++)

{

board[i][j] = ' ';

}

}

}

void DisplayBoard(char board[ROW][COL], int row, int col)

{

int i = 0;

for (i = 0; i < row; i++)

{

//1.打印一行的数据

//printf(" %c | %c | %c \n");

//printf(" %c | %c | %c \n", board[i][0], board[i][1], board[i][2]);

int j = 0;

for (j = 0; j < col; j++)

{

printf(" %c ", board[i][j]);

if (j < col - 1)

printf("|");

}

printf("\n");

//2.打印分割行

//if (i < row - 1)

//{

// printf("---|---|---\n");

//}

if (i < row - 1)

{

for (j = 0; j < col; j++)

{

printf("---");

if(j<col-1)

printf("|");

}

}

printf("\n");

}

}

相关推荐
liulilittle15 分钟前
Y组合子剖析:C++ 中的递归魔法
开发语言·c++·编程语言·函数式编程·函数式·函数编程·y组合子
金涛03192 小时前
QT-day2,信号和槽
开发语言·qt·命令模式
坚持编程的菜鸟5 小时前
LeetCode每日一题——困于环中的机器人
c语言·算法·leetcode·机器人
Aurorar0rua7 小时前
C Primer Plus Notes 09
java·c语言·算法
R-G-B9 小时前
【02】C#入门到精通——C# 变量、输入/输出、类型转换
开发语言·c#·c# 变量·c#输入/输出·c#类型转换
星河队长9 小时前
C# 软件加密方法,有使用时间限制,同时要防止拷贝
开发语言·c#
史迪奇_xxx9 小时前
10、一个简易 vector:C++ 模板与 STL
java·开发语言·c++
2301_801252229 小时前
Java中的反射
java·开发语言
Kiri霧9 小时前
Rust开发环境搭建
开发语言·后端·rust
weixin-a153003083169 小时前
[数据抓取-1]beautifulsoup
开发语言·python·beautifulsoup