標題:
猜拳遊戲 (一)
[打印本頁]
作者:
tonyh
時間:
2014-3-8 17:18
標題:
猜拳遊戲 (一)
本帖最後由 tonyh 於 2014-3-8 17:42 編輯
運用產生隨機亂數的技巧, 設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布, 電腦隨機出拳,
比對後判斷輸贏
[attach]853[/attach]
作者:
施伯叡
時間:
2014-3-8 17:49
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player, computer;
string name[]={"剪刀","石頭","布"};
cout<<"請出拳:(1)剪刀 (2)石頭 (3)布 ";
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(computer==player)
{
cout<<"平手!"<<endl;
}
else if((player==1 && computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"你贏了"<<endl;
}
else
{
cout<<"電腦贏了"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
周雍程
時間:
2014-3-8 17:52
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player, computer;
string name[3]={"剪刀","石頭","布"};
cout<<"<1> 剪刀 <2> 石頭 <3> 布";
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出:"<<name[player-1]<<endl;
cout<<"電腦出:"<<name[computer-1]<<endl;
if(player == computer)
{
cout<<"平手!"<<endl;
}
else if((player==1 && computer==3)||(player==1 && computer==3)||(player==1 && computer==3))
{
cout<<"你贏了!"<<endl;
}
else
{
cout<<"電腦贏了!"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
張彥承
時間:
2014-3-8 17:55
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player,computer;
string name[3]={"剪刀 ","石頭 ","布 "};
cout<<"請猜拳 <1>剪刀 <2>石頭 <3>布 "<<endl;
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出:"<<name[player-1]<<endl;
cout<<"電腦出:"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手"<<endl;
}else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
{
cout<<"你贏了!"<<endl;
}else
{
cout<<"你輸了!"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
張郁偵
時間:
2014-3-8 17:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳!(1)剪刀(2)石頭(3)布 "<<endl;
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手"<<endl;
}else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
{
cout<<"你贏了"<<endl;
}else
{
cout<<"電腦贏了"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
張峻瑋
時間:
2014-3-8 18:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳!(1)剪刀(2)石頭(3)布";
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
if(player==computer)
{
cout<<"平手!"<<endl;
}
else if((player==1 && computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"你贏了!"<<endl;
}
else
{
cout<<"電腦贏了!"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
劉得旗
時間:
2014-3-8 18:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player, computer;
string name[]={"剪刀","石頭","布"};
cout<<"請出拳:(1)剪刀 (2)石頭 (3)布 "<<endl;
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出:"<<name[player-1]<<endl;
cout<<"電腦出:"<<name[computer-1]<<endl;
if(computer==player)
{
cout<<"平手!"<<endl;
}
else if((player==1 && computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"你是贏家"<<endl;
}
else
{
cout<<"你是輸家"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
張郁庭
時間:
2014-3-8 18:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1) 剪刀 (2) 石頭 (3) 布 "<<endl;
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
cout<<"你出"[player-1]<<endl;
cout<<"電腦出"[computer-1]<<endl;
if(player==computer)
{
cout<<"平手!"<<endl;
}else if((player==1 && computer==3)||
(player==2 && computer==1)||
(player==3 && computer==2))
{
cout<<"你贏了!"<<endl;
}else
{
cout<<"電腦贏了!"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2