diff options
| author | Fuwn <[email protected]> | 2022-05-26 00:43:28 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-05-26 00:43:28 -0700 |
| commit | d946ecce7ca44299df225fb33e63cdf06482a192 (patch) | |
| tree | e755210ddbcdfb52c698015e62cbdf6a5130a185 | |
| parent | fix(platypus): reorder ctor (diff) | |
| download | wk7_platypusproject-d946ecce7ca44299df225fb33e63cdf06482a192.tar.xz wk7_platypusproject-d946ecce7ca44299df225fb33e63cdf06482a192.zip | |
refactor(platypus.cpp): simplify namesFile
| -rw-r--r-- | platypus/platypus.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/platypus/platypus.cpp b/platypus/platypus.cpp index 094fae5..fef02e6 100644 --- a/platypus/platypus.cpp +++ b/platypus/platypus.cpp @@ -92,17 +92,11 @@ Platypus Platypus::hatch() const { if (this->alive) { int newGender = rand() & 1; std::string newName; - std::ifstream namesFile; + // If the platypus is male, pick a random male name; otherwise, pick a + // female name. + std::ifstream namesFile(newGender ? "mnames.txt" : "fnames.txt"); std::vector<std::string> names; - // If the platypus is male, pick a random male name; ... - if (newGender) { - namesFile.open("mnames.txt"); - } else { - // ... otherwise, pick a female name - namesFile.open("fnames.txt"); - } - while (std::getline(namesFile, newName)) { names.emplace_back(newName); } |