您现在的位置:计算机技术学习网 > 技术中心 > 编程开发 > C >

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

来源:不详 责任编辑:栏目编辑 发表时间:2013-07-01 21:21 点击:

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

enum p_r_s{
   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;
   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

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Glib实例学习(2)双链表
    • C程序员要学C++吗?
    • C++中实现Singleton的正确方法
    • 编程思维训练(一)
    • 【编程好习惯】引入中间变量使程序更易读
    • 在C++中通过模板规避潜在错误
    • 在C++中通过模板去除强制转换
    • 【编程好习惯】减少搜索头文件的目录数
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1