用c语言编写你和计算机玩猜拳游戏,五局三胜,在屏幕上显示每局情况和最终结果

用c语言编写你和计算机玩猜拳游戏,五局三胜,在屏幕上显示每局情况和最终结果,第1张

找到一个,看看合适不。

如下:

enum p_r_s{

paper,rock,scissors,game,help,instructions,quit

}; /枚举变量,paper表示包袱,rock表示石头,scissors表示剪子/

#include <stdioh>

main()

{

enum p_r_s player,machine;

enum p_r_s selection_by_player(),selection_by_machine();

int win,lose,tie;

win=lose=tie=0;

instructions_for_the_player();

while((player=selection_by_player())!=quit)

switch(player){

case paper:

case rock:

case scissors:

machine=selection_by_machine();

if(player==machine){

++tie;

printf("\n a tie");

}

else if(you_won(player,machine)){

++win;

printf("\n you won");

}

else{

++lose;

printf("\n i won");

}

break;

case game:

game_status(win,lose,tie);

break;

case instructions:

instructions_for_the_player();

break;

case help:

help_for_the_player();

break;

}

game_status(win,lose,tie);

printf("\n\nBYE\n\n");

}

instructions_for_the_player()

{

printf("\n%s\n\n%s\n\n%s\n%s\n%s\n\n%s\n%s\n%s\n\n%s\n%s\n%s",

"PAPER,ROCK,SCISSORS",

"In this game",

"p is for paper,",

"r is for rock,",

"s is for scissors",

"Both the player and the machine will choose one",

"of p,r,or s If the two choices are the same,",

"then the game is a tie Otherwise:",

"\"paper covers the rock\" (a win for paper),",

"\"rock breaks the scissors\" (a win for rock),",

"\"scissors cut the paper\" (a win for scissors)");

printf("\n\n%s\n\n%s\n%s\n%s\n%s\n\n%s\n\n%s",

"There are other allowable inputs:",

"g for game status (the number of wins so far),",

"h for help,",

"i for instructions (reprin these instructions),",

"q for quit (to quit the game)",

"This game is played repeatedly until q is entered",

"Good luck!");

}

enum p_r_s selection_by_player()

{

char c;

enum p_r_s player;

printf("\n\ninput p,r,or s:");

while((c=getchar())==''||c=='\n'||c=='t');

;

switch(c){

case 'p':

player=paper;

break;

case 'r':

player=rock;

break;

case 's':

player=scissors;

break;

case 'g':

player=game;

break;

case 'i':

player=instructions;

break;

case 'q':

player=quit;

break;

default:

player=help;

}

return(player);

}

enum p_r_s selection_by_machine()

{

static int i;

i=++i%3;

return((i==0) paper:((i==1) rock:scissors));

}

you_won(player,machine)

enum p_r_s player,machine;

{

int victory;

if(player==paper)

victory=machine==rock;

else if(player==rock)

victory=machine==scissors;

else/player==scissors/

victory=machine==paper;

return(victory);

}

game_status(win,lose,tie)

{

printf("\nGAME STATUS");

printf("\n\n%7d%s\n%7d%s\n%7d%s\n%7d%s",

win,"games won by you",

lose,"games won by me",

tie,"game tied",

win+lose+tie,"games played:");

}

help_for_the_player()

{

printf("\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s",

"the following characters can be used for input:",

" p for paper",

" r for rock",

" s for scissors",

" g to find out the game status",

" h to print this list",

" i to reprint the instructions for this game",

" q to quit this game");

}

#include <stdioh>

#include <timeh>

int main()

{

int a,b,i,m=0,n=0;

srand(time(NULL));

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

{

a=rand()%3+1;

printf("%d",a);

b=rand()%3+1;

printf("%d\n",b);

if(a>b) m++;

else if(a<b) n++;

if(m>3)

{

printf("a is the winner");

break;

}

if(n>3)

{

printf("b is the winner");

break;

}

}

return 0;

}

#include "stdioh"

#include <stdlibh>

void fun(int a);

void main()

{

int i;

//i 改为随机数可以了:rand()%x x表示随机数在0--x之间

i = rand()%100;//i 是0--100之间的一个随机数

fun(i);

}

void fun(int a)

{

int j;

int flag = 1;//标记输入的次数

scanf("d%", &j);

do

{

if(j > i)

printf("输入过大!请重新输入/n");

else if(j < i)

printf("输入过小!请重新输入/n");

else

{

printf("输入正确!/n");

printf("输入次数为:d%", flag);

break;

}

scanf("%d", &j);

flag++;

}while (flag <= 20);

}

以上就是关于用c语言编写你和计算机玩猜拳游戏,五局三胜,在屏幕上显示每局情况和最终结果全部的内容,包括:用c语言编写你和计算机玩猜拳游戏,五局三胜,在屏幕上显示每局情况和最终结果、C语言 怎么用C语言设计一个猜拳游戏 剪刀石头布用1.2.3代替 要玩5局3胜,、用C语言编制猜数游戏程序,请问该怎么写等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10643416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存