標題:
猜拳遊戲 (一)
[打印本頁]
作者:
方浩葦
時間:
2024-7-19 21:00
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧,設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布,電腦隨機出拳。
#include<iostream>
#include<cstdlib>
#include<ctime>
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;
}
複製代碼
作者:
林少謙
時間:
2024-7-20 15:35
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
re:
srand(time(NULL));
int p,c;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>p;
c=rand()%3+1;
if(p==1)
cout<<"你出剪刀"<<endl;
else if(p==2)
cout<<"你出石頭"<<endl;
else
cout<<"你出布"<<endl;
if(c==1)
cout<<"電腦出剪刀"<<endl;
else if(c==2)
cout<<"電腦出石頭"<<endl;
else
cout<<"電腦出布"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-20 15:51
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int c,p;
re:
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>p;
srand(time(NULL));
for(int i=1; i<=1; i++)
c=rand()%4+1;
if(p==1)
cout<<"剪刀!"<<endl;
else if(p==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(c==1)
cout<<"剪刀!"<<endl;
else if(c==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-20 15:55
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
re:
srand(time(NULL));
int computer,player;
cout<<"請出拳 <1>剪刀 <2>石頭 <3>布"<<endl;
cin>>player;
computer=rand()%3+1;
cout<<"你出 ";
if(player==1)
cout<<"剪刀!"<<endl;
else if (player==2)
cout<<"石頭!"<<endl;
else if (player==3)
cout<<"石頭!"<<endl;
else{
cout<<"輸入錯誤"<<endl;
goto re;
}
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if (computer==2)
cout<<"石頭!"<<endl;
else if (computer==3)
cout<<"石頭!"<<endl;
else{
cout<<"輸入錯誤"<<endl;
goto re;
}
system("pause");
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-20 16:07
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1<<endl;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else(player==3)
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else(computer==3)
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李偈睿
時間:
2024-7-20 16:12
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player,pc;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
pc=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀"<<endl;
else if(player==2)
cout<<"石頭"<<endl;
else
cout<<"布"<<endl;
cout<<"電腦出";
if(pc==1)
cout<<"剪刀"<<endl;
else if(pc==2)
cout<<"石頭"<<endl;
else
cout<<"布"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2