A1/hands.h

51 lines
1.4 KiB
C
Raw Normal View History

#include <istream>
#include <memory>
enum GameResult { Win, Tie, Loss };
class Hand {
public:
// Converts a user-inputted character to the correct instance of Hand.
static std::unique_ptr<Hand> fromChar(char);
// Randomly returns one of the variants of Hand.
static std::unique_ptr<Hand> generateRandom();
// Returns the lowercase name of this type of hand, for example "rock" or
// "scissors".
virtual std::string getHandName() const = 0;
// Returns if this instance of Hand wins against another instance. The
// returned value is from the perspective of this instance of hand. For
// example, if GameResult::Win is returned, the instance of Hand wins
// against the passed argument Hand.
virtual GameResult compareAgainst(const Hand&) = 0;
};
class Rock : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand&) override;
};
class Paper : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand&) override;
};
class Scissors : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand&) override;
};
class Lizard : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand&) override;
};
class Spock : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand&) override;
};