The PlayerInfo Class Header
class PlayerInfo {
public:
PlayerInfo(string name);
string getName();
virtual Move getMove(GameState state);
private:
string name;
};
|
getMove is declared virtual so that it can be polymorphically
overridden by the AutomatedPlayerInfo class.
|
Defining the PlayerInfo Class Members
PlayerInfo::PlayerInfo(string name) {
this->name = name;
}
string PlayerInfo::getName() {
return name;
}
Move PlayerInfo::getMove(GameState state) {
string response = new char[5];
cout << "Which pile will you remove from? " << endl;
cin >> response;
int pile = atoi(response.c_str()); // if response non-integer, zero returned
cout << "How many coins do you want to remove? " << endl;
cin >> response;
int coins = atoi(response.c_str());
return new MoveInfo(coins, pile);
}
|
- atoi is a C built-in function that converts string to integers
- c_str is a C++ method that converts a C++ string to its C-style representation
|