diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 03:12:49 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 03:12:49 +0100 |
| commit | f3a2c9fbc1c946379acdd077c0d742a3298a56e3 (patch) | |
| tree | 5ec921049e7ed7cd115e94a57d4dea3ee3d7d6fa /labb5 | |
| parent | 34d24825172e89a973e2a3559fb112cb0d4b75e1 (diff) | |
| download | tddd86-f3a2c9fbc1c946379acdd077c0d742a3298a56e3.tar.gz | |
newline polish
Diffstat (limited to 'labb5')
| -rwxr-xr-x | labb5/src/Boggle.cpp | 3 | ||||
| -rwxr-xr-x | labb5/src/Boggle.h | 4 | ||||
| -rwxr-xr-x | labb5/src/boggleplay.cpp | 21 |
3 files changed, 18 insertions, 10 deletions
diff --git a/labb5/src/Boggle.cpp b/labb5/src/Boggle.cpp index 06880e8..2741cae 100755 --- a/labb5/src/Boggle.cpp +++ b/labb5/src/Boggle.cpp @@ -225,9 +225,6 @@ string Boggle::words_to_string(const set<string>& words, int words_per_line) con if ((cur_word_idx+1) % words_per_line == 0) { res += '\n'; } - } else { - // newline after final - res += '\n'; } cur_word_idx++; } diff --git a/labb5/src/Boggle.h b/labb5/src/Boggle.h index 9e6e9cd..0082c2b 100755 --- a/labb5/src/Boggle.h +++ b/labb5/src/Boggle.h @@ -34,8 +34,8 @@ public: bool find_single_word(const string& word) const; string board_to_string() const; - string user_words_to_string(int words_per_line = 3) const; - string computer_words_to_string(int words_per_line = 3) const; + string user_words_to_string(int words_per_line = 8) const; + string computer_words_to_string(int words_per_line = 8) const; void do_computer_turn(); int get_computer_words_size() const; diff --git a/labb5/src/boggleplay.cpp b/labb5/src/boggleplay.cpp index 60e45c6..b11c9d2 100755 --- a/labb5/src/boggleplay.cpp +++ b/labb5/src/boggleplay.cpp @@ -34,22 +34,28 @@ void setup_board(Boggle& boggle) { } } +void print_user_status(const Boggle& boggle) { + cout << boggle.board_to_string() << endl; + cout << "Your words (" << boggle.get_user_words_size() << "): " << endl; + cout << boggle.user_words_to_string() << endl; + cout << "Your score: " << boggle.get_user_score() << endl; +} + /* * Plays one game of Boggle using the given boggle game state object. */ void playOneGame(Boggle& boggle) { boggle.clear(); setup_board(boggle); + clearConsole(); string user_input; while (true) { - std::cout << "It's your turn!" << std::endl; - cout << boggle.board_to_string() << endl; - cout << "Your words (" << boggle.get_user_words_size() << "): " << endl; - cout << boggle.user_words_to_string() << endl; - cout << "Your score: " << boggle.get_user_score() << endl; + cout << "It's your turn!" << endl; + print_user_status(boggle); cout << "Type a word (or press Enter to end your turn) "; getline(cin, user_input); + clearConsole(); if (user_input == "") { break; } @@ -64,11 +70,16 @@ void playOneGame(Boggle& boggle) { boggle.add_user_word(user_input); } } + print_user_status(boggle); + cout << endl; + cout << "It's my turn!" << endl; boggle.do_computer_turn(); cout << "My words (" << boggle.get_computer_words_size() << "): " << endl; cout << boggle.computer_words_to_string() << endl; cout << "My score: " << boggle.get_computer_score() << endl; + + cout << endl; if (boggle.get_computer_score() > boggle.get_user_score()) { cout << "Ha ha ha, I destroyed you. Better luck next time, puny human!" << endl; } else { |
