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

}

}

相关推荐
ptu小鹏24 分钟前
类和对象(中)
开发语言·c++
Bayi·3 小时前
前端面试场景题
开发语言·前端·javascript
碎梦归途3 小时前
23种设计模式-结构型模式之享元模式(Java版本)
java·开发语言·jvm·设计模式·享元模式
Xiaoyu Wang3 小时前
Go协程的调用与原理
开发语言·后端·golang
bigear_码农3 小时前
python异步协程async调用过程图解
开发语言·python·线程·进程·协程
知识分享小能手4 小时前
JavaScript学习教程,从入门到精通,Ajax与Node.js Web服务器开发全面指南(24)
开发语言·前端·javascript·学习·ajax·node.js·html5
凌叁儿4 小时前
Python 的 datetime 模块使用详解
开发语言·python
谁家有个大人4 小时前
Python数据清洗笔记(上)
开发语言·笔记·python·数据分析
MurphyStar5 小时前
UV: Python包和项目管理器(从入门到不放弃教程)
开发语言·python·uv
阿让啊5 小时前
单片机获取真实时间的实现方法
c语言·开发语言·arm开发·stm32·单片机·嵌入式硬件