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

}

}

相关推荐
新手小新15 分钟前
C++游戏开发(2)
开发语言·前端·c++
你的电影很有趣1 小时前
lesson30:Python迭代三剑客:可迭代对象、迭代器与生成器深度解析
开发语言·python
程序员编程指南2 小时前
Qt 嵌入式界面优化技术
c语言·开发语言·c++·qt
q__y__L3 小时前
C#线程同步(二)锁
开发语言·性能优化·c#
二川bro3 小时前
第二篇:Three.js核心三要素:场景、相机、渲染器
开发语言·javascript·数码相机
云泽8083 小时前
数据结构前篇 - 深入解析数据结构之复杂度
c语言·开发语言·数据结构
卷卷的小趴菜学编程3 小时前
Qt-----初识
开发语言·c++·qt·sdk·qt介绍
天天进步20153 小时前
Python游戏开发引擎设计与实现
开发语言·python·pygame
Vic101014 小时前
Hutool 的完整 JSON 工具类示例
开发语言·json
程序员编程指南4 小时前
Qt 开发 IDE 插件开发指南
c语言·c++·ide·qt·elasticsearch