Reformat
This commit is contained in:
parent
e07bcb6dcf
commit
430a8225c5
2 changed files with 23 additions and 12 deletions
32
hands.cpp
32
hands.cpp
|
@ -4,6 +4,7 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
std::unique_ptr<Hand> Hand::fromChar(const char letter) {
|
||||
|
@ -36,7 +37,9 @@ std::unique_ptr<Hand> Hand::generateRandom() {
|
|||
case 2:
|
||||
return std::make_unique<Scissors>();
|
||||
default:
|
||||
std::cerr << "An invalid random number was generated, this should be impossible" << std::endl;
|
||||
std::cerr << "An invalid random number was generated, this should "
|
||||
"be impossible"
|
||||
<< std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -47,25 +50,34 @@ std::string Rock::getHandName() const { return "rock"; }
|
|||
GameResult Rock::compareAgainst(const Hand &other) {
|
||||
const std::string otherName = other.getHandName();
|
||||
|
||||
if (otherName == "rock") return GameResult::Tie;
|
||||
if (otherName == "scissors") return GameResult::Win;
|
||||
else return GameResult::Loss;
|
||||
if (otherName == "rock")
|
||||
return GameResult::Tie;
|
||||
if (otherName == "scissors")
|
||||
return GameResult::Win;
|
||||
else
|
||||
return GameResult::Loss;
|
||||
}
|
||||
|
||||
std::string Paper::getHandName() const { return "paper"; }
|
||||
GameResult Paper::compareAgainst(const Hand &other) {
|
||||
const std::string otherName = other.getHandName();
|
||||
|
||||
if (otherName == "paper") return GameResult::Tie;
|
||||
if (otherName == "rock") return GameResult::Win;
|
||||
else return GameResult::Loss;
|
||||
if (otherName == "paper")
|
||||
return GameResult::Tie;
|
||||
if (otherName == "rock")
|
||||
return GameResult::Win;
|
||||
else
|
||||
return GameResult::Loss;
|
||||
}
|
||||
|
||||
std::string Scissors::getHandName() const { return "scissors"; }
|
||||
GameResult Scissors::compareAgainst(const Hand &other) {
|
||||
const std::string otherName = other.getHandName();
|
||||
|
||||
if (otherName == "scissors") return GameResult::Tie;
|
||||
if (otherName == "paper") return GameResult::Win;
|
||||
else return GameResult::Loss;
|
||||
if (otherName == "scissors")
|
||||
return GameResult::Tie;
|
||||
if (otherName == "paper")
|
||||
return GameResult::Win;
|
||||
else
|
||||
return GameResult::Loss;
|
||||
}
|
3
main.cpp
3
main.cpp
|
@ -11,8 +11,7 @@ int main(void) {
|
|||
|
||||
while (true) {
|
||||
// Take a letter input and convert it to the correct class type for
|
||||
// later
|
||||
// use
|
||||
// later use
|
||||
char handLetter;
|
||||
std::cout << "Welcome to a round of Rock Paper Scissors! Please enter "
|
||||
"a hand to play (R/P/S): ";
|
||||
|
|
Loading…
Reference in a new issue