GO语言实现石头剪刀布,小班语言石头剪刀布教案

求大神帮忙编个剪刀石头布的C++程序

#include stdio.h

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比铁山网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式铁山网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖铁山地区。费用合理售后完善,10多年实体公司更值得信赖。

#include iostream

#include time.h

int getrand()

{

//srand((unsigned)time(NULL));

return rand()%3;

}

int win(int me,int cpu)

{

if(me==2cpu==0)

return -1;

else if (me==0cpu==2)

return 1;

else if(me==cpu)

return 0;

else if(mecpu)

return 1;

else

return -1;

}

int exchange(char input)

{

int i=0;

switch(input) {

case 'S':

case 's':

i = 2;

break;

case 'p':

case 'P':

i = 1;

break;

default:

i = 0;

}

return i;

}

int main(void)

{

char c='a';

char msg[3][10] = {"rock","paper","scissors"};

int me,cpu;

while(1){

printf("Enter R(ock), P(aper), or S(cissors) ");

flushall();

scanf("%c",c);

if(c=='q'||c=='Q') break;

me = exchange(c);

cpu = getrand();

printf("You played %s.\n",msg[me]);

printf("The computer played %s.\n",msg[cpu]);

if(win(me,cpu)==1)

printf("You win!\n");

else if(win(me,cpu)==-1)

printf("The computer win!\n");

else

printf("Go go go!\n");

}

return 0;

}

C语言石头剪刀布程序

帮你修改了一下判断部分。你试试吧:

#include stdio.h

#include stdlib.h

#includesys/types.h

#includesys/timeb.h

main()

{

loop:

printf("欢迎来玩石头剪刀布,请使用键盘输入,0代表石头,1代表剪刀,2代表布。\n******************************************************\n");

int x,com,user;

unsigned int seedVal;

struct timeb timeBuf;

ftime(timeBuf);

seedVal=((((unsigned int)timeBuf.time0xFFFF)+

(unsigned int)timeBuf.millitm)^

(unsigned int)timeBuf.millitm);

srand((unsigned int)seedVal);  

x=rand();

com=x%3;

scanf("%d",user);

if(user2) 

printf("您的输入有误,请输入0、1、2中任意一个数字\n");

else 

{

if(com==0) 

{

if(user==0) printf("平手\n");

if(user==1) printf("输了\n");

if(user==2) printf("赢了\n");

}

if(com==1) 

{

if(user==0) printf("赢了\n");

if(user==1) printf("平手\n");

if(user==2) printf("输了\n");

}

if(com==2) 

{

if(user==0) printf("输了\n");

if(user==1) printf("赢了\n");

if(user==2) printf("平手\n");

}

}

goto loop;

}

用c++编写一个石头剪刀布,R为石头S为剪刀P为布

#include iostream

#include ctime

#include random

using namespace std;

void print(int b){

if(b==0) cout"R ";

else if(b==1) cout"S ";

else if(b==2) cout"P ";

}

void select(int a,int b){

if(a==0){

if(b==0) cout"TIE\n";

else if(b==1) cout"Player2\n";

else if(b==2) cout"Player1\n";

}

else if(a==1){

if(b==1) cout"TIE\n";

else if(b==2) cout"Player2\n";

else if(b==0) cout"Player1\n";

}

else if(a==2){

if(b==2) cout"TIE\n";

else if(b==1) cout"Player1\n";

else if(b==0) cout"Player2\n";

}

}

int main()

{

srand(time(0));

int n;

cout"输入要进行的比赛次数,R为箭头 S为石头 P为布";

cinn;

for(int i=0;in;i++){

int player1=rand()%2;

int player2=rand()%2;

print(player1);

print(player2);

select(player1,player2);

}

return 0;

}

c语言编一个简单的剪刀石头布游戏?

用1、2、3来表示剪刀、石头、布,然后先用scanf函数读取用户的输入,再用rand函数产生一个随机数,最后进行比较就可以了。

#include

#include

#include

void

main()

{

int

com,user;

char

c;

srand((unsigned)time(null));

//初始化随机数,如果没有这条语句,每次运行电脑产生的随机数序列都是一样的

printf("进入游戏\n");

do{

printf("请出拳(1.剪刀、2.石头、3.布):");

scanf("%d",user);

com=rand()%3+1;

//产生1-3范围内的随机数

printf("电脑出%s\n",com==1?"剪刀":com==2?"石头":"布");

switch(com-user)

//用电脑产生的数和用户输入的数的差值来判断胜负

{

case

0:

printf("平手\n");

break;

case

1:

case

-2:

printf("电脑赢了\n");

break;

case

-1:

case

2:

printf("你赢了\n");

}

printf("继续游戏按y键、其它键退出");

getchar();

c=getchar();

}while(c=='y'

||

c=='y');

printf("已经退出游戏");

}

C语言编程:剪刀石头布的小游戏

#include iostream

using namespace std;

#include ctime

#include cstdlib

int cchuquan()

{

int t;

srand(time(0)); //seed

t = rand() % 3+ 1; // random number 1-3

if(t==1)

{

cout"电脑出的为剪刀!"endl;

}

else if(t==2)

{

cout"电脑出的为石头!"endl;

}

else

{

cout"电脑出的为布!"endl;

}

return t;

}

int iswin(int n,int m)

{

if(n==m)

{

return 0;

}

else if(n==1m==2)

{

return -1;

}

else if(n==1m==3)

{

return 1;

}

else if(n==2m==1)

{

return 1;

}

else if(n==2m==3)

{

return -1;

}

else if(n==3m==1)

{

return -1;

}

else

{

return 1;

}

}

int main()

{

const int jiandao=1;

const int shitou=2;

const int bu=3;

cout"请输入你要选择的局数(必须为奇数且大于1):";

int n;

cinn;

int win=0,shu=0;

for(int i=0;in;++i)

{

cout"请出拳: 1:为剪刀;2:为石头;3:为布"endl;

int flag;

cinflag;

if(flag==1)

{

cout"你出的为剪刀!"endl;

}

else if(flag==2)

{

cout"你出的为石头!"endl;

}

else

{

cout"你出的为布!"endl;

}

int cf=cchuquan();

if(iswin(flag,cf)==1)

{

++win;

}

else if(iswin(flag,cf)==-1)

{

++shu;

}

}

if(win-shu0)

{

cout"恭喜你获胜!"endl;

}

else

{

cout"非常遗憾!你失败了!"endl;

}

return 0;

}

c++写的 呵呵 你可以参考

用C语言编写一个游戏:剪刀,石头,布的,用随即数来实现。哪位大大帮帮

/************************************************

* Copyright(C) 2007 babybubble

* Author: babybubble

* Date: 2007-9-20

* Description: 0表示剪刀,1表示石头,2表示布

**********************************************/

#includestdio.h

#includetime.h

#includestdlib.h

/***********************

* a与b游戏

* 如果a赢,返回1

* 如果a输,返回-1

* 如果相同,返回0

***********************/

int fight(int a, int b)

{

int result;

result=a-b;

if (result==2) result=-1;

else if (result==-2) result=1;

return result;

}

int main()

{

int computer,player;

srand(time(0));

while (1)

{

printf("0 剪刀\n1 石头\n2 布\n3 退出\n");

printf("please input your choice number: ");

scanf("%d",player);

if (player=0player=2)

{

computer=rand()%3;

if (computer==0) printf("我出剪刀!\n");

else if (computer==1) printf("我出石头!\n");

else printf("我出布!\n");

if (fight(computer,player)==1) printf("I win!!! ^_^\n");

else if (fight(computer,player)==-1) printf("You win... T_T\n");

else printf("The same\n");

}

else if (player==3) break;

else printf("wrong input!\n");

}

return 0;

}

分享文章:GO语言实现石头剪刀布,小班语言石头剪刀布教案
文章路径:https://www.cdcxhl.com/article12/hchidc.html

成都网站建设公司_创新互联,为您提供用户体验关键词优化网站收录响应式网站外贸网站建设网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

微信小程序开发