目录
源码:
想法:
可以改进的地方:
源码:
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>using std::cout;
using std::endl;
using std::cin;class player {
private:int card;bool viewable;
public:player(): card(0), viewable(false) {}void setCardValue() {card = rand() % 10 + 1;}int getCardValue() {if (viewable == false) {cout << "目前牌不可见" << endl;return 0; // 返回一个默认值,比如0,但注意这只是一个标记} else {return card;}}void setviewable(bool flag) {viewable = flag;}bool checkCard(int guess) { // 改为检查当前玩家的牌return guess == card;}std::string getResult(bool flag) {if (flag) {return "猜对了!!";} else {return "猜错了!!";}}
};int main() {srand(time(nullptr));player one;player two;int guess = 0;co