c语言课程设计_猜拳游戏

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

};

#include <stdio.h>

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;

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

}

 

第二篇:C语言课程设计总结

一周的计算机C语言课程设计很快就结束了,回想这一周,几分欣喜,几分紧张,欣喜的是学了C语言能得到应用,紧张的是怕自己不能更好的设计自己的程序,生怕自己设计的程序不能顺利的完成。不过在老师的帮助下,在我们组员的共同的努力下,我们能很好而顺利的将程序设计并且运行出来,虽然有几处不足但在老师的改正下我们的程序也得到了完善。

通过这一周的C语言课程设计,我懂得了很多,它让我知道做事情需要认真与细心,需要耐心与恒心。就拿我们的程序来说把,起初做完运行后有很多错误,当时我们组每个人都非常焦虑,的确,看着长长的程序想要去一一把问题解决也并非是件简单的事,但如果你静下心来细心的去找就会把错误一个一个的找出来。还有一点是非常重要的,那就是有不懂的地方及时向老师提问,那样的话你就会对不懂的地方有个深刻的理解,以后再碰到此类问题自己也就能解决了。所以我们的程序是在老师的帮助下,在我们组成员的耐心的查找与改正下完成的。我们的成功离不开老师的指导,离不开我们的共同努力。看着运行出来的程序我们笑了,真的,当时的心情真的想不出用哪个词语去形容,也许笑容代表了一切。

短短的几天时间让我对C语言有了一个全新的概念,它不仅是一门课程,更是一门技术。也使我领会到实践的重要性,我希望在以后的学习生活中我会有更多的实践机会来提高我的思考能力与动手能力,培养我的细心、耐心与恒心。这是难忘的一次实训课程,它会在我的人生旅途中写上浓重的一笔。感谢老师的指导帮助,感谢同组兄弟的支持,谢谢! 未来的社会必将是科学技术全面,全面发展的社会,我们需要更应该懂得并掌握现代化的科学知识,C语言是一门全新的课程,也许当我们初次接触这门课程会感觉到新鲜,当你更加深入的学习它你会体会到它的乐趣与方便,而未来的社会也正需要全能型的人才,让我们共同努力吧,学会更多的知识技术,为了美好的未来而加油!

相关推荐