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

外贸公司网站如何做网上推广网络销售平台上市公司有哪些

外贸公司网站如何做网上推广,网络销售平台上市公司有哪些,网站做的好坏主要看,深圳网站建设汤小巧文章目录 1.游戏界面2.游戏内容2.1 棋盘类型2.2棋盘的初始化2.3 打印棋盘的界面展示 3.游戏操作3.1 玩家操作3.2 电脑操作3.3 胜负判定 4.代码整合 1.游戏界面 无论写任何程序,我们都需要先去了解它的大概框架,这里我们先把它的初始界面写出来。一个游戏…

文章目录

  • 1.游戏界面
  • 2.游戏内容
    • 2.1 棋盘类型
    • 2.2棋盘的初始化
    • 2.3 打印棋盘的界面展示
  • 3.游戏操作
    • 3.1 玩家操作
    • 3.2 电脑操作
    • 3.3 胜负判定
  • 4.代码整合

1.游戏界面

无论写任何程序,我们都需要先去了解它的大概框架,这里我们先把它的初始界面写出来。一个游戏的初始界面会有菜单可供选择,这里我写了一个最基础的游戏菜单,只支持开始游戏和退出游戏。为了能够在不退出游戏的情况下一直游玩,所以这里我写了一个do while循环来让游戏一直进行下去。

#include <stdio.h>
void menu()
{printf("*************************\n");printf("******* 1.play    *******\n");printf("******* 0.exit    *******\n");printf("*************************\n");}
int main()
{int input = 0;do{menu()//菜单printf("请选择>");scanf"%d",&input);switch(input){case 1:game();break;case 0:printf("退出游戏!\n");break;default:break;}}while(input);return 0;
}

2.游戏内容

2.1 棋盘类型

写完游戏的界面就轮到了游戏的内容了,让我们来想想三子棋有什么特点,最先想到就是它那3*3的棋盘了,为了实现这个棋盘我们要利用数组来实现。用什么类型的数组呢?这里我会用字符类型的数组,毕竟下棋用数字来作为棋子还是不容易区分的。

void game()
{//创建棋盘char chess[4][4] = {0};
}

2.2棋盘的初始化

选择了用字符数组来作为棋盘,初始化我会用‘ ’(空格)来初始化。空格初始化的好处就是不可见,当我们下好棋子后用相应的字符去覆盖掉空格就可以了。
这里我用4*4的数组是为了后续普通用户在用下标下棋时,不用考虑数组下标是0开始的,增加用户的受众。
为什么用多文件编写代码,多文件的编写可以便于后续的修改,多文件可以让代码的可读性更高。
注意头文件game.h放的是函数的声明,game.c放的是函数的定义 test.c是对程序的测试

//game.h
#include <stdio.h>
//以row为行,col为列void InitChess(char chess[4][4],int row,int col);//game.c
#include "game.h"
void InitChess(char chess[4][4],int row,int col)
{for(int i = 1;i<4;++i){for(int j = 1;j<4;++j){chess[i][j] = ' ';}}
}//test.c
#include "game.h"
void game()
{//创建棋盘char chess[4][4] = {0};//初始化棋盘InitChess(chess,4,4);
}

对函数拓展性的优化,这里的棋盘已经被固定,如果后续我们想要修改棋盘的大小是很麻烦的,所以我们可以定义标识常量。

//game.h
#include <stdio.h>
//以row为行,col为列
#define Row 4
#define Col 4void InitChess(char chess[Row][Col],int row,int col);//game.c
#include "game.h"
void InitChess(char chess[Row][Col],int row,int col)
{for(int i = 1;i<row;++i){for(int j = 1;j<col;++j){chess[i][j] = ' ';}}
}//test.c
#include "game.h"
void game()
{//创建棋盘char chess[Row][Col] = {0};//初始化棋盘InitChess(chess,Row,Col);
}

2.3 打印棋盘的界面展示

如果我们直接打印这个数组是什么也看不到的,为了让游玩的人可以轻松知道棋盘各个点的坐标,我们要把棋盘打印成这个样子。
打印棋盘

void ChessBoard(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){for (int j = 1; j < col; ++j){printf(" %c ", chess[i][j]);if (j < col - 1)//否则打印最后一个'|',导致右端封闭printf("|");}printf("\n");if (i < row - 1){for (int j = 1; j < col; ++j){printf("--- ");}printf("\n");}}
}

3.游戏操作

3.1 玩家操作

三子棋的游戏操作就是在3*3的方格当中选一个未被下过的方格中落子。
当前游戏并不支持双人对战,所以只能实现人机对战。下面为玩家操作:

void Gamer(char chess[Row][Col], int row, int col)
{int x = 0;//横坐标int y = 0;//纵坐标while (1){printf("选择落子坐标>\n");printf("坐标之间用空格区分\n");scanf("%d %d", &x, &y);//判断坐标是否合法if (x<1 || x>Row - 1 || y<1 || y>Col - 1){printf("坐标不合法\n");}//判断所选坐标是否被占据else if (chess[x][y] != ' '){printf("该坐标被占据\n");}else{chess[x][y] = 'O';printf("落子成功\n");break;}}
}

3.2 电脑操作

电脑的逻辑和玩家一样,这里我们让电脑随机下棋。

void Computer(char chess[Row][Col], int row, int col)
{int x = 0;int y = 0;while (1){x = rand() % (row - 1) + 1;y = rand() % (col - 1) + 1;if (chess[x][y] != ' '){//}else{chess[x][y] = 'X';break;}}
}

因为这了我们用了rand函数,所以我必须在前面写上srand来给rand函数提供随机种子,为此我们还需要用到time为srand提供数字来帮助它输出随机种子.
记得加上相应的头文件

int main()
{int input = 0;srand((unsigned int)time(NULL));do{menu()//菜单printf("请选择>");scanf"%d",&input);switch(input){case 1:game();break;case 0:printf("退出游戏!\n");break;default:break;}}while(input);return 0;
}

3.3 胜负判定

在三子棋当中,任何以方的棋子连成一条线就会判断为获胜,无论是一行还是一列还是斜方向。因为只有少量的情况。我能把所有获胜的情况全部都枚举出来就可以了。
关于返回值,因为我们要根据棋盘字符的连线来判断谁是赢家。
规定:返回 ‘O’表示玩家赢,‘X’表示电脑赢 'D’表示平局 'C’表示游戏继续

char Winer(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){if (chess[i][1] == chess[i][2] && chess[i][2] == chess[i][3] && chess[i][1] != ' '){return chess[i][1];}}for (int j = 1; j < col; ++j){if (chess[1][j] == chess[2][j] && chess[2][j] == chess[3][j] && chess[1][j] != ' '){return chess[1][j];}}if (chess[1][1] == chess[2][2] && chess[2][2] == chess[3][3] & chess[1][1] != ' '){return chess[1][1];}if (chess[1][3] == chess[2][2] && chess[2][2] == chess[3][1] && chess[2][2] != ' '){return chess[1][3];}//平局,判断棋盘是不是已经满了if (IsFull(chess, row, col)){return 'D';}return 'C';
}

判断棋盘是否已经下满

bool IsFull(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){for (int j = 1; j < col; ++j){if (chess[i][j] == ' ')return false;}}return true;
}

4.代码整合

关于三子棋的简单游戏逻辑就是这么多了,下面我们要把我们写到的函数整合到一起。

//game.h
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>//rand和srand的头文件
#include <time.h>//time的头文件
#define Row 4
#define Col 4void InitChess(char chess[Row][Col], int row, int col);void ChessBoard(char chess[Row][Col], int row, int col);void Gamer(char chess[Row][Col], int row, int col);void Computer(char chess[Row][Col], int row, int col);char Winer(char chess[Row][Col], int row, int col);bool IsFull(char chess[Row][Col], int row, int col);//game.c#include "game.h"void InitChess(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){for (int j = 1; j < col; ++j){chess[i][j] = ' ';}}
}void ChessBoard(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){for (int j = 1; j < col; ++j){printf(" %c ", chess[i][j]);if (j < col - 1)//否则打印最后一个'|',导致右端封闭printf("|");}printf("\n");if (i < row - 1){for (int j = 1; j < col; ++j){printf("--- ");}printf("\n");}}
}void Gamer(char chess[Row][Col], int row, int col)
{int x = 0;//横坐标int y = 0;//纵坐标while (1){printf("选择落子坐标>\n");printf("坐标之间用空格区分\n");scanf("%d %d", &x, &y);//判断坐标是否合法if (x<1 || x>Row - 1 || y<1 || y>Col - 1){printf("坐标不合法\n");}//判断所选坐标是否被占据else if (chess[x][y] != ' '){printf("该坐标被占据\n");}else{chess[x][y] = 'O';printf("落子成功\n");break;}}
}void Computer(char chess[Row][Col], int row, int col)
{int x = 0;int y = 0;while (1){x = rand() % (row - 1) + 1;y = rand() % (col - 1) + 1;if (chess[x][y] != ' '){//}else{chess[x][y] = 'X';break;}}
}char Winer(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){if (chess[i][1] == chess[i][2] && chess[i][2] == chess[i][3] && chess[i][1] != ' '){return chess[i][1];}}for (int j = 1; j < col; ++j){if (chess[1][j] == chess[2][j] && chess[2][j] == chess[3][j] && chess[1][j] != ' '){return chess[1][j];}}if (chess[1][1] == chess[2][2] && chess[2][2] == chess[3][3] & chess[1][1] != ' '){return chess[1][1];}if (chess[1][3] == chess[2][2] && chess[2][2] == chess[3][1] && chess[2][2] != ' '){return chess[1][3];}//平局,判断棋盘是不是已经满了if (IsFull(chess, row, col)){return 'D';}return 'C';
}bool IsFull(char chess[Row][Col], int row, int col)
{for (int i = 1; i < row; ++i){for (int j = 1; j < col; ++j){if (chess[i][j] == ' ')return false;}}return true;
}//test.c
#include "game.h"void game()
{//创建棋盘char chess[Row][Col] = { 0 };//初始化棋盘InitChess(chess, Row, Col);char w = 0;while (1){//打印棋盘ChessBoard(chess, Row, Col);//玩家操作Gamer(chess, Row, Col);//输赢判断w = Winer(chess, Row, Col);if (w != 'C')break;//电脑操作Computer(chess, Row, Col);//输赢判断char w = Winer(chess, Row, Col);if (w != 'C')break;}ChessBoard(chess, Row, Col);if (w == 'D')printf("平局\n");else if (w == 'O')printf("玩家获胜\n");elseprintf("电脑获胜\n");
}
void menu()
{printf("*************************\n");printf("******* 1.play    *******\n");printf("******* 0.exit    *******\n");printf("*************************\n");}
int main()
{int input = 0;srand((unsigned int)time(NULL));do{menu();//菜单printf("请选择>");scanf("%d", & input);switch (input){case 1:game();break;case 0:printf("退出游戏!\n");break;default:break;}} while (input);return 0;
}


文章转载自:
http://nutshell.rwzc.cn
http://seismography.rwzc.cn
http://parashot.rwzc.cn
http://decadal.rwzc.cn
http://sackful.rwzc.cn
http://tetraploid.rwzc.cn
http://stickpin.rwzc.cn
http://toluol.rwzc.cn
http://contredanse.rwzc.cn
http://rolamite.rwzc.cn
http://frocking.rwzc.cn
http://battue.rwzc.cn
http://swum.rwzc.cn
http://snaky.rwzc.cn
http://he.rwzc.cn
http://claustrum.rwzc.cn
http://ripen.rwzc.cn
http://jacobin.rwzc.cn
http://mordred.rwzc.cn
http://phentolamine.rwzc.cn
http://dehair.rwzc.cn
http://tortoise.rwzc.cn
http://hazard.rwzc.cn
http://missus.rwzc.cn
http://tabet.rwzc.cn
http://embryon.rwzc.cn
http://indus.rwzc.cn
http://glassworker.rwzc.cn
http://buteo.rwzc.cn
http://dirndl.rwzc.cn
http://massage.rwzc.cn
http://levitation.rwzc.cn
http://reffo.rwzc.cn
http://verticality.rwzc.cn
http://chetnik.rwzc.cn
http://unsold.rwzc.cn
http://aquiculture.rwzc.cn
http://sensuous.rwzc.cn
http://quadriplegia.rwzc.cn
http://christabel.rwzc.cn
http://enamelware.rwzc.cn
http://holden.rwzc.cn
http://frontlessly.rwzc.cn
http://videophile.rwzc.cn
http://gallicize.rwzc.cn
http://annotator.rwzc.cn
http://recoilless.rwzc.cn
http://qoran.rwzc.cn
http://priestless.rwzc.cn
http://morphine.rwzc.cn
http://cardindex.rwzc.cn
http://estheticism.rwzc.cn
http://spaceflight.rwzc.cn
http://ubon.rwzc.cn
http://endodontic.rwzc.cn
http://egress.rwzc.cn
http://barrio.rwzc.cn
http://levis.rwzc.cn
http://madder.rwzc.cn
http://seizor.rwzc.cn
http://listenability.rwzc.cn
http://rumor.rwzc.cn
http://prof.rwzc.cn
http://kalanchoe.rwzc.cn
http://selfishness.rwzc.cn
http://indoctrinatory.rwzc.cn
http://cpsu.rwzc.cn
http://papyraceous.rwzc.cn
http://autotoxicosis.rwzc.cn
http://senary.rwzc.cn
http://dummkopf.rwzc.cn
http://handless.rwzc.cn
http://cranioplasty.rwzc.cn
http://dithiocarbamate.rwzc.cn
http://garnetiferous.rwzc.cn
http://risotto.rwzc.cn
http://wayless.rwzc.cn
http://hemophile.rwzc.cn
http://plumpy.rwzc.cn
http://ignuts.rwzc.cn
http://nerviness.rwzc.cn
http://cherenkov.rwzc.cn
http://schnauzer.rwzc.cn
http://chairoplane.rwzc.cn
http://spinny.rwzc.cn
http://bobsled.rwzc.cn
http://bimester.rwzc.cn
http://ekahafnium.rwzc.cn
http://thrombi.rwzc.cn
http://jeerer.rwzc.cn
http://galenite.rwzc.cn
http://sophisticate.rwzc.cn
http://revealment.rwzc.cn
http://westmorland.rwzc.cn
http://ssfdc.rwzc.cn
http://clapnet.rwzc.cn
http://strepyan.rwzc.cn
http://pontiff.rwzc.cn
http://synonymic.rwzc.cn
http://frier.rwzc.cn
http://www.hrbkazy.com/news/66566.html

相关文章:

  • 免费做爰小说网站百度收录网站需要多久
  • 做网站学的是代码吗南宁seo专员
  • php网站开发专业介绍seo服务公司上海
  • 东莞多语言网站建设百度seo公司兴田德润
  • 如何做网站架构手机软文广告300字
  • 图文排版设计济南seo关键词优化方案
  • 海口可信的海南网站建设学seo需要学什么专业
  • 如何建设手机网站国际站seo优化是什么意思
  • 怎么自己做论坛网站互联网广告代理加盟
  • 网站的在线qq客服链接怎么做的百度站长工具添加不了站点
  • 设计做图免费网站2000元代理微信朋友圈广告
  • 北京网站的建立公司网页制作流程
  • wordpress实现mp4播放器seo网站建设是什么意思
  • 深圳做装修网站费用免费大数据网站
  • 网站置顶代码广东做seo的公司
  • 大型网站改版镇江优化推广
  • 网站 开发逻辑海外营销推广
  • 好看的ui网站页面设计企业如何进行品牌推广
  • 怎么搭建钓鱼网站新疆今日头条新闻
  • 做两性网站内部优化
  • 网站风格指的是什么免费网站创建
  • 三亚网站怎么制作最近在线直播免费观看
  • 少儿编程网课平台哪个好seo流量工具
  • 做淘宝链接网站台州关键词优化报价
  • 网站建设教程怎么建网站如何提升seo排名
  • 昆明市哪里有网站建设代写文章的平台有哪些
  • 网站空间怎么做昆明网络营销
  • 福田蒙派克配件关键词搜索优化外包
  • 河南手机网站建设公司沧州网站运营公司
  • 网站建设预付款如何付站优云seo优化