標題:
猜拳遊戲 (一)
[打印本頁]
作者:
tonyh
時間:
2017-4-15 13:58
標題:
猜拳遊戲 (一)
本帖最後由 tonyh 於 2020-1-3 14:39 編輯
運用產生隨機亂數的技巧,設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布,電腦隨機出拳。
#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;
}
複製代碼
作者:
黃宥鈞
時間:
2017-4-15 14:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int x,y;
srand(time(NULL));
cout<<"請出拳! (1)剪刀(2)石頭(3)布";
cin>>x;
cout<<"你出";
if(x==1)
cout<<"剪刀";
if(x==2)
cout<<"石頭";
if(x==3)
cout<<"布";
cout<<endl;
y=rand()%3;
if(y==0)
cout<<"電腦出剪刀";
if(y==1)
cout<<"電腦出石頭";
if(y==2)
cout<<"電腦出布";
cout<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
許紘誌
時間:
2017-4-15 14:17
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int a,b;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 "<<endl;
cin>>a;
b=rand()%3+1;
cout<<"你出";
if(a==1)
cout<<"剪刀!"<<endl;
if(a==2)
cout<<"石頭!"<<endl;
if(a==3)
cout<<"布!"<<endl;
cout<<"電腦出";
if(b==1)
cout<<"剪刀!"<<endl;
if(b==2)
cout<<"石頭!"<<endl;
if(b==3)
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2017-4-15 14:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int x,y;
srand(time(NULL));
cout<<"請出拳! (1)剪刀(2)石頭(3)布";
cin>>x;
cout<<"你出";
if(x==1)
cout<<"剪刀";
if(x==2)
cout<<"石頭";
if(x==3)
cout<<"布";
cout<<endl;
y=rand()%3;
if(y==0)
cout<<"電腦出剪刀";
if(y==1)
cout<<"電腦出石頭";
if(y==2)
cout<<"電腦出布";
cout<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2017-4-15 14:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y;
srand(time(NULL));
cout<<"出拳吧~(1)剪刀(2)石頭(3)布";
cin>>x;
cout<<"你出";
if(x==1)
cout<<"剪刀";
if(x==2)
cout<<"石頭";
if(x==3)
cout<<"布";
cout<<endl;
y=rand()%3;
if(x==0)
cout<<"電腦出剪刀";
if(x==1)
cout<<"電腦出石頭";
if(x==2)
cout<<"電腦出布";
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2017-4-15 14:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y;
srand(time(NULL));
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 ";
cin>>x;
y=rand()%3+1;
cout<<"你出";
if(y==1)
cout<<"剪刀!"<<endl;
if(y==2)
cout<<"石頭!"<<endl;
if(y==3)
cout<<"布!"<<endl;
cout<<"電腦出";
if(x==0)
cout<<"剪刀!"<<endl;
if(x==1)
cout<<"石頭!"<<endl;
if(x==2)
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2017-4-15 14:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y;
srand(time(NULL));
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 ";
cin>>x;
y=rand()%3+1;
cout<<"你出"<<n[x-1]<<endl;
cout<<"電腦出"<<n[y-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2017-4-21 18:06
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2