#include#include #include #include #include using namespace std; //布=0,剪刀=1,石头=2; enum Chioce { paper, sisser, rock }; //判断胜负函数(mod3同余判断胜负) //结算各自得分 void decide_winner(int x, int y)//x是你的出拳状态,y是电脑的 { if (x == y) { cout << "平局!" << endl; } else if ((x - y == 1) || (x - y == -2)) { cout << "你赢了!" << endl; } else { cout << "你输了!" << endl; } } //玩家 类 class Player { public: int PlayerChoice; int score; public: Player() { PlayerChoice= paper;//构造函数初始化数据随便定义一个 score = 0; } }; //定义一个电脑 基类 :包含电脑出拳选择状态,当前得分 class ComputerBase { public: int ComputerChioce; int score; public: ComputerBase() { ComputerChioce = paper; score = 0; } }; //随机出拳电脑,继承了电脑基类 class ComputerRandom :public ComputerBase { public: //随机出拳函数,基于当下时间的随机出拳 static int getChioce() { int a; a = time(NULL) % 3; switch (a) { case 0: cout << "电脑出的布" << endl; break; case 1: cout << "电脑出的剪刀" << endl; break; case 2: cout << "电脑出的石头" << endl; break; } return (a); } }; int main() { int mode; cout << "欢迎来到猜拳游戏" << endl; cout << "请选择对手模式:" << endl; cout << "1.随机出拳" << endl; cout << "2.暂未开放" << endl; cout << "3.暂未开放,直接进入模式1" << endl; Player player1; cout << "你出:(布=0,剪刀=1,石头=2)" << endl; cin >> player1.PlayerChoice; ComputerRandom computer1; computer1.ComputerChioce = ComputerRandom::getChioce(); decide_winner(player1.PlayerChoice, computer1.ComputerChioce); ComputerRandom Computer1; system("pause"); return 0; }



