標題:
猜拳遊戲 (一)
[打印本頁]
作者:
陳品肇
時間:
2018-11-10 16:38
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧, 設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布, 電腦隨機出拳,
比對後判斷輸贏
[attach]5261[/attach]
作者:
蔡依宸
時間:
2018-11-10 17:21
本帖最後由 蔡依宸 於 2018-11-17 15:54 編輯
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int player,computer;
cout<<"請出拳(1)剪刀 (2)石頭 (3)布"<<endl;
cin>>player;
if(player==1)
{
cout<<"你出剪刀"<<endl;
}else if(player==2)
{
cout<<"你出石頭"<<endl;
}else
{
cout<<"你出布"<<endl;
}
srand(time(NULL));
computer=rand()%3+1;
if(computer==1)
{
cout<<"電腦出剪刀"<<endl;
}else if(computer==2)
{
cout<<"電腦出石頭"<<endl;
}else
{
cout<<"電腦出布"<<endl;
}
if(player==computer)
{
cout<<"平手"<<endl;
}if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
{
cout<<"你贏了"<<endl;
}else
{
cout<<"你輸了"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
譚詩澐
時間:
2018-11-10 17:24
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
re:
int player, computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布";
cin>>player;
if(player==1)
{
cout<<"你出剪刀"<<endl;
}else if(player==2)
{
cout<<"你出石頭"<<endl;
}else
{
cout<<"你出布"<<endl;
}
srand (time(NULL));
computer=rand()%3+1;
if(player==computer)
{
cout<<"平手!";
}else if((player==1&&computer==3)||
(player==2&&computer==1)||
(player==3&&computer==2))
{
cout<<"我贏了!"<<endl;
}else
{
cout<<"我輸了!!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳柏霖
時間:
2018-11-10 17:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player ,computer;
cout<<"請出拳 (1)剪刀 (2)石頭 (3)布";
cin>>player;
bb:
if(player==1)
{
cout<<"你出剪刀!"<<endl;
}else if(player==2)
{
cout<<"你出石頭!"<<endl;
}else if(player==3)
{
cout<<"你出布!"<<endl;
}else
{
cout<<"輸入錯誤!"<<endl;
goto bb;
}
srand(time(NULL));
computer=rand()%3+1;
if(computer==1)
{
cout<<"電腦出剪刀!"<<endl;
}else if(computer==2)
{
cout<<"電腦出石頭!"<<endl;
}else
{
cout<<"電腦出布!"<<endl;
}
if(player==computer)
{
cout<<"平手!"<<endl;
}else if((player==1 && computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"你贏了!"<<endl;
}else
{
cout<<"你輸了!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴唯陞
時間:
2018-11-10 17:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player,computer;
cout<<"請出拳(1)剪刀(2)石頭(3)布";
cin>>player;
if (player==1)
{cout<<"你出剪刀"<<endl;}
else if (player==2)
{cout<<"你出石頭"<<endl;}
else {cout<<"你出布"<<endl;}
srand(time(NULL));
computer=rand()%3+1;
cout<<computer<<endl;
if (player==computer)
{cout<<"平手"<<endl;}
else if((player==3 && computer==1)||
(player==2 && computer==3)||
(player==1 && computer==2))
{cout<<"你贏了"<<endl;}
else {cout<<"你輸了"<<endl;}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴偉宸
時間:
2018-11-10 17:36
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int p,computer;
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布"<<endl;
cin>>p;
if(p==1)
{
cout<<"你出剪刀"<<endl;
}
else if(p==2)
{
cout<<"你出石頭"<<endl;
}
else if(p==3)
{
cout<<"你出布"<<endl;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
srand(time(NULL));
computer=rand()%3+1 ;
cout<<computer<<endl;
if(computer==1)
{
cout<<"電腦出剪刀"<<endl;
}
else if(computer==2)
{
cout<<"電腦出石頭"<<endl;
}
else if(computer==3)
{
cout<<"電腦出布"<<endl;
}else{}
if(p==computer)
{
cout<<"平手"<<endl;
}
else if((p==1 && computer==3)||
(p==2 && computer==1)||
(p==3 && computer==2))
{
cout<<"你贏了~~"<<endl;
}
else if((p==1 && computer==2)||
(p==2 && computer==3)||
(p==3 && computer==1))
{
cout<<"你輸囉!"<<endl;
}
else{}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴安利
時間:
2018-11-10 17:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int player, computer;
re:
cout<<"請出拳!! (1)剪刀 (2)石頭 (3)布 "<<endl;
cin>>player;
if(player==1)
{
cout<<"你出剪刀!!"<<endl;
}
else if(player==2)
{
cout<<"你出石頭!!"<<endl;
}
else
{
cout<<"你出布!!"<<endl;
}
srand(time(NULL));
computer=rand()%3+1;
if (computer==1)
{
cout<<"電腦出剪刀!!"<<endl;
}
else if(computer==2)
{
cout<<"電腦出石頭!!"<<endl;
}
else
{
cout<<"電腦出布!!"<<endl;
}
if (player==computer)
{
cout<<"平手!!"<<endl;
}
else if((player==1&& computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"我贏ㄌ!!!!!"<<endl;
}
else
{
cout<<"我輸ㄌ!!!!!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蔡季庭
時間:
2018-11-17 16:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int player, computer;
re:
cout<<"請出拳!! (1)剪刀 (2)石頭 (3)布 "<<endl;
cin>>player;
if(player==1)
{
cout<<"你出剪刀!!"<<endl;
}
else if(player==2)
{
cout<<"你出石頭!!"<<endl;
}
else
{
cout<<"你出布!!"<<endl;
}
srand(time(NULL));
computer=rand()%3+1;
if (computer==1)
{
cout<<"電腦出剪刀!!"<<endl;
}
else if(computer==2)
{
cout<<"電腦出石頭!!"<<endl;
}
else
{
cout<<"電腦出布!!"<<endl;
}
if (player==computer)
{
cout<<"平手!!"<<endl;
}
else if((player==1&& computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"我贏ㄌ!!!!!"<<endl;
}
else
{
cout<<"我輸ㄌ!!!!!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2