#include "ghost.h" #include #include #include #include using namespace std; /* * Guidance and tips: * - Modify the file structure to be in separate files, a header and implementation. * - Extend 'run()' and 'draw_map()' with the required functionality. * - Add all ghosts in a container as a member * - Break out all large code blocks to their own functions. * - Use helper functions to avoid duplicated code. * - Try to limit each function to about 25 lines of code. */ class Ghost_Tester { public: Ghost_Tester() : pacman {} { } void run() { while(true) { draw_map(); cout << "> "; string line {}; getline(cin, line); istringstream iss {line}; string command {}; iss >> command; if (command == "pos") { Point new_pos {}; iss >> new_pos.x >> new_pos.y; pacman.set_position(new_pos); } else if (command == "dir") { } else if (command == "quit") { break; } } } private: /* * A helper function that determines which of two characters to draw for a * given position on the board. */ string to_draw(Point const& curr_pos) { string to_draw{" "}; if (pacman.get_position() == curr_pos) { to_draw[1] = '@'; } return to_draw; } /* * A helper function to draw the game board for the test program. * * Iterates over each row and column in the map. Index for the rows are * flipped to place y = 0 at the bottom. * * Each point on the map are drawn as two characters since one character in * the terminal is about double the height compared to its' width. */ void draw_map() { cout << "+" << setfill('-') << setw(WIDTH * 2) << "-" << "+\n"; for (int y {HEIGHT - 1}; y >= 0; --y) { cout << "|"; for (int x {}; x < WIDTH; ++x) { cout << to_draw( Point{x,y} ); } cout << "|\n"; } cout << "+" << setfill('-') << setw(WIDTH * 2) << "-" << "+" << endl; } Pacman pacman; }; int main() { Ghost_Tester gt {}; gt.run(); return 0; }