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 boardROWCOL = { 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 boardROWCOL,int row,int col);

void DisplayBoard(char boardROWCOL,int row,int col);


game.c

#include"game.h"

void InitBoard(char boardROWCOL, int row, int col)

{

int i = 0;

int j = 0;

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

{

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

{

boardij = ' ';

}

}

}

void DisplayBoard(char boardROWCOL, int row, int col)

{

int i = 0;

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

{

//1.打印一行的数据

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

//printf(" %c | %c | %c \n", boardi0, boardi1, boardi2);

int j = 0;

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

{

printf(" %c ", boardij);

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");

}

}

相关推荐
小白学大数据7 分钟前
超简单:用 Python 让 Excel 飞起来:用 openpyxl 把重复报表整理交给脚本
开发语言·数据库·python·excel
旧梦952717 分钟前
Java SortedMap 接口详解:从入门到实战
java·开发语言
莫陌尛.21 分钟前
Java_this构造方法
java·开发语言
Persistent的粽子!1 小时前
C++:类与对象(二)
开发语言·c++
Dreams°1231 小时前
【Java后端+Vue前后端分离:内网正常、公网访问异常|5个高频经典踩坑完整复盘】
java·开发语言·vue.js
思麟呀1 小时前
嵌入式入门(一)宏观生态到首次烧录
c语言·嵌入式硬件
小雪崩1 小时前
嵌入式学习 day39:TCP并发服务器模型
linux·服务器·c语言·网络·学习·tcp/ip
.YM.Z1 小时前
C++ STL 容器深度剖析:vector 与 list 的模拟实现及对比
开发语言·c++·vector·list
lsylalalala2 小时前
多线程(4)
java·开发语言·多线程
小白不想画工图2 小时前
银河麒麟V10系统安装QT5.12
linux·开发语言·qt·银河麒麟