#include<bits/stdc++.h>
using namespace std;
class Coin
{
private:
string sideUp;
public:
Coin() {
srand(time(0));
flip();
}
void flip() {
sideUp = (rand() % 2 == 0) ? "正面" : "反面";
}
string getSideUp() const {
return sideUp;
}
};
class CoinFlipGame {
private:
int playerScore;
int computerScore;
int totalRounds;
Coin coin;
public:
CoinFlipGame() : playerScore(0), computerScore(0), totalRounds(0) {}
void showRules() const {
cout << "\n===== 抛硬币游戏规则 =" << endl;
cout << "1. 选择正面或反面" << endl;
cout << "2. 系统将随机抛硬币" << endl;
cout << "3. 猜中则得1分,否则电脑得1分" << endl;
cout << "4. 先达到5分者获胜" << endl;
cout << "====================\n" << endl;
}
int getPlayerChoice() const {
int choice;
cout << "请选择:" << endl;
cout << "1. 正面" << endl;
cout << "2. 反面" << endl;
cout << "3. 查看规则" << endl;
cout << "4. 退出游戏" << endl;
cout << "请输入选择 (1-4): ";
cin >> choice;
return choice;
}
void showScore() const {
cout << "\n----- 当前比分 -----" << endl;
cout << "玩家: " << playerScore << " 分" << endl;
cout << "电脑: " << computerScore << " 分" << endl;
cout << "总局数: " << totalRounds << " 局" << endl;
cout << "-------------------\n" << endl;
}
void playRound(int playerChoice) {
totalRounds++;
coin.flip();
};
int main() {
CoinFlipGame game;
game.run();
return 0;
}