求程序,下面是剪刀石头布的程序,谁能帮忙改成能选择三局两胜,五局三胜……的?能成功运行的加分

求程序,下面是剪刀石头布的程序,谁能帮忙改成能选择三局两胜,五局三胜……的?能成功运行的加分,第1张

#include<windows.h>

#include<iostream>

using namespace std

class Play

{

public:

int People

unsigned long Computer

public:

Play(){}

~Play(){}

void Set_People(int _p)

{

People=_p

}

void Set_Computer(unsigned long _C)

{

Computer=_C

}

int Judge()

{

switch(People)

{

case 0:

cout<<"你所选择的是石头 :"

break

case 1:

cout<<"你所选择的是剪刀 :"

break

case 2:

cout<<"你所选择的是布 :"

break

}

switch(Computer)

{

case 0:

cout<<"电脑选择的是石头"

break

case 1:

cout<<"电脑选择的是剪刀"

break

case 2:

cout<<"电脑选择的是布"

break

}

cout<<endl

if(People+1==Computer || People-2==Computer)

return 1

if(People==Computer)

return 0

return -1

}

}

#define AllCount 5 // 输入你要选择的赛制,5为五局三胜,3为三局两胜

#define WinCount AllCount / 2 + 1

void main()

{

Play play

int a=5

int failure=0,win=0,tie=0

unsigned long begin

while(a!=-1)

{

begin=GetTickCount()

cout<<"****************** 请选择 *******************"<<endl

cout<<"*********0石头 1剪刀 2布 -1退出**********"<<endl

cout<<"请输入 :"

cin>>a

system("cls"基消型)

if(a<=2 &&a>-1)

{

play.Set_People(a)

play.Set_Computer(begin%3)

switch(play.Judge())

{

case 1:

//cout<<"恭喜你赢了"<<endl

win++

if (win == WinCount) {

cout<<"恭喜你赢了"<<endl

win = 0

}

break

case 0:

cout<<"你未获胜,请继续"<<endl

tie++

break

case -1:

//cout<<"不幸,你输了了"<<endl

failure++

if (failure == WinCount) {

cout<<"你未获胜,请继续"<<endl

failure = 0

}

break

}

}

else

{

if(a!=-1)

cout<<"选择错误 ,请桥毕重新选择"<<endl

}

}

cout<<"你总共下了: "<<搏猜failure+win+tie<<"次 "<<"你赢了: "<<win<<"次 "<<"输了:"<<failure<<"次 "<<"平局:"<<tie<<"次"<<endl

}

你这代码有问题啊,case那里轿斗,达不到效果

应该是:

case 65:

case 97:

gamer=4

break

后面的也要改成相应的格式

最好粘贴代码尺脊,不要图,方便帮你陵帆渗调试

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main(void)

{

char player

char computer

srand ((unsigned)time(NULL))// 随机数种子

while(1)

{fflush(stdin)

printf("欢迎来到猜拳小游戏,请选择你要出的手势:\n")

printf("a剪刀\nb石头\nc布\n")

scanf("%c"穗前,&player)

if (player==65 || player==97)printf("你出了剪刀,")

else if (player==66 || player==98)printf("你出了石头,")

else if (player==67 || player==99)printf("你出了布,")

else printf("输入错误,请重试:\n")

if(player>67)player-=32

computer = rand()%3+1// 产生随机数,得到电脑出拳

printf("电脑出了")

switch (computer)

{

case 1:printf("剪刀\n"销悉)break

case 2:printf("石头\n")break

case 3:printf("布\n")break

}

if (player==65 &&computer==3)//剪刀——布

printf("你赢了!\n")

else if (player==66 &&computer==1)//石头——剪刀

printf("你赢了!\n")

else if (player==67 &&computer==2)//布——石头

printf("你赢了!\n")

else if (player==67 &&computer==1)//布——剪刀

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

else if (player==65 &&computer==2)//剪刀——石头

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

else if (player==66 &&computer==3)//石头——布

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

else if (player==65 &&computer==1)//都出剪刀

printf("平手亏族乎!\n")

else if (player==66 &&computer==2)//都出石头

printf("平手!\n")

else if (player==67 &&computer==3)//都出布

printf("平手!\n")

printf("\n")

}

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12503776.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存