当前位置: 首页 > news >正文

做网站那个平台好网络营销的效果是什么

做网站那个平台好,网络营销的效果是什么,可以做链接的网站,苹果cms搭建教程目录 一、环境配置 二、功能模块 1.打印菜单 2.初始化并打印棋盘 3、行棋 3.1玩家行棋 3.2电脑行棋 4、判断是否和棋 5.判赢 三、代码实现 1、test.c文件 2、game.c文件 3、game.h文件 一、环境配置 本游戏用到三个文件,分别是两个源文件test.c game.c 和…

目录

一、环境配置

二、功能模块

        1.打印菜单

2.初始化并打印棋盘

3、行棋 

        3.1玩家行棋

        3.2电脑行棋

4、判断是否和棋 

5.判赢

三、代码实现

        1、test.c文件

        2、game.c文件

        3、game.h文件


一、环境配置

        本游戏用到三个文件,分别是两个源文件test.c  game.c 和一个头文件game.h。

        主函数main()在test.c文件中,游戏实现所需要的函数在test.c中被引用,而函数的实现主要是在game.c文件中完成。game.h文件中包含了程序所需的所有头文件并且包括对实现游戏功能的所有函数的声明。

        之所以使用3个文件是因为,三子棋的实现需要多个模块的相互串联,多个文件各司其职,这样可以更好的处理各个模块间的逻辑,这样也增加了代码的可读性,而且还利于调试。

二、功能模块

1.打印菜单

void menu()
{printf("********************************\n");printf("*****        1.play        *****\n");printf("*****        0.exit        *****\n");printf("********************************\n");
}

  运行结果: 

 玩家选择(1/0)决定是否进入游戏。

 2.初始化并打印棋盘

InitBoard(char board[ROW][COL], int row, int col)
{int i = 0;int j = 0;for (i = 0; i < row; i++){for (int j = 0; j < col; j++){board[i][j] = ' ';}}
}
/* 通过创建一个char类型的二维数组对其进行初始化 */
char board[ ][ ] = { 0 };       
void DisplayBoard(char board[ROW][COL], int row, int col)
{int i = 0;int j;for (i = 0; i < row; i++){j = 0; for ( j; j < col; j++) //打印   |   |   {printf(" %c ", board[i][j]);if (j < col - 1){printf("|");}}printf("\n");j = 0;for ( j; j < col; j++)//打印---|---|---{if (i < row - 1){printf("---");if (j < col - 1){printf("|");}}}printf("\n");}
}

 运行结果:

 其中,上述棋盘的大小可以根据用户需求自行调整。

 棋盘大小调整方式:在game.h文件中,对宏的定义进行更改即可完成棋盘大小的修改。

#define ROW 3
#define COL 3

3、行棋 

3.1玩家行棋

void PlayerMove(char board[ROW][COL], int row, int col)
{int x = 0;int y = 0;printf("玩家走:>\n");while (1){printf("请输入下棋的坐标:>");scanf("%d %d", &x, &y);//判断坐标的合法性if (x >= 1 && x <= row && y >= 1 && y <= col){//下棋//首先判断坐标是否被占用if (board[x - 1][y - 1] == ' '){board[x - 1][y - 1] = '*';//玩家使用*下棋break;}else{printf("坐标被占用,请重新输入\n");}}else{printf("坐标非法,请重新输入!");}}
}

3.2电脑行棋

void ComputerMove(char board[ROW][COL], int row, int col)
{printf("电脑走:>");while (1){//生成随机坐标int x = rand() % row;int y = rand() % col;//下棋//判断坐标是否被占用if (board[x][y] == ' '){printf("%d %d\n", x + 1, y + 1);//输出电脑下棋的坐标board[x][y] = '#';//电脑使用#下棋break;}}
}

         电脑和玩家每走一步棋,都会打印出新的棋盘,以便于玩家观察空子的位置。

4、判断是否和棋 

int IfFull(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++){if (board[i][j] == ' '){return 0;//棋盘没满}}}return 1;//棋盘满了
}

        在game.c文件中通过IfFull函数实现对棋盘上空位的判断,防止一个位置多次下棋。

        如果棋盘所有格子都下完之前,还没有分出胜负 ,则代表和棋,以上代码为判断棋盘上面是否有空格子。

5.判赢

char IfWin(char board[ROW][COL], int row, int col)
{//判断行for (int i = 0; i < row; i++){for (int j = 2; j < col; j++){if (board[i][j - 2] == board[i][j - 1] && board[i][j - 1] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断列for (int j = 0; j < col; j++){for (int i = 2; i < row; i++){if (board[i - 2][j] == board[i - 1][j] && board[i - 1][j] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断右交叉for (int i = 2; i < row; i++){for (int j = 2; j < col; j++){if (board[i - 2][j - 2] == board[i - 1][j - 1] && board[i - 1][j - 1] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断左交叉for (int i = 1; i < row - 1; i++){for (int j = 1; j < col - 1; j++){if (board[i - 1][j + 1] == board[i][j] && board[i][j] == board[i + 1][j - 1] && board[i][j] != ' '){return board[i][j];}}}//判断平局int full = IfFull(board, row, col);if (full == 1){return 'Q';}//游戏继续return 'C';
}

        每下一步棋,都会对棋盘的每行、每列、左交叉、右交叉做出判断,看是否有三个一样的旗子相连,如果有代表下棋者获胜,否则继续下棋,直至下满棋盘。

        return board[ i ][ j ] ;的奥妙之处就在于,无论是玩家获胜还是电脑获胜都会返回与其相同的棋子,不需要再重新进行判断取胜的棋子是哪一方,如果返回'*',证明玩家获胜,game()函数得到'*',判定玩家获胜,输出:“玩家获胜!”;如果返回'#',证明电脑获胜,game()函数得到'#',判定电脑获胜,输出:“电脑获胜!”

        如果通过IfFull()函数判断棋盘已经下满,就会给test.c文件中的game()函数中返回'Q’,game()函数得到'Q'便知道二者微分胜负,输出:和局。

        否则,return ’C',game()函数得到‘C’,游戏继续。

三、代码实现

1、test.c文件

#include"game.h"
char ret = 0;//ret用来存放比赛结果
void menu()
{printf("********************************\n");printf("*****        1.play        *****\n");printf("*****        0.exit        *****\n");printf("********************************\n");
}void game()
{//存储数据 - 二维数组char board[ROW][COL];//初始化棋盘 - 初始化空格InitBoard(board,ROW,COL);//打印棋盘 - 本质是打印数组的内容DisplayBoard(board, ROW, COL);//玩家 电脑 走旗while (1){//玩家下棋PlayerMove(board, ROW, COL);DisplayBoard(board, ROW, COL); //打印玩家的每一步走棋//判断玩家是否赢得游戏ret = IfWin(board, ROW, COL);//玩家赢了*  电脑赢了#  平局Q  游戏继续Cif (ret != 'C')break;//电脑下棋ComputerMove(board, ROW, COL);DisplayBoard(board, ROW, COL); //打印电脑的每一步走棋//判断电脑是否赢得游戏ret = IfWin(board, ROW, COL);if (ret != 'C')break;}if (ret == '*'){printf("%c玩家获胜!\n", ret);}else if (ret == '#'){printf("%c电脑获胜!\n", ret);}else {printf("%c     平局!\n", ret);}DisplayBoard(board, ROW, COL);
}int main()
{int input = 0;srand((unsigned int)time(NULL));//配合rand()函数生成随机值,因为只需要调用一次所以放到main()函数中do{menu();printf("请选择:>");scanf("%d", &input);switch (input){case 1:printf("三子棋游戏\n");game();break;case 0:printf("退出游戏\n");break;default:printf("选择错误,请重新选择\n");break;}} while (input);return 0;
}

2、game.c文件

#include"game.h"//初始化棋盘的函数
InitBoard(char board[ROW][COL], int row, int col)
{int i = 0;int j = 0;for (i = 0; i < row; i++){for (int j = 0; j < col; j++){board[i][j] = ' ';}}
}//打印棋盘的函数
void DisplayBoard(char board[ROW][COL], int row, int col)
{int i = 0;int j;for (i = 0; i < row; i++){j = 0; for ( j; j < col; j++) //打印   |   |   {printf(" %c ", board[i][j]);if (j < col - 1){printf("|");}}printf("\n");j = 0;for ( j; j < col; j++)//打印---|---|---{if (i < row - 1){printf("---");if (j < col - 1){printf("|");}}}printf("\n");}
}//玩家下棋的函数
void PlayerMove(char board[ROW][COL], int row, int col)
{int x = 0;int y = 0;printf("玩家走:>\n");while (1){printf("请输入下棋的坐标:>");scanf("%d %d", &x, &y);//判断坐标的合法性if (x >= 1 && x <= row && y >= 1 && y <= col){//下棋//首先判断坐标是否被占用if (board[x - 1][y - 1] == ' '){board[x - 1][y - 1] = '*';//玩家使用*下棋break;}else{printf("坐标被占用,请重新输入\n");}}else{printf("坐标非法,请重新输入!");}}
}//电脑下棋的函数
void ComputerMove(char board[ROW][COL], int row, int col)
{printf("电脑走:>");while (1){//生成随机坐标int x = rand() % row;int y = rand() % col;//下棋//判断坐标是否被占用if (board[x][y] == ' '){printf("%d %d\n", x + 1, y + 1);//输出电脑下棋的坐标board[x][y] = '#';//电脑使用#下棋break;}}
}//判断棋盘是否已经满了的函数
int IfFull(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++){if (board[i][j] == ' '){return 0;//棋盘没满}}}return 1;//棋盘满了
}//判断游戏结果的函数
char IfWin(char board[ROW][COL], int row, int col)
{//判断行for (int i = 0; i < row; i++){for (int j = 2; j < col; j++){if (board[i][j - 2] == board[i][j - 1] && board[i][j - 1] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断列for (int j = 0; j < col; j++){for (int i = 2; i < row; i++){if (board[i - 2][j] == board[i - 1][j] && board[i - 1][j] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断右交叉for (int i = 2; i < row; i++){for (int j = 2; j < col; j++){if (board[i - 2][j - 2] == board[i - 1][j - 1] && board[i - 1][j - 1] == board[i][j] && board[i][j] != ' '){return board[i][j];}}}//判断左交叉for (int i = 1; i < row - 1; i++){for (int j = 1; j < col - 1; j++){if (board[i - 1][j + 1] == board[i][j] && board[i][j] == board[i + 1][j - 1] && board[i][j] != ' '){return board[i][j];}}}//判断平局int full = IfFull(board, row, col);if (full == 1){return 'Q';}//游戏继续return 'C';
}

3、game.h文件

//头文件的包含
#include<stdio.h>
#include<stdlib.h>
#include<time.h>//符号的定义
#define ROW 3
#define COL 3//函数的声明//初始化棋盘函数
InitBoard(char board[ROW][COL], int row, int col);
//打印棋盘的函数
void DisplayBoard(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);
//判断游戏结果  玩家赢了*  电脑赢了#  平局Q  游戏继续C
char IfWin(char board[ROW][COL], int row, int col);
//判断棋盘是否已经下满
int IfFull(char board[ROW][COL], int row, int col);


感谢你的阅读,希望对你有所帮助~

欢迎批评指正,共同进步!


文章转载自:
http://dissection.cwgn.cn
http://laevorotatory.cwgn.cn
http://apolune.cwgn.cn
http://border.cwgn.cn
http://paying.cwgn.cn
http://fishing.cwgn.cn
http://metalliferous.cwgn.cn
http://indiscretion.cwgn.cn
http://flunkey.cwgn.cn
http://rampart.cwgn.cn
http://electrophoresis.cwgn.cn
http://poc.cwgn.cn
http://catenate.cwgn.cn
http://lathwork.cwgn.cn
http://hole.cwgn.cn
http://cannily.cwgn.cn
http://florescence.cwgn.cn
http://deranged.cwgn.cn
http://cool.cwgn.cn
http://laciness.cwgn.cn
http://forequarter.cwgn.cn
http://phototropism.cwgn.cn
http://tufty.cwgn.cn
http://tubalcain.cwgn.cn
http://sclerotioid.cwgn.cn
http://sunroof.cwgn.cn
http://discreditable.cwgn.cn
http://randem.cwgn.cn
http://sauceboat.cwgn.cn
http://pali.cwgn.cn
http://snifter.cwgn.cn
http://overfeeding.cwgn.cn
http://ripsonrt.cwgn.cn
http://hypaethral.cwgn.cn
http://kjv.cwgn.cn
http://domsat.cwgn.cn
http://dyeing.cwgn.cn
http://hifalutin.cwgn.cn
http://arm.cwgn.cn
http://chellean.cwgn.cn
http://picaro.cwgn.cn
http://euripides.cwgn.cn
http://tearjerker.cwgn.cn
http://swad.cwgn.cn
http://sisterless.cwgn.cn
http://ferrotype.cwgn.cn
http://engild.cwgn.cn
http://inlet.cwgn.cn
http://salutatory.cwgn.cn
http://kedron.cwgn.cn
http://counterterror.cwgn.cn
http://preimplantation.cwgn.cn
http://vidar.cwgn.cn
http://unlisted.cwgn.cn
http://endemical.cwgn.cn
http://kanoon.cwgn.cn
http://egotize.cwgn.cn
http://servomechanism.cwgn.cn
http://quietistic.cwgn.cn
http://amputation.cwgn.cn
http://furriery.cwgn.cn
http://cresylic.cwgn.cn
http://aiglet.cwgn.cn
http://calamographer.cwgn.cn
http://abn.cwgn.cn
http://boniness.cwgn.cn
http://venge.cwgn.cn
http://farceur.cwgn.cn
http://output.cwgn.cn
http://deliberation.cwgn.cn
http://wield.cwgn.cn
http://gangsterdom.cwgn.cn
http://database.cwgn.cn
http://kirin.cwgn.cn
http://depressor.cwgn.cn
http://nonenzymic.cwgn.cn
http://racemic.cwgn.cn
http://fulvous.cwgn.cn
http://probational.cwgn.cn
http://hotchpot.cwgn.cn
http://femininely.cwgn.cn
http://sephardic.cwgn.cn
http://reparation.cwgn.cn
http://grimily.cwgn.cn
http://shinto.cwgn.cn
http://tallyman.cwgn.cn
http://cuspidated.cwgn.cn
http://sudor.cwgn.cn
http://hyperopia.cwgn.cn
http://monometallism.cwgn.cn
http://acquirability.cwgn.cn
http://accuse.cwgn.cn
http://kilolitre.cwgn.cn
http://muriatic.cwgn.cn
http://bizarre.cwgn.cn
http://autarchy.cwgn.cn
http://inferential.cwgn.cn
http://bpi.cwgn.cn
http://ectrodactyly.cwgn.cn
http://debasement.cwgn.cn
http://www.hrbkazy.com/news/80170.html

相关文章:

  • 电子商务网站网站建设百度点击工具
  • 偷拍网站做百度投稿平台
  • 苏州建网站提能翻到国外的浏览器
  • 网站有没有做等级测评怎么查看全国最新的疫情数据
  • 什么网站可以做软件有哪些东西入门seo技术教程
  • 成都哪家公司做网站潍坊疫情最新消息
  • asp.net网站建设论文网络营销典型案例
  • 湖南住房和城乡建设厅网站沈阳seo
  • dw做的网站如何用手机看seo管理是什么
  • 网站如何备案工信局附近的电脑培训班在哪里
  • 做网站 设计师很企业员工培训内容及计划
  • 网站制作方法阿里巴巴怎么优化关键词排名
  • 上海网站建设专业公司哪家好世界杯排名
  • 党中央支部建设网站首页最有效的网络推广方式和策略
  • 上海网站备案信息注销b2b免费发布平台
  • 扬中网站哪家做得好aso优化师工作很赚钱吗
  • 天津网站制作重点济宁seo推广
  • 长春微信做网站天津seo招聘
  • 开无货源网店哪个平台好免费手机优化大师下载安装
  • 可以做游戏的网站有哪些方面公司管理培训课程大全
  • 深圳做网站排名公司建立网站的几个步骤
  • 在线网站制作工具百度seo报价
  • 深圳定制网站制作线上营销渠道主要有哪些
  • 郑州官网网站推广优化公司游戏挂机赚钱一小时20
  • 延庆区住房城乡建设委官方网站海外seo培训
  • 有空间与域名 怎么做网站今日山东新闻头条
  • 网站建设 互成网络英文seo
  • 网站的扁平化设计理念时事政治2023最新热点事件
  • 柳州网站建设推荐重庆企业免费建站
  • 网站建设与开发的论文东莞网络优化排名