標題:
猜拳遊戲 (一)
[打印本頁]
作者:
鄭繼威
時間:
2023-6-2 21:05
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧,設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布,電腦隨機出拳。
#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;
}
複製代碼
作者:
蔡沛倢
時間:
2023-6-8 16:43
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a,b;
cout<<"請出拳 1剪刀2石頭3布";
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;
}
複製代碼
作者:
呂得銓
時間:
2023-6-9 16:47
#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;
}
複製代碼
作者:
呂宗晉
時間:
2023-6-9 17:24
#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;
}
複製代碼
作者:
黃子豪
時間:
2023-6-9 20:31
#include<iostream>
#include<ctime>
using namespace std;
int main(){
int player, computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
cout<<"你出";
if(player==1){
cout<<"剪刀\n";
}
else if(player==2){
cout<<"石頭\n";
}
else if(player==3){
cout<<"布\n";
}
cout<<"電腦出";
computer=rand()%3+1;
if(computer==1){
cout<<"剪刀\n";
}
else if(computer==2){
cout<<"石頭\n";
}
else if(computer==3){
cout<<"布\n";
}
system("pause");
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-6-9 20:32
#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;
}
複製代碼
作者:
何權晉
時間:
2023-6-9 20:34
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int p,c;
cout<<"ROCK PAPER SCISSORS 1v1 WITH PC!!"<<endl;
cout<<"Rock Paper Scissors! (1)Rock (2)Paper (3)Scissors";
cin>>p;
c=rand()%3+1;
cout<<"You picked: ";
if(p==1)
cout<<"Rock!"<<endl;
else if(p==2)
cout<<"Paper!"<<endl;
else if(p==3)
cout<<"Scissors!"<<endl;
cout<<"The PC picked: "
if(c==1)
cout<<"Rock!"<<endl;
else if(c==2)
cout<<"Paper!"<<endl;
else if(c==3)
cout<<"Scissors!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
廖秝瑜
時間:
2023-6-9 20:35
#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;
}
複製代碼
作者:
鄭繼威
時間:
2023-6-9 20:38
7
作者:
張絜晰
時間:
2023-6-9 20:50
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(time(NULL));
int p,c;
cout<<"請出拳:(1)剪刀(2)石頭(3)布";
cin>>p;
if (p==1){
cout<<"剪刀"<<endl;}
else if (p==2){
cout<<"石頭"<<endl;}
else if (p==2){
cout<<"布"<<endl;}
else{
cout<<"輸入錯誤"<<endl;}
cout<<"電腦出:";
c=rand()%3+1;
if (c==1){
cout<<"剪刀"<<endl;}
else if (c==2){
cout<<"石頭"<<endl;}
else if (c==2){
cout<<"布"<<endl;}
system("pause");
return 0;}
複製代碼
作者:
黃品禎
時間:
2023-7-1 16:25
#include<cstdlib>
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
if(player==1)
{
cout<<"你出剪刀"<<endl;
}
else if(player==2)
{
cout<<"你出石頭"<<endl;
}
else
cout<<"你出布"<<endl;
computer=rand()%3+1;
if(computer==1)
{
cout<<"電腦出剪刀"<<endl;
}
else if(computer==2)
{
cout<<"電腦出石頭"<<endl;
}
else
cout<<"電腦出布"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳柏潁
時間:
2023-7-27 17:32
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int p,c;
srand(time(NULL));
cout<<"請出拳(1)剪刀(2)石頭(3)布:";
cin>>p;
cout<<"玩家出:";
if(p==1)
cout<<"剪刀"<<endl;
if(p==2)
cout<<"石頭"<<endl;
if(p==3)
cout<<"布"<<endl;
c=rand()%3+1;
cout<<"電腦出:";
if(c==1)
cout<<"剪刀"<<endl;
if(c==2)
cout<<"石頭"<<endl;
if(c==3)
cout<<"布"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
邱品惟
時間:
2023-8-8 20:28
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
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;
system("pause");
return 0;
}
複製代碼
作者:
朱奕祈
時間:
2024-2-19 19:48
#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<<"剪刀";
}
else if(p==2)
{
cout<<"石頭";
}
else if(p==3)
{
cout<<"布";
}
else
{
cout<<"輸入錯誤";
}
cout<<"電腦出";
if(c==1)
{
cout<<"剪刀";
}
else if(c==2)
{
cout<<"石頭";
}
else if(c==3)
{
cout<<"布";
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2