c语言程序设计猜拳小游戏答辩,C语言课程设计-猜拳游戏

C语言课程设计-猜拳游戏

C语言课程设计-猜拳游戏|c语言程序代码编程小程序设计|c语言课程设计报告课程案例

enum p_r_s{

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

};

#include

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

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值