| 
鐵幣692 元文章1215 篇聲望1348 枚上次登入17-8-25精華3註冊時間07-3-1UID362229
 
 | 
        
        
| 原文由 風痕戀 於 08-11-29 13:02 發表  do while 可以用來控制遊戲要不要繼續執行..
 
 我有稍微做了一下..
 
 大概就像是這樣
 
 
 
 剪刀,石頭,布
include <iostream>
 #include <cstdlib>
 #include <time.h>
 using namespace std;
 int main(void)
 {
 int com[3],j,d,g,a,s;//a是輸電腦,s是贏電腦
 com[0] = 0;
 com[1] = 1;
 com[2] = 2;
 a = 0;
 s = 0;
 srand(time(0));
 for(j=0;j<3;j++)
 {
 do
 {
 d=rand()%3;
 cout<<"規則====>剪刀:0 石頭:1 布:2 跳出:4"<<endl;
 cout<<"*****請出拳:*****"<<endl;
 cin>>g;
 if (g==0 && com[d]==0)
 {
 cout<<"剪刀 V.S 剪刀"<<endl;
 cout<<"平手!!!\n"<<endl;
 }
 else if (g==1 && com[d]==1)
 {
 cout<<"石頭 V.S 石頭"<<endl;
 cout<<"平手!!!\n"<<endl;
 }
 else if (g==2 && com[d]==2)
 {
 cout<<"布 V.S 布"<<endl;
 cout<<"平手!!!\n"<<endl;
 }
 else if (g==0 && com[d]==1)
 {
 cout<<"剪刀 V.S 石頭"<<endl;
 cout<<"你輸了!!!\n"<<endl;
 a++;
 }
 else if (g==0 && com[d]==2)
 {
 cout<<"剪刀 V.S 布"<<endl;
 cout<<"你贏了!!!\n"<<endl;
 s++;
 }
 else if (g==1 && com[d]==0)
 {
 cout<<"石頭 V.S 剪刀"<<endl;
 cout<<"你贏了!!!\n"<<endl;
 s++;
 }
 else if (g==1 && com[d]==2)
 {
 cout<<"石頭 V.S 布"<<endl;
 cout<<"你輸了!!!\n"<<endl;
 a++;
 }
 else if (g==2 && com[d]==0)
 {
 cout<<"布 V.S 剪刀"<<endl;
 cout<<"你輸了!!!\n"<<endl;
 a++;
 }
 else if (g==2 && com[d]==1)
 {
 cout<<"布 V.S 石頭"<<endl;
 cout<<"你贏了!!!\n"<<endl;
 s++;
 }
 else if (g==4)
 {
 cout<<"遊戲結束~\n中途而廢是不好的事喔~"<<endl;
 system("pause");
 return 0;
 }
 else
 {
 cout<<"你亂出......請遵守遊戲規則!!!\n"<<endl;
 return main();
 }
 }
 while(j>3);}
 if(a==3)
 {
 cout<<"你連輸三場,會不會太悲慘了!?"<<endl;
 }
 else if(a==2 && s==1)
 {
 cout<<"你輸了兩場(贏了一場),請再接再厲!!"<<endl;
 }
 else if(a==1 && s==2)
 {
 cout<<"你輸了一場(贏了二場),真厲害~~"<<endl;
 }
 else if(s==3)
 {
 cout<<"你連贏三場,你的運氣真好。"<<endl;
 }
 else
 {
 return main();
 }
 system("pause");
 return 0;
 }
 
 
 目前我的能力只能幫你幫到這裡,
 
 後面還是會有平手辦別的問題,也就是平手之後會重計成績。
 
 P.S:猜拳程式碼參考yahoo知識+,成績判別方法個人製作。
 
 
 [ 本文章最後由 西札爾 於 08-12-1 23:52 編輯 ]
 | 
 |