C语言 怎么用C语言设计一个猜拳游戏 剪刀石头布的游戏作文用1.2.3代替 要玩5局3胜,

藤本植物导航
&>&&>&&>&正文
编写一个C程序,模拟一个“剪刀、石头、布”的游戏。实现的是“人机对战”。...#include #include #include void main() { int w,c,i=0,j=0,k=0; printf("我们来玩剪刀石头布的游戏0代表石头,1代表剪刀,2代表布\n"); do { do { printf("请出拳"); scanf("%d",&w); if(w2) { printf("输入有误,请从新输入"); } }w...
编写一个C程序,模拟一个“剪刀、石头、布”的游戏
}while(w&n&quot,c.h&gt!;n&k) {
printf(&)!,请从新输入&);
c=rand()%3;k) {
printf(&平了&||ch==&#39.h&/
printf(&;#include&lt!,电脑出%d\);,i=0;
fflush(stdin)!,i;n\#include&lt,k=0;
else if(w==0&&c==1||w==1&&c==2||w==2&&c==0)
printf(&n&输了 &quot:#include& } else if(j&%求余可以控制随机数的大小;输入有误;void main(){srand(time(NULL));您的坏运气已经用光了.h&gt,1;
printf(&赢了&quot,2代表布\void main(){
printf(&quot!;请出拳&quot.h& }while(ch=='n&quot!;n&quot.h& printf(&
ch=getchar();time!&#92!,接下来都是好运气;您真棒,k),&w);n&我出%d!;#include&),平了%d次!!,j=0,神人啊;
char ch!;
printf(&#include& do { do
printf(&quot,1代表剪刀;竟然能打去平手; printf(&quot!;int c=rand()%3;
scanf(&quot!;2);
k++,w,可以控制玩得次数随机数;共玩了%d次;我们来玩剪刀石头布的游戏0代表石头;)!\
srand(time(NULL));
if(w&lt#include&);/
printf(&y'Y',c),i+j+k; }} 以前做的!, 赢了%d次输了%d次\2)
j++;);n &0||w&0||w& if(j&gt.h&gt!&#92!;&#47!;
i++;);););y/%d&stdlib,2)/比如跟三取模得到的随机数比三小(0编写一个C程序,模拟一个“剪刀、石头、布”的游戏#include&stdio.h&#include&stdlib.h&#include&time.h&void main(){ int w,c,i=0,j=0,k=0;
printf(&我们来玩剪刀石头布的游戏0代
编写一个C程序,模拟一个“剪刀、石头、布”的游戏。实现的是“人机对战”。 建议思路如下:由程序产生一个1 ~ 3随机数,1代表剪刀,2代表石头,3代表布;然后计算机用户从键盘上输入一个整数,同样1代表剪刀,2代表石头,3代表布,程序给出对战结果(输、赢...
编写一个C程序,模拟一个“剪刀、石头、布”的游戏。实现的是“人机对战”。...#include #include #include void main() { int w,c,i=0,j=0,k=0; printf("我们来玩剪刀石头布的游戏0代表石头,1代表剪刀,2代表布\n"); do { do { printf("请出拳"); scanf("%d",&w); if(w2) { printf("输入有误,请从新输入"); } }w...怎么用C语言编写一个和电脑玩石头剪刀布的程序?用1、2、3来表示剪刀、石头、布,然后先用scanf函数读取用户的输入,再用rand函数产生一个随机数,最后进行比较就可以了。 #include #include #include void main() { int com, srand((unsigned)time(NULL)); //初始化随机数,如果...在线等定义0、1、2三个数分别代表剪刀石头和布 通过生成一个随机数(0-2)与输入的数据对比就好了 然后根据规则(游戏规则)判断输赢 如果自己不想写代码的话 我可以提供有偿代劳用c语言编写一个游戏 游戏规则用户选择出拳的数字(1、石头 2、剪刀 3、...#include#includechar *ch[100] = {"剪刀", "石头" ,"布"};void show_menu(){printf("*******************************\n");printf("1 %s\n", ch[0]);printf("2 %s\n", ch[1]);printf("3 %s\n", ch[2]);printf("4 quit\n");printf("************...问题描述: 玩家和电脑进行石头剪子布游戏,可以反复进行,直到玩家不想...#include #include #include int main(){ int playerWin = 0, computerWin = 0, balance = 0; scanf_s( "%d", &player ); while( player != 0 ) { srand( time( 0 ) ); computer = rand() % 3 + 1; if( computer == p...【基本要求】 编程模拟剪刀、石头、布的游戏。用s表示尖刀,r表示石头,...#include void main() { char a,b,c; do{ cout#include &stdio.h& #include &stdlib.h& #include &time.h& int main()...#include #include #include /*************\ * 剪刀 石头 布 * * 最简单小游戏 * \*************/ int main(void){ char gesture[3][10] = {"scissor","stone","cloth"}; int man, computer, result, /*随机数初始化函数*/ srand(time(NUL...用C语言编写一个石头剪子布游戏。 基本要求:1.能够实现输入玩家姓名,...#include #include #include void main () { char a, srand ((unsigned)time (NULL)); //产生随机数种子 while (1) { cout & int m = (int) (3 * rand () / (RAND_MAX + 1)); //产生从0到2的随机数,a+(int)(n*rand()...srand(time(0)); 这个只需要运行一次就行了,放在循环体前边就行了刚刚的有点问题,现在改好了: #include #include #include #include char name[100],way[3][10]={"石头","剪子","布"},mode_name[2][20]={"三局两胜","五局三胜"}; void new_game(int mode,int *p_win,int * p_lose,int *p_tide){ char cmd[10]...
种植经验最新
种植经验推荐
& 6种植网 版权所有
渝ICP备号-23用C语言编写一个石头剪子布游戏,具体要求如下,高分急求-C语言剪刀石头布游戏如何设置实战模式和练习模式 _汇潮装饰网
您当前位置:
用C语言编写一个石头剪子布游戏,具体要求如下,高分急求
用C语言编写一个石头剪子布游戏,具体要求如下,高分急求
C语言编写一个石头剪子布游戏。基本要求。
2.实现选择赛制(三局两胜,五局三胜)相关说明:
这只是大一期末一道题而已,没有很难吧,写段程序在VC++上编译运行一下就行
&quot刚刚的有点问题,现在改好了:#include&stdio.h&gt:%s&n&;printf(& 可惜!;t%s\/******************石头剪子布游戏 ******************\lose){printf(&printf(&***当前模式:\t赢\n&);***%-10s:%s\#include&printf(&quot,&tide);else if(cmd[0]=='}return 0;***比赛情况;lose+cnt[mode]-i-1 || lose&\t 2 -- 剪子\t 3 -- 布\}else{(*p_tide)++;printf(&quot:\t%d\t输;}}int main(){srand(time(0)):\t&n&,win=0:\t%d\n&string.h&\t电脑\t赢\int win,lose!\n&1&#39,5};printf(&***当前模式:\tQ -- 退出;\n&,name,way[user]),win=lose=tide=0; || cmd[0]=='n')new_game(mode,&}else{printf(&quot!\n&printf(&***%-10s;char name[100],way[3][10]={&石头&;0');请输入玩家姓名!\n&t%s&#92,way[computer]);if(computer==user){printf(&quot,mode_name[2][20]={&n&);}else if(user-computer==-1 || user-computer==2){printf(&&#92:\t%s\n&,win,,name);win++;name[strlen(name)-1]='\ || cmd[0]=='q')elsemode=1-n&);lose++;}if(win&;while(1){printf(&n&);fgets(cmd,9,stdin);stdlib.h&if(cmd[0]==' 此局平局;);char cmd[10];i&cnt[mode];i++){printf(&***1 -- 石头;if(user&0)user+=3;computer=rand()%3;printf(&,&布&quot,lose=0;int cnt[2]={3;fgets(t%s&#92,99,stdin);n&......
选择模式1。\n\n&int userWinNum = 0;for (i=1; i&rule*2+1;case 3:printf(&布\n&, name, userWinNum, computerWinNum);恭喜你:&int computerT} else {return 1;模式选择错误!请输入1或2进行选择;printType(computerType);printf(&%s;scanf(&n&);}case 2;);n&);} else if (computerWinNum == (rule*2+1)/, &userType);} while(userType == 1 || userType == 2 || userType == 3);printf(&平局,此局重来\int computerWinNum = 0!= 2) {printf(&, name);case -1;printType(userType);switch (Compare(userType, computerType)) {case 0:i--!\n&printf(&quot:&if (userWinNum == (rule*2+1)/2 + 1) {printf(&quot. 三局两胜;);%d&n&);break:&quot,你赢了!!\你输了. 布&} else {return -1;}break;3:\n%s:%d&#92:&);case 2:printf(&剪刀\);, &rule);if (rule != 1 &&}switch (computerType) {case 1:if (userType == 2) {return -1;n&);%d&case 1:userWinNum++;printf(&你赢了!\);}}}int main() {char name[20];n电脑. 五局三胜;printf(&).石头;2.剪刀;int userT第%d局,请出;} else {return 1;case 3:if (userType == 1) {return -1;}printf(&当前比分;}}int Compare(int userType, int computerType) {if (userType == computerType) {return 0;n&quot......Please input player name:wydChoose (A)5/3 or (B)3/2:aSelect Jiandao(J) or Shitou(S) or Bu(B): sComputer is Shitou(S)The same!Select Jiandao(J) or Shitou(S) or Bu(B): bComputer is Jiandao(J)You Lost!Select Jiandao(J) or Shitou(S) or Bu(B): jComputer is Jiandao(J)The same!Select Jiandao(J) or Shitou(S) or Bu(B): sComputer is Shitou(S)The same!Select Jiandao(J) or Shitou(S) or Bu(B): bComputer is Shitou(S)You Win!5 rounds, 1 win,3 same,1 lost,The Same!Press any key to continue#include &stdio.h&#include &stdlib.h&#include &time.h&main(){int i,randAI,playerGuess,score[3]={0},char sel,player[20]={0},game[3][12]={&Jiandao(J)&,&Shitou(S)&,&Bu(B)&};srand((unsigned)time(NULL));printf(&Please input player name:&);gets(player);printf(&Choose (A)5/3 or (B)3/2:&);scanf(&%c&,&sel);if (sel=='A' || sel=='a')round =5;else if (sel=='B' || sel=='b')round =3;elseprintf(&select error!\n&);for (i=0;i&i++){randAI= rand()%2;printf(&Select %s or %s or %s: &,game[0],game[1],game[2]);fflush(stdin);scanf(&%c&,&sel);printf(&Computer is %s&,game[randAI]);if (sel=='J' || sel =='j' )playerGuess=0;else if (sel =='S' || sel =='s')playerGuess=1;else if (sel =='B' || sel =='b')playerGuess=2;els......#include &stdio.h&#include &stdlib.h&#include &time.h&int main(){
char name[100];
int system_
int usrwin=0,syswin=0,nowin=0;
printf(&please in put you name:\n&);
scanf(&%s&,name);
printf(&please input how many games do you want to play:\n&);
scanf(&%d&,&num);
while (num == 0 || (num %2) == 0)
printf(&the num must be singular,please input a right number again:\n&);
scanf(&%d&,&num);
int temp = 1;
for (temp&= temp++)
printf(&%d: input you chocice:(0:shi tou 1:jian zi 2:bu)&,temp);
scanf(&%d&,&usr_select);
while( usr_select &0 || usr_select &2 )
printf(&your choice is error,please input again(0:shi tou 1: jian zi 2:bu)\n&);
scanf(&%d&,&usr_select);
srand(time(0));
system_select= rand()%3;
if(usr_select - system_select == -1 || usr_select-system_select == 2)
printf(&you win!\n&);
else if(usr_select == system_select)
printf(&no one win\n&);
printf(&system win\n&);
if(usrwin ......#include &stdio.h&#include &stdlib.h&#include &time.h&char *words[3]={&石头&,&剪刀&,&布&};//本程序用S代表石头,C代表剪刀,P代表布//本程序假设用户所有的输入,都是遵循电脑的提示进行的正确输入,不考虑输入错误的处理void main(){char name[81];//玩家姓名//代表赛制//代表你出的东东int you,//代表你和电脑出的东东int win,lose,srand( (unsigned)time( NULL ) ); //初始化随机数种子printf(&欢迎参加猜挙比赛,请输入您的名字:&);gets(name);printf(&欢迎您,%s\n&,name);printf(&本次猜挙比赛,您想采取哪种赛制?(1.三局两胜\t2.五局三胜):&);scanf(&%d&,&mode);//此处不考虑用户输入1,2以外数字或非数字字符的情况getchar();//过滤回车if(mode==1)printf(&您选择了三局两胜制\n&);else if(mode==2)printf(&您选择了五局三胜制\n&);printf(&比赛开始!!!\n&);win=lose=deuce=0;while(1){printf(&请出拳{石头:(S/s),剪刀(C/c),布(P/p)}:&);input=getchar(); //此处不考虑用户输入了其他字符的情况getchar();//过滤回车if(input=='S' || input=='s')you=0;else if(input=='C' || input=='c')you=1;else you=2;computer=rand()%3;printf(&你出了%s,电脑出了%s\n&,words[you],words[computer]);if(you-computer==-1 || you-computer==2){win++;printf(&你赢了\n&);}else if(you-computer==1 || you-computer==-2){lose++;printf(&你输了\n&);}else{deuce++;printf(&平手\n&);}if((mode==1 &......是创造这个游戏么???
先简单给你写了一下,你先看看行不行,太晚了,我得睡啦,要是不明白,明天追问就行: #include ...)
#include &stdio.h& int main(void) {printf(&hello w...)
#include&stdio.h& #include&stdlib.h& #define Size ...)
#include&stdio.h&#include&string.h&int main(){ int...)
调用window库窗口函数即可创建windows窗口。 必须使用windows的编译器,如VC,MS...)
#include &stdio.h& void main() { double data[8]; d...)
现在windows中,已经不能这样,,,,,,可以使用WIndows API的 Beep函数)
*帮助做程序主体(开始游戏部分)*/ #include &iostream.h& #include ...)
//看到你的问题后我写的 #include&stdio.h& #include&string.h& ...)
帮忙写一个算法,用c语言数值下标是从0开始的,array[0...5,0...7](1)数组A的体积...) 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
《C语言课程设计报告--小游戏“石头剪子布”》
下载积分:1000
内容提示:《C语言课程设计报告--小游戏“石头剪子布”》
文档格式:DOC|
浏览次数:84|
上传日期: 17:07:58|
文档星级:
全文阅读已结束,如果下载本文需要使用
 1000 积分
下载此文档
该用户还上传了这些文档
《C语言课程设计报告--小游戏“石头剪子布”》
官方公共微信C语言小游戏编程之剪刀石头布
这是一个简单的C语言小游戏编程猜拳游戏(剪刀石头布),让你与电脑对决。你出的拳头由你自己决定,电脑则随机出拳,最后判断胜负。
下面的代码会实现一个C语言猜拳游戏,让你与电脑对决。你出的拳头由你自己决定,电脑则随机出拳,最后判断胜负。
C语言启动程序后,让用户出拳,截图:
用户出拳,显示对决结果:截图:
代码实现:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
char gamer; // 玩家出拳
int computer; // 电脑出拳
int result; // 比赛结果
// 为了避免玩一次游戏就退出程序,可以将代码放在循环中
while (1){
printf("这是一个猜拳的小游戏,请输入你要出的拳头:\n");
printf("A:剪刀\nB:石头\nC:布\nD:不玩了\n");
scanf("%c%*c",&gamer);
switch (gamer){
case 65: //A
case 97: //a
case 66: //B
case 98: //b
case 67: //C
case 99: //c
case 68: //D
case 100: //d
printf("你的选择为 %c 选择错误,退出...\n",gamer);
getchar();
system("cls"); // 清屏
srand((unsigned)time(NULL)); // 随机数种子
computer=rand()%3; // 产生随机数并取余,得到电脑出拳
result=(int)gamer+computer; // gamer 为 char 类型,数学运算时要强制转换类型
printf("电脑出了");
switch (computer)
case 0:printf("剪刀\n");break; //4 1
case 1:printf("石头\n");break; //7 2
case 2:printf("布\n");break; //10 3
printf("你出了");
switch (gamer)
case 4:printf("剪刀\n");break;
case 7:printf("石头\n");break;
case 10:printf("布\n");break;
if (result==6||result==7||result==11) printf("你赢了!");
else if (result==5||result==9||result==10) printf("电脑赢了!");
else printf("平手");
system("pause&nul&&cls"); // 暂停并清屏
首先,我们需要定义3个变量来储存玩家出的拳头(gamer)、电脑出的拳头(computer)和最后的结果(result),然后给出文字提示,让玩家出拳。
接下来接收玩家输入:
scanf("%c%*c",&gamer);
注意:由于每次输入以回车结束,缓冲区中除了玩家输入的字母,还有回车符。回车符要跳过,以免影响下次输入。Scanf()
函数的格式控制字符串个数可以多于参数个数,scanf(“%c%*c”,&gamer);的作用是从缓冲区多输出一个字符(回车符),却不赋给任何变量。
玩家输入结束,使用 switch
语句判断输入内容,65(A)、97(a)、66(B)、98(b)、67(C)、99(c)、68(D)、100(d)为相应字符的ASCII码。
注意:system(“cls”); 语句的作用是清屏。System() 函数用来执行 dos 命令,这里相当于在 dos 里输入
cls 命令。
2) 玩家出拳结束,电脑开始出拳。
电脑通过产生随机数来出拳:
srand((unsigned)time(NULL)); //为了避免多次运行结果相同,故在前面加入上(需要time.h)
computer=rand()%3; //获取0~2的随机数
最后通过玩家和电脑出拳的和来判断输赢:
result=(int)gamer+computer;
if (result==6||result==7||result==11) printf("你赢了!");
else if (result==5||result==9||result==10) printf("电脑赢了!");
else printf("平手");
这是一个很巧妙的算法,玩家和电脑出拳不同,result 的值就不同,且不会重复,见下表:
电脑 — 玩家 石头(4) 剪刀(7) 布(10)
石头(0) 4 7 10
剪刀(1) 5 8 11
布(2) 6 9 12
3) 每次猜拳结束,暂停并清屏,进入下一次猜拳:
system("pause&nul&&cls"); //暂停运行和清屏
转载请注明:&&&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(3a25e893d2938a07-ua98).
重新安装浏览器,或使用别的浏览器

我要回帖

更多关于 音乐游戏剪刀石头布 的文章

 

随机推荐