標題:
猜拳遊戲 (四)
[打印本頁]
作者:
王瑞喻
時間:
2019-11-14 17:41
標題:
猜拳遊戲 (四)
本帖最後由 王瑞喻 於 2019-11-28 00:54 編輯
需求說明:
1. 為程式加上一個適當的標題 (如: *** 猜拳遊戲 v1.0 ***)
2. 要有判斷輸入錯誤的機制
3. 加上戰果統計, 顯示總共贏了幾次, 輸了幾次, 平手幾次.
本帖隱藏的內容需要回復才可以瀏覽
作者:
洪榜蔓
時間:
2019-11-16 11:50
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b;
int win=0,lose=0,draw=0;
srand(time(NULL));
string name[]={"剪刀","石頭","布"};
cout<<"猜拳遊戲"<<endl;
start:
cout<<endl<<"請出拳! (1)剪刀 (2)石頭 (3)布 (0)結束"<<endl;
cin>>a;
if(a==0)
goto end;
else if(a>=1 && a<=3)
{
b=rand()%3+1;
cout<<"你出: "<<name[a-1]<<endl;
cout<<"電腦出: "<<name[b-1]<<endl;
if((a==1 && b==3)||(a==2 && b==1)||(a==3 && b==2))
{
cout<<"你贏了"<<endl;
win++;
}
if((b==1&&a==3)||(b==2&&a==1)||(b==3&&a==2))
{
cout<<"你輸了"<<endl;
lose++;
}
if(a==b)
{
cout<<"平手"<<endl;
draw++;
}
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
end:
cout<<endl<<"戰果統計"<<endl;
cout<<"總共贏了"<<win<<"次, 輸了"<<lose<<"次, 平手"<<draw<<"次!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭哲維
時間:
2019-11-16 11:55
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b;
int win=0,lose=0,draw=0;
srand(time(NULL));
string name[]={"剪刀","石頭","布"};
cout<<"猜拳遊戲"<<endl;
start:
cout<<endl<<"請出拳! (1)剪刀 (2)石頭 (3)布 (0)結束"<<endl;
cin>>a;
if(a==0)
goto end;
else if(a>=1 && a<=3)
{
b=rand()%3+1;
cout<<"你出: "<<name[a-1]<<endl;
cout<<"電腦出: "<<name[b-1]<<endl;
if((a==1 && b==3)||(a==2 && b==1)||(a==3 && b==2))
{
cout<<"你贏了"<<endl;
win++;
}
if((b==1&&a==3)||(b==2&&a==1)||(b==3&&a==2))
{
cout<<"你輸了"<<endl;
lose++;
}
if(a==b)
{
cout<<"平手"<<endl;
draw++;
}
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
end:
cout<<endl<<"戰果統計"<<endl;
cout<<"總共贏了"<<win<<"次, 輸了"<<lose<<"次, 平手"<<draw<<"次!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王建葦
時間:
2019-11-16 11:58
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
cout<<"---猜拳系統(Beta1.5.0)---"<<endl;
int win=0,lost=0,s=0;
re:
srand(time(NULL));
int computer,player,i;
string c[]= {"剪刀","石頭","布"};
cout<<"請出拳!"<<" (1)"<<c[0]<<"(2) "<<c[1]<<"(3) "<<c[2]<<"(4) 結束"<<" :";
cin>>player;
if(player<4)
{
goto rw;
}else if(player==4)
{
goto end;
}else if(player>4)
{
cout<<"輸入錯誤"<<endl;
goto re;
}
rw:
computer=rand()%3+1;
computer=computer-1;
player=player-1;
cout<<"你出"<<c[player]<<"!"<<endl;
cout<<"電腦出"<<c[computer]<<"!"<<endl;
if(computer==player)
{
cout<<"平手!"<<endl;
s=s+1;
cout<<endl<<endl;
goto re;
}else if(player==0&&computer==2||player==1&&computer==0||player==2&&computer==1)
{
cout<<"你贏了!"<<endl;
win=win+1;
cout<<endl<<endl;
goto re;
}else
{
cout<<"你輸了!"<<endl;
lost=lost+1;
cout<<endl<<endl;
goto re;
}
end:
cout<<"---戰果統計---"<<endl;
cout<<"贏"<<win<<"場 輸"<<lost<<"場 合局"<<s<<"場"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃傳耀
時間:
2019-11-16 11:59
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int computer,player,win = 0,lost=0;
srand(time(NULL));
string name [4]= {"剪子","石子","布","over"};
cout<<"出拳(1)剪子(2)石子(3)布(4)over";
cin>>player;
if(player == 1||player == 2||player == 3)
{
computer = rand()%3+1;
cout<<"你出"<<name[player-1];
cout<<endl;
cout<<"電腦出"<<name[computer-1];
if(player == 1)
{
if(computer == 1)
cout<<"Again!";
if(computer == 2)
{
cout<<"You Lost!";
lost+=1;
}
if(computer == 3)
{
cout<<"You Win!";
win+=1;
}
}
if(player == 2)
{
if(computer == 2)
cout<<"Again!";
if(computer == 3)
{
cout<<"You Lost!";
lost+=1;
}
if(computer == 1)
{
cout<<"You Win!";
win+=1;
}
}
if(player == 3)
{
if(computer == 3)
cout<<"Again!";
if(computer == 1)
{
cout<<"You Lost!";
lost+=1;
}
if(computer == 2)
{
cout<<"You Win!";
win+=1;
}
}
if(player == 4)
{
cout<<"win:"<<win<<" lost:"<<lost<<endl;
}
cout<<endl;
}
else
cout<<"You are beach"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
王翎璇
時間:
2019-11-16 12:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"***猜拳遊戲***"<<endl;
re:
srand(time(NULL));
int player,computer;
int win=0,lose=0,draw=0;
string name[4]={"剪刀","石頭","布","結束"};
cout<<"請出拳 (1)剪刀(2)石頭(3)布(4)結束";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手"<<endl;
draw++;
}
else if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
{
cout<<"你贏!"<<endl;
win++;
}
else
{ cout<<"電腦贏!"<<endl;
lose++;
}
cout<<endl<<endl;
goto re;
finish:
cout<<"***結算***"<<endl;
cout<<"贏了"<<win<<"次,"<<"輸了"<<lose<<"次,"<<"平手"<<draw<<"次!"<<endl;
cout<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾宥程
時間:
2019-11-16 12:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"*****猜拳3缺1*****"<<endl;
int P1,com,win=0,lose=0,draw=0;
re:
srand(time(NULL));
string name[3]={"剪刀","石頭","布",};
cout<<"請出拳!!! <1>剪刀<2>石頭<3>布<0>結束 :";
cin>>P1;
if(P1==0)
{
goto final;
}else if(P1>=1 && P1<=3)
{
cout<<"你出"<<name[P1-1]<<endl;
com=rand()%3+1;
cout<<"電腦出"<<name[com-1]<<endl;
if(P1==com)
{
draw++;
cout<<"你們平手"<<endl;
}else if(P1==1 && com==3 || P1==2 && com==1 || P1==3 && com==2)
{
win++;
cout<<"你贏了!!!!!!!!!!教師節快樂!!!!!!!!!!!!!!!!!!";
}else
{
lose++;
cout<<"你輸了!!!!!!!!!!光棍節快樂!!!!!!!!!!!!!!! 87"<<endl;
}
cout<<endl<<endl;
goto re;
}else
{
cout<<"輸入錯誤!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
goto re;
}
final:
cout<<"*****結果*****"<<endl;
cout<<"你贏了"<<win<<"場,輸了"<<lose<<"場,平手"<<draw<<"場"<<endl;
system ("pause");
return 0;
}
複製代碼
作者:
鄭羽捷
時間:
2019-11-16 12:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
cout<<"☆★☆猜拳遊戲☆★☆"<<endl;
srand(time(NULL));
int player,comuter;
int win=0,lose=0,draw=0;
cout<<"請出拳!(1)剪刀(2)石頭(3)布(0)結束";
string name[3]={"剪刀","石頭","布"};
cin>>player;
comuter=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[comuter-1]<<endl;
{
if(player==comuter)
cout<<"平手"<<endl;
draw++;
}else if((player==1 && comuter==3)||(player==2 && comuter=1)||(player==3 && comuter==2))
{
cout<<"你贏了"<<endl;
win++;
}else
{
cout<<"你輸了"<<endl;
lose++;
}else
{
cout<<"輸入錯誤";
goto re;
}
end:
cout<<"☆★☆戰果統計☆★☆"
cout<<"總共贏了"<<win<<"次,輸了"<<lose<<"次,平手"<<draw<<"次"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林孟蓁
時間:
2019-11-18 20:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer,win=0,lose=0,draw=0;
string name[3]={"剪刀","石頭","布"};
cout<<"★☆★猜拳遊戲★☆★"<<endl;
re:
cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束 :";
cin>>player;
if(player==0)
{
goto end;
}else if(player>=1&&player<=3)
{
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手!"<<endl;
draw++;
}else if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
{
cout<<"你贏了!"<<endl;
win++;
}else
{
cout<<"電腦贏了!"<<endl;
lose++;
}
cout<<endl;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
end:
cout<<endl<<"★☆★戰果統計★☆★"<<endl;
cout<<"總共贏了"<<win<<"次,輸了"<<lose<<"次,平手"<<draw<<"次!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡少宇
時間:
2019-11-23 10:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer,win=0,lose=0,draw=0;
string name[3]={"剪刀","石頭","布"};
cout<<"★☆★猜拳遊戲★☆★"<<endl;
re:
cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束 :";
cin>>player;
if(player==0)
{
goto end;
}else if(player>=1&&player<=3)
{
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手!"<<endl;
draw++;
}else if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
{
cout<<"你贏了!"<<endl;
win++;
}else
{
cout<<"電腦贏了!"<<endl;
lose++;
}
cout<<endl;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
end:
cout<<endl<<"★☆★戰果統計★☆★"<<endl;
cout<<"總共贏了"<<win<<"次,輸了"<<lose<<"次,平手"<<draw<<"次!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳宇柏
時間:
2019-11-23 10:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"猜拳遊戲"<<endl;
srand(time(NULL));
int player,computer;
int win=0,lose=0,tie=0;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束 :";
if(player==0)
goto end;
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手!!!"<<endl;
tie+=1;
}
if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
{
cout<<"你贏了!!!"<<endl;
win+=1;
}
else
{
cout<<"你輸了!!!"<<endl;
lose+=1;
}
end:
{
cout<<"戰果統計"<<endl;
cout<<"贏了"<<win<<"次"<<"輸了"<<lose<<"次"<<"平手了"<<tie<<"次"<<endl<<
}
system("pause");
return 0;
}
複製代碼
作者:
洪子涵
時間:
2019-12-14 12:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int you,cm,w=0,l=0,ev=0;
string gt[3]={"剪刀","石頭","布"};
srand(time(NULL));
re:
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 (0)離開 妳出: ";
cin>>you;
if(you>3||you<0){
cout<<"輸入錯誤! "<<endl;
goto re;
}else if(you==0)
goto re1;
you--;
cm=rand()%3;
cout<<"你出"<<gt[you]<<endl;
cout<<"電腦出"<<gt[cm]<<endl;
if(you==1&&cm==1||you==2&&cm==2||you==0&&cm==0){
cout<<"平手!\n";
ev++;
}
else if(you==1&&cm==0||you==2&&cm==1||you==0&&cm==2){
cout<<"你贏了!\n";
w++;
}
else{
cout<<"你輸了!\n";
l++;
}
goto re;
re1:
cout<<"---戰果統計---\n總共贏了"<<w<<"次,輸了"<<l<<"次,"<<"平手"<<ev<<"次\n" ;
system("pause");
return 0;
}
複製代碼
作者:
駱顗安
時間:
2020-8-20 19:31
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"*** 猜拳遊戲 v1.0 ***"<<endl<<endl;
string n[]={"剪刀","石頭","布"},
m[]={"平手!","你贏了!","你輸了!"};
int box[3]={0,0,0}; //平手 贏 輸
re:
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束";
cin>>player;
if(player<=3&&player>=1)
{
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
cout<<m[(player+3-computer)%3]<<endl<<endl;
box[(player+3-computer)%3]=box[(player+3-computer)%3]+1;
}
else if(player==0)
{
cout<<endl<<"*** 戰果統計 ***"<<endl;
cout<<"總共贏了"<<box[1]<<"次,輸了"<<
box[2]<<"次,平手"<<box[0]<<"次!"<<endl;
system("pause");
return 0;
}
else
cout<<"輸入錯誤!"<<endl<<endl;
goto re;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2