標題:
猜拳遊戲 (一)
[打印本頁]
作者:
tonyh
時間:
2020-1-17 19:52
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧,設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布,電腦隨機出拳。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
孫嘉駿
時間:
2020-1-17 20:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int f,t;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>f;
t=rand()%3+1;
cout<<"你出";
if(f==1)
cout<<"剪刀!"<<endl;
else if(f==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(t==1)
cout<<"剪刀!"<<endl;
else if(t==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李宇澤
時間:
2020-1-17 20:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
if(player==2)
cout<<"石頭!"<<endl;
if(player==3)
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
if(computer==2)
cout<<"石頭!"<<endl;
if(computer==3)
cout<<"布!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
余有晉
時間:
2020-1-17 20:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int player,computer;
cout<<"請出拳! (1)屌爆刀(2)硬頭(3)如來神掌 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"屌爆刀!"<<endl;
else if(player==2)
cout<<"硬頭!"<<endl;
else
cout<<"如來神掌!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"屌爆刀!"<<endl;
else if(computer==2)
cout<<"硬頭!"<<endl;
else
cout<<"如來神掌!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃宥華
時間:
2020-1-17 20:05
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand (time(NULL));
int d,f;
cout<<"還不快出 1.剪刀 2.石頭 3.布"<<endl;
cin>>d;
f=rand()%3+1;
cout<<"你出";
if(d==1)
cout<<"剪刀!"<<endl;
else if(d==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(f==1)
cout<<"剪刀!"<<endl;
else if(f==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
董宸佑
時間:
2020-1-17 20:08
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int p,c;
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 -> ";
cin>>p;
c=rand()%3+1;
cout<<"你出";
if(p==1)
cout<<"剪刀!"<<endl;
if(p==2)
cout<<"石頭!"<<endl;
if(p==3)
cout<<"布!"<<endl;
cout<<"電腦出";
if(c==1)
cout<<"剪刀!"<<endl;
if(c==2)
cout<<"石頭!"<<endl;
if(c==3)
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡忻霓
時間:
2020-1-17 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林政瑜
時間:
2020-1-17 20:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃辰昊
時間:
2020-1-17 20:11
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
re:
a:
system("cls");
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布";
cin>>player;
computer=rand()%3+1;
switch(player)
{
case 1:
{
cout<<"你出剪刀!"<<endl;
break;
}
case 2:
{
cout<<"你出石頭!"<<endl;
break;
}
case 3:
{
cout<<"你出布!"<<endl;
break;
}
default:
{
cout<<"你出錯了"<<endl;
goto a;
}
}
cout<<"電腦出";
switch(computer)
{
case 1:
{
cout<<"剪刀!"<<endl;
break;
}
case 2:
{
cout<<"石頭!"<<endl;
break;
}
default:
{
cout<<"布!"<<endl;
}
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳宥穎
時間:
2020-1-17 20:12
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int pl,co;
s:
srand(time(NULL));
cout<<"請出拳! (1)剪刀(2)石頭(3)布\n ";
cin>>pl;
cout<<"你出";
switch(pl)
{
case 1:
cout<<"剪刀\n";
break;
case 2:
cout<<"石頭\n";
break;
case 3:
cout<<"布\n";
break;
}
co=rand()%3+1;
cout<<"電腦出";
switch(co)
{
case 1:
cout<<"剪刀\n";
break;
case 2:
cout<<"石頭\n";
break;
case 3:
cout<<"布\n";
break;
}
goto s;
system("pause>nul");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2