標題:
猜拳遊戲 (一)
[打印本頁]
作者:
王瑞喻
時間:
2019-11-7 16:44
標題:
猜拳遊戲 (一)
本帖最後由 王瑞喻 於 2019-12-28 15:31 編輯
運用產生隨機亂數的技巧, 設計一個猜拳遊戲,
使用者可以選擇出剪刀、石頭或布, 電腦隨機出拳.
本帖隱藏的內容需要回復才可以瀏覽
作者:
洪藜芸
時間:
2019-11-9 11:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int c,p;
cout<<"請出拳! (1)剪刀(2)石頭(3)布"<<endl;
cin>>p;
if(p==1)
cout<<"你出剪刀!"<<endl;
else if(p==2)
cout<<"你出石頭!"<<endl;
else
cout<<"你出布!"<<endl;
c=rand()%3+1;
if(c==1)
cout<<"電腦出剪刀!"<<endl;
else if(c==2)
cout<<"電腦出石頭!"<<endl;
else
cout<<"電腦出布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾宥程
時間:
2019-11-9 11:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int P1,com;
srand(time(NULL));
cout<<"請出拳!!! <1>剪刀<2>石頭<3>布 :";
cin>>P1;
cout<<"你出";
if(P1==1)
{
cout<<"剪刀"<<endl;
}else if(P1==2)
{
cout<<"石頭"<<endl;
}else if(P1==3)
{
cout<<"布"<<endl;
}else
{
cout<<"輸入錯誤!!!";
}
com=rand()%3+1;
cout<<"電腦出";
if(com==1)
{
cout<<"剪刀"<<endl;
}else if(com==2)
{
cout<<"石頭"<<endl;
}else if(com==3)
{
cout<<"布"<<endl;
}else
{
cout<<"輸入錯誤!!!";
}
system ("pause");
return 0;
}
複製代碼
作者:
郭哲維
時間:
2019-11-9 11:05
#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;
if (computer==1)
cout<<"剪刀 !"<<endl;
else if(computer==2)
cout<<"石頭 !"<<endl;
else
cout<<"布 !"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王翎璇
時間:
2019-11-9 11:05
#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;
}
複製代碼
作者:
黃傳耀
時間:
2019-11-9 11:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int computer,player;
srand(time(NULL));
cout<<"出拳(1)剪子(2)石子(3)布";
cin>>player;
computer = rand()%3+1;
if(player ==1)
cout<<"你出剪子";
if(player ==2)
cout<<"你出石子";
if(player ==3)
cout<<"你出布";
cout<<endl;
if(computer ==1)
cout<<"電腦出剪子";
if(computer ==2)
cout<<"電腦出石子";
if(computer ==3)
cout<<"電腦出布";
system("pause");
return 0;
}
複製代碼
作者:
鄭羽捷
時間:
2019-11-9 11:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,comuter;
cout<<"請出拳!(1)剪刀(2)石頭(3)布";
cin>>player;
comuter=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布"<<endl;
cout<<"電腦出";
if(comuter==1)
cout<<"剪刀!"<<endl;
else if(comuter==2)
cout<<"石頭!"<<endl;
else
cout<<"布"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林孟蓁
時間:
2019-11-11 20:09
本帖最後由 林孟蓁 於 2019-11-11 20:24 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int computer,player;
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布";
cin>>player;
cout<<"你出";
computer=rand()%3+1;
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;
}
複製代碼
作者:
陳宇柏
時間:
2019-11-12 17:33
本帖最後由 陳宇柏 於 2019-11-12 17:34 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int computer,player;
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;
}
system ("pause");
return 0;
}
複製代碼
作者:
蔡少宇
時間:
2019-11-12 19:52
本帖最後由 蔡少宇 於 2019-11-12 19:54 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"<1>剪刀 <2>石頭 <3>布";
cout<<"請出拳:"
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
{
cout<<"剪刀喔!!"<<endl;
}else if(player==2)
{
cout<<"石頭喔!!"<<endl;
}else if(player==3)
{
cout<<"布喔!!"<<endl;
}
cout<<"電腦出";
if(computer==1)
{
cout<<"剪刀喔!!"<<endl;
}else if(computer==2)
{
cout<<"石頭喔!!"<<endl;
}else if(computer==3)
{
cout<<"布喔!!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
王建葦
時間:
2019-11-16 09:40
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
srand(time(NULL));
int computer,player;
cout<<"請出拳 <1>剪刀 <2>石頭 <3>布 :";
cin>>player;
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
{
cout<<"布"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2019-11-16 09:43
#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;
}
複製代碼
作者:
洪子涵
時間:
2019-12-14 11:47
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int you,cm;
string gt[3]={"剪刀","石頭","布"};
srand(time(NULL));
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 妳出: ";
cin>>you;
you--;
cm=rand()%3;
cout<<"你出"<<gt[you]<<endl;
cout<<"電腦出"<<gt[cm]<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2