標題:
猜拳遊戲(五)
[打印本頁]
作者:
周政輝
時間:
2018-4-21 15:23
標題:
猜拳遊戲(五)
解決平手時的BUG
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
//請將遊戲改為三戰兩勝 並將贏的次數最多者輸出
// 第一局 我:1 電腦:0
// 第二局 我:1 電腦:1
// 第三局 我:2 電腦:1
// 結果: 玩家贏
srand(time(NULL));
int player =0;
int com =0;
int mypoint = 0;
int compoint = 0;
int game = 1;
string mora[] = {"剪刀","石頭","布"};
for(int i=game;i<=3;i++) {
cout << "第" << i << "局" << "玩家: "<< mypoint << "電腦: " << compoint << endl;
cout << "=========================" << endl;
cout << endl;
cout << "請選擇想要出的拳 (1:剪刀 2:石頭 3:布)"<< endl;
cin >> player;
cout << "電腦出拳中..." << endl;
com = (rand()%3)+1;
cout << "你出:" << mora[player-1] << endl;
cout << "電腦出:" << mora[com-1] << endl;
if(player == 1 && com==3)
{
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 2 && com==1)
{
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 3 && com==2)
{
cout << "你贏了" << endl;
mypoint++;
}
else if(player == com)
{
cout << "平手" << endl;
}
else
{
cout << "你輸了" << endl;
compoint++;
}
if(mypoint == 2 || compoint == 2) {
break;
}
cout << "=========================" << endl;
cout << endl;
}
cout << "最後結果: " << "玩家: "<< mypoint << "電腦: " << compoint << endl;
if(mypoint > compoint) {
cout << "玩家贏" << endl;
}
else if(mypoint == compoint ) {
cout << "平手" << endl;
}
else {
cout << "電腦贏" << endl;
}
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-4-21 15:25
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
string card[3]={"剪刀","石頭","布"};
string win[3]={"你贏","電腦贏","平手"};
int player=0;
int com=0;
int game=1;
int mypoint=0;
int compoint=0;
for(int i=game;i<=3;i++)
{
cout<<"第"<<i<<"局"<<"\t玩家: "<<mypoint<<"電腦: "<<compoint<<endl;
cout<<"輸入你要的拳(1.剪刀2.石頭3.布)"<<endl;
cin>>player;
cout<<"電腦出拳中..."<<endl;
srand(time(NULL));
com=(rand()%3)+1;
cout << "你出:"<<card[player-1]<<endl;
cout << "電腦出:"<<card[com-1
]<<endl;
if(player==1&&com==3)
{
cout<<win[0]<<endl;
mypoint++;
}
if(player==1&&com==2)
{
cout<<win[1]<<endl;
compoint++;
}
if(player==2&&com==1)
{
cout<<win[0]<<endl;
mypoint++;
}
if(player==2&&com==3)
{
cout<<win[1]<<endl;
compoint++;
}
if(player==3&&com==2)
{
cout<<win[0]<<endl;
mypoint++;
}
if(player==2&&com==3)
{
cout<<win[1]<<endl;
compoint++;
}
else
{
cout<<win[2]<<endl;
}
if(compoint==2||mypoint==2)
break;
}
cout<<"\t玩家: "<<mypoint<<"電腦: "<<compoint<<endl;
if(mypoint>compoint)
{
cout<<win[0]<<endl;
}
else if(compoint==mypoint)
{
cout<<win[2]<<endl;
}
else
{
cout<<win[1]<<endl;
}
system("PAUSE");
return 0;
}
複製代碼
作者:
戴嘉禾
時間:
2018-4-21 15:25
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
re:
system("cls");
srand(time(NULL));
int com=0;
int player=0;
int mypoint=0;
int compoint=0;
int game=1;
cout<< "==========☆★☆猜拳遊戲☆★☆==========" <<endl;
cout<<endl;
for(int i=game;i<=3;i++)
{
string mora[]={"剪刀","石頭","布"};
cout<< " 玩家:"<<mypoint<<" 第"<<i<<"局 "<<" 電腦:"<<compoint<<endl;
cout<< "========================================" <<endl;
cout<< "請輸入你想要出的拳 (1)剪刀(2)石頭(3)布" <<endl;
cin>>player;
cout<< "電腦出拳中..." <<endl;
com=(rand()%3)+1;
cout<<"你出"<<mora[player-1]<<endl;
cout<< "電腦出" << mora[com-1] <<endl;
if(player==1&&com==3)
{
cout<<"你贏了"<<endl;
mypoint++;
}
else if(player==2&&com==1)
{
cout<<"你贏了"<<endl;
mypoint++;
}
else if(player==3&&com==2)
{
cout<<"你贏了"<<endl;
mypoint++;
}
else if(player==com)
cout<<"平手"<<endl;
else
{
cout<<"你輸了"<<endl;
compoint++;
}
if( mypoint == 2 || compoint == 2)
break;
cout<<endl;
}
cout<< "========================================" <<endl;
cout<<endl;
cout<<"玩家:"<<mypoint<<endl;
cout<<"電腦:"<<compoint<<endl;
cout<<endl;
if( mypoint> compoint )
cout<<"玩家贏了"<<endl;
else if( compoint> mypoint )
cout<<"電腦贏了"<<endl;
else
cout<<"平手"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-4-21 15:26
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int player=0;
int com=0;
int my=0;
int comp=0;
int game=1;
string mora[]={"剪刀","石頭","布"};
for(int i=game;i<=3;i++)
{
cout<<"第"<<i<<"局"<<" 玩家: "<<my<<"電腦: "<< comp<<endl;
cout<<"========================"<<endl;
cout<<"輸入你要的拳(1:剪刀,2:石頭,3:布)"<<endl;
cin>>player;
cout<<"電腦出拳中"<<endl;
com=(rand()%3)+1;
cout << "你出:" << mora[player-1] << endl;
cout << "電腦出:" << mora[com-1] << endl;
if(player==com)
{
cout<<"平手"<<endl;
}
else if(player==1&&com==3)
{
cout<<"贏"<<endl;
my++;
}
else if(player==2&&com==1)
{
cout<<"贏"<<endl;
my++;
}
else if(player==3&&com==2)
{
cout<<"贏"<<endl;
my++;
}
else
{
cout<<"輸"<<endl;
comp++;
}
if(my==2||comp==2)
{break;
}
cout<<"========================"<<endl;
cout<<endl;
}
cout<<"玩家: "<<my<<"電腦: "<< comp<<endl;
if(my>comp)
{
cout<<"你贏"<<endl;
}
else if(my==comp)
{
cout<<"平手"<<endl;
}
else
{cout<<"電腦贏了"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
顏詢
時間:
2018-4-21 15:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player =0;
int com =0;
int mypoint=0;
int compoint=0;
int game=1;
string mora[] = {"剪刀","石頭","布"};
for(int i=game;i<=3;i++)
{
cout<<"第"<<i<<"局"<<"玩家"<< mypoint<<"電腦"<<compoint<<endl;
cout << "請選擇想要出的拳 (1:剪刀 2:石頭 3:布)"<< endl;
cin >> player;
cout << "電腦出拳中..." << endl;
com = (rand()%3)+1;
cout << "你出:" << mora[player-1] << endl;
cout << "電腦出:" << mora[com-1] << endl;
if(player == 1 && com==3) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 2 && com==1) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 3 && com==2) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == com) {
cout << "平手" << endl;
}
else {
cout << "你輸了" << endl;
compoint++;
}
if(mypoint==2||compoint==2){
break;
}
}
cout<<"最後結果:"<<"玩家:"<<mypoint<<"電腦:"<<compoint<<endl;
if(mypoint>compoint){
cout<<"玩家贏"<<endl;
else if(mypoint=compoint)
cout<<"平手"<<endl;
}
else{
cout<<"電腦贏"<<endl;
}
複製代碼
作者:
黃安立
時間:
2018-4-21 15:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player =0;
int com =0;
int mypoint=0;
int compoint=0;
int game=1;
string mora[] = {"剪刀","石頭","布"};
for(int i=game;i<=3;i++)
{
cout<<"第"<<i<<"局"<<"玩家"<< mypoint<<"電腦"<<compoint<<endl;
cout << "請選擇想要出的拳 (1:剪刀 2:石頭 3:布)"<< endl;
cin >> player;
cout << "電腦出拳中..." << endl;
com = (rand()%3)+1;
cout << "你出:" << mora[player-1] << endl;
cout << "電腦出:" << mora[com-1] << endl;
if(player == 1 && com==3) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 2 && com==1) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == 3 && com==2) {
cout << "你贏了" << endl;
mypoint++;
}
else if(player == com) {
cout << "平手" << endl;
}
else {
cout << "你輸了" << endl;
compoint++;
}
if(mypoint==2||compoint==2){
break;
}
}
cout<<"最後結果:"<<"玩家:"<<mypoint<<"電腦:"<<compoint<<endl;
if(mypoint>compoint){
cout<<"玩家贏"<<endl;
else if(mypoint=compoint)
cout<<"平手"<<endl;
}
else{
cout<<"電腦贏"<<endl;
}
複製代碼
作者:
湯東緯
時間:
2018-4-21 15:31
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int player=0;
int com=0;
int mypoint=0;
int compoint=0;
int game=1;
for(int i=game;i<4;i++)
{
string mora[] = {"剪刀","石頭","布"};
cout<<"玩家:"<<mypoint<<" 第"<<i<<"局"<<" 電腦:"<<compoint<<endl;
cout<<"======================================================="<<endl;
cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
cout<<"電腦出拳中..."<<endl;
com=(rand()%3)+1;
cout <<"你出:"<< mora[player-1] << endl;
cout <<"電腦出:"<< mora[com-1] << endl;
if(player == 1&&com==3)
{
cout << "你贏了" << endl;
mypoint++;
}
else if(player ==2&&com==1)
{
cout <<"你贏了"<< endl;
mypoint++;
}
else if(player == 3&&com==2)
{
cout <<"你贏了"<< endl;
mypoint++;
}
else if(player == com)
{
cout <<"平手"<< endl;
}
else
{
cout <<"你輸了"<< endl;
compoint++;
}
if(mypoint == 2 ||compoint == 2)
{
break;
}
cout<<"======================================================="<<endl;
cout<<endl;
}
cout<<"玩家:"<<mypoint<<" 電腦:"<<compoint<<endl;
if(mypoint>compoint)
{
cout<<"你贏了"<<endl;
}
else if(player == com)
{
cout <<"平手"<< endl;
}
else
{
cout<<"你輸了"<<endl;
}
system("pause");
return 0;
}
作者:
湯東緯
時間:
2018-4-21 15:31
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int player=0;
int com=0;
int mypoint=0;
int compoint=0;
int game=1;
for(int i=game;i<4;i++)
{
string mora[] = {"剪刀","石頭","布"};
cout<<"玩家:"<<mypoint<<" 第"<<i<<"局"<<" 電腦:"<<compoint<<endl;
cout<<"======================================================="<<endl;
cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
cout<<"電腦出拳中..."<<endl;
com=(rand()%3)+1;
cout <<"你出:"<< mora[player-1] << endl;
cout <<"電腦出:"<< mora[com-1] << endl;
if(player == 1&&com==3)
{
cout << "你贏了" << endl;
mypoint++;
}
else if(player ==2&&com==1)
{
cout <<"你贏了"<< endl;
mypoint++;
}
else if(player == 3&&com==2)
{
cout <<"你贏了"<< endl;
mypoint++;
}
else if(player == com)
{
cout <<"平手"<< endl;
}
else
{
cout <<"你輸了"<< endl;
compoint++;
}
if(mypoint == 2 ||compoint == 2)
{
break;
}
cout<<"======================================================="<<endl;
cout<<endl;
}
cout<<"玩家:"<<mypoint<<" 電腦:"<<compoint<<endl;
if(mypoint>compoint)
{
cout<<"你贏了"<<endl;
}
else if(player == com)
{
cout <<"平手"<< endl;
}
else
{
cout<<"你輸了"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
吳秉翰
時間:
2018-4-27 20:11
本帖最後由 吳秉翰 於 2018-4-27 20:38 編輯
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int player=0;
int com=0;
int my=0;
int it=0;
int game=1;
string mora[] = {"剪刀","石頭","布"};
for(int i=game;i<=3;i++)
{
cout << "第" << i << "局";
cout<<"請出拳"<<endl;
cin>>player;
com = (rand()%3)+1;
cout << "你出:" << mora[player-1] << endl;
cout << "電腦出:" << mora[com-1] << endl;
if(player==1 && com==3)
{
cout << "贏" << endl;
my++;
}
else if(player==2 && com==1)
{
cout << "此局贏" << endl;
my++;
}
else if(player==3 && com==2)
{
cout << "此局贏" << endl;
my++;
}
else if(player==com)
{
cout << "此局平手" << endl;
}
else
{
cout << "此局輸" << endl;
it++;
}
if(my==2 || it==2)
break;
}
if(my>it)
{
cout<<"此場贏";
}
else if(it>my)
{
cout<<"此場輸";
}
else
{
cout<<"此場平手";
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2