標題:
猜拳遊戲 (一)
[打印本頁]
作者:
tonyh
時間:
2021-1-16 19:56
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧,設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布,電腦隨機出拳。
#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;
}
複製代碼
作者:
俞成章
時間:
2021-1-16 20: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;
}
複製代碼
作者:
林鼎傑
時間:
2021-1-16 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
re:
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;
cout<<"韓國瑜使用了善逸的謊言!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
余柏緯
時間:
2021-1-16 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
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 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;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
王宇崴
時間:
2021-1-16 20:09
#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;
}
複製代碼
作者:
李柏穎
時間:
2021-1-16 20:10
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a, b;
cout<<"請出拳(1)剪刀(2)石頭(3)布: ";
cin>>a;
b=rand()%3+1;
if(a==1)
cout<<"你出剪刀!"<<endl;
else if(a==2)
cout<<"你出石頭!"<<endl;
else if(a==3)
cout<<"你出布!"<<endl;
if(b==1)
cout<<"電腦出剪刀!"<<endl;
else if(b==2)
cout<<"電腦出石頭!"<<endl;
else if(b==3)
cout<<"電腦出布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
朱奕祐
時間:
2021-1-16 20:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
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 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;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
呂尚霖
時間:
2021-1-16 20:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
re:
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;
}
複製代碼
作者:
許洧熏
時間:
2021-1-16 20:15
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
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;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃子倢
時間:
2021-1-16 20:15
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
srand(time(NULL));
re:
cout<<"請出拳: (1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
cout<<rand()%3+1;
cin>>computer;
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;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
王秉鈞
時間:
2021-1-16 20:28
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int play,computer;
re:
cout<<"請出人! (1)陳其邁(2)蔡英文(3)陳時中";
cin>> play;
computer=rand()%3+1;
if(play==1)
cout<<"陳其邁"<<endl;
else if(play==2)
cout<<"蔡英文"<<endl;
else if(play==3)
cout<<"陳時中"<<endl;
cout<<"國民黨出";
if(computer==1)
cout<<"韓國瑜"<<endl;
else if(computer==2)
cout<<"馬英9"<<endl;
else
cout<<"老師"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2