summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-26 00:43:28 -0700
committerFuwn <[email protected]>2022-05-26 00:43:28 -0700
commitd946ecce7ca44299df225fb33e63cdf06482a192 (patch)
treee755210ddbcdfb52c698015e62cbdf6a5130a185
parentfix(platypus): reorder ctor (diff)
downloadwk7_platypusproject-d946ecce7ca44299df225fb33e63cdf06482a192.tar.xz
wk7_platypusproject-d946ecce7ca44299df225fb33e63cdf06482a192.zip
refactor(platypus.cpp): simplify namesFile
-rw-r--r--platypus/platypus.cpp12
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);
}