- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int main()
- {
- int player=0;
- int com=0;
- cout<<"輸入你要的拳(1:剪刀,2:石頭,3:布)"<<endl;
- cin>>player;
- cout<<"電腦出拳中"<<endl;
- srand(time(NULL));
- com=(rand()%3)+1;
- if(com==1)
- {cout<<"電腦出剪刀"<<endl;
- }
- else if(com==2)
- {cout<<"電腦出石頭"<<endl;
- }
- else if(com==3)
- {cout<<"電腦出布"<<endl;
- }
-
- if(player==1&&com==1)
- {
- cout<<"平手"<<endl;
- }
- else if(player==1&&com==2)
- {
- cout<<"輸"<<endl;
- }
- else if(player==1&&com==3)
- {
- cout<<"贏"<<endl;
- }
-
- else if(player==2&&com==2)
- {
- cout<<"平手"<<endl;
- }
- else if(player==2&&com==1)
- {
- cout<<"贏"<<endl;
- }
- else if(player==2&&com==3)
- {
- cout<<"輸"<<endl;
- }
-
- else if(player==3&&com==3)
- {
- cout<<"平手"<<endl;
- }
- else if(player==3&&com==2)
- {
- cout<<"贏"<<endl;
- }
- else if(player==3&&com==1)
- {
- cout<<"輸"<<endl;
- }
-
-
- system("pause");
- return 0;
- }
複製代碼 |