標題:
猜拳遊戲(二)
[打印本頁]
作者:
周政輝
時間:
2017-9-12 19:03
標題:
猜拳遊戲(二)
請在選擇玩出拳之後 可以顯示出拳的名字
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
// 1 剪刀 2 石頭 3 布
// 使用者可以自行選擇要出哪一個,電腦自動出拳
// 判斷最後結果誰贏
// 隨機 1~3
int player =0;
int computer = 0;
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;
cout << "結果: ";
if(player ==computer)
{
cout << "平手" << endl;
}
else if(player ==1 && computer == 3)
{
cout << "你贏了" << endl;
}
else if(player ==2 && computer == 1)
{
cout << "你贏了" << endl;
}
else if(player ==3 && computer == 2)
{
cout << "你贏了"<<endl;
}
else
{
cout << "你輸了" << endl;
}
system("pause");
return 0;
}
複製代碼
作者:
顏羽彤
時間:
2017-9-12 19:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int player=0,computer=0;
string name[]={"剪刀","石頭","布"};
srand(time(NULL));
cout<<"請輸入:(1)剪刀 (2)石頭 (3)布";
cin>>player;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出拳中..."<<endl;
computer=(rand()%(3))+1;
cout<<"電腦出:"<<name[computer-1]<<endl;
if(player==1&&computer==2)
{
cout<<"你贏了!"<<endl;
}
else if(player==2&&computer==3)
{
cout<<"你贏了!"<<endl;
}
else if(player==3&&computer==1)
{
cout<<"你贏了!"<<endl;
}
else if(player==computer)
{
cout<<"平手!"<<endl;
}
else
{
cout<<"你輸了!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張凱婷
時間:
2017-9-12 19:09
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int player =0;
int computer = 0;
cout << "請出拳 輸入:(1)剪刀(2)石頭(3)布"<< endl;
cin >> player;
string data [] = {"剪刀","石頭","布"};
srand(time(NULL));
computer = (rand()%3)+1;
cout << "你出 :" << data[player-1]<<endl;
cout << "電腦出 :" << data[computer-1]<<endl;
cout << "結果: ";
if(player ==computer)
{
cout << "Tie" << endl;
}
else if(player ==1 && computer == 3)
{
cout << "you win" << endl;
}
else if(player ==2 && computer == 1)
{
cout << "you win" << endl;
}
else if(player ==3 && computer == 2)
{
cout << "you win"<<endl;
}
else
{
cout << "you lose" << endl;
}
system("pause");
return 0;
}
複製代碼
作者:
巫晉宇
時間:
2017-9-12 19:11
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int play=0;
int com=0;
string name []={"剪刀","石頭","布"};
cout<<"請輸入(1)剪刀(2)石頭(3)布"<<endl;
cin>>play;
cout<<"電腦出拳中..."<<endl;
srand(time(NULL));
com=(rand()%(3))+1;
cout<<"玩家出"<<name[play-1]<<endl;
cout<<"電腦出"<<name[com-1]<<endl;
cout<<"結果"<<endl;
if(com==play)
{
cout<<"平手"<<endl;
}
if(com==2&&play==1)
{
cout<<"電腦獲勝"<<endl;
}
if(com==3&&play==2)
{
cout<<"電腦獲勝"<<endl;
}
if(com==1&&play==3)
{
cout<<"電腦獲勝"<<endl;
}
if(com==1&&play==2)
{
cout<<"玩家獲勝"<<endl;
}
if(com==2&&play==3)
{
cout<<"玩家獲勝"<<endl;
}
if(com==3&&play==1)
{
cout<<"玩家獲勝"<<endl;
}
system("pause");
return 0;
}
作者:
張閎鈞
時間:
2017-9-12 19:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int plaper=0;
int computer=0;
string name []={"檢","十", "不"};
cout<<"1=檢 2=十 3=不"<<endl;
cin>>plaper;
cout<<name [plaper-1];
srand(time(NULL));
computer=(rand()%3)+1;
cout<< name [computer-1] <<endl;
if(plaper==1 && computer==3)
{
cout<<"贏了!!!" <<endl;
}
else if(plaper==2&&computer==1)
{
cout<<"贏了!!!" <<endl;
}
else if(plaper==3&&computer==2)
{
cout<<"贏了!!!" <<endl;
}
else if(plaper==computer)
{
cout<<"平熟!!!" <<endl;
}
else
{
cout<<"書了!!!" <<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
巫沛庭
時間:
2017-9-12 19:12
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int player=0;
int computer=0;
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(player==1&&computer==3)
{
cout<<"你贏了~~~"<<endl;
}
else if(player==2&&computer==1)
{
cout<<"你贏了~~~"<<endl;
}
else if(player==3&&computer==2)
{
cout<<"你贏了~~~"<<endl;
}
else if(player==computer)
{
cout<<"平手!!"<<endl;
}
else{
cout<<"你輸了"<<endl;
}
system("pause");
return 0;
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2