Put the ghosts in a tuple to reduce duplication

This commit is contained in:
Corentin Jabot 2021-06-28 10:37:52 +02:00 committed by Patricia Aas
parent 3e84746cee
commit ced6cd829c
3 changed files with 9 additions and 16 deletions

View file

@ -26,10 +26,9 @@ void Canvas::update(const Game & game) {
renderSuperPellets(game.superPellets); renderSuperPellets(game.superPellets);
renderPacMan(game.pacMan); renderPacMan(game.pacMan);
renderGhost(game.blinky); std::apply([&](const auto&... ghost) {
renderGhost(game.speedy); (renderGhost(ghost),...);
renderGhost(game.inky); }, game.ghosts);
renderGhost(game.clyde);
renderScore(game.score.points); renderScore(game.score.points);
renderLives(game.score.lives); renderLives(game.score.lives);

View file

@ -11,13 +11,11 @@ Game::Game()
: pacMan(board), : pacMan(board),
pellets(board), pellets(board),
superPellets(board), superPellets(board),
blinky(board), ghosts(Blinky(board), Speedy(board), Inky(board), Clyde(board)) {
speedy(board),
inky(board),
clyde(board) {
score.lives = DEFAULT_LIVES; score.lives = DEFAULT_LIVES;
} }
auto Game::now() { auto Game::now() {
return std::chrono::system_clock::now(); return std::chrono::system_clock::now();
} }
@ -52,10 +50,9 @@ void Game::run() {
void Game::step(std::chrono::milliseconds delta, InputState inputState) { void Game::step(std::chrono::milliseconds delta, InputState inputState) {
pacMan.update(delta, inputState, board); pacMan.update(delta, inputState, board);
blinky.update(delta, board); std::apply([&](auto &... ghost) {
speedy.update(delta, board); (ghost.update(delta, board),...);
inky.update(delta, board); }, ghosts);
clyde.update(delta, board);
eatPellets(); eatPellets();
} }

View file

@ -23,10 +23,7 @@ private:
PacMan pacMan; PacMan pacMan;
Pellets pellets; Pellets pellets;
SuperPellets superPellets; SuperPellets superPellets;
Blinky blinky; std::tuple<Blinky, Speedy, Inky, Clyde> ghosts;
Speedy speedy;
Inky inky;
Clyde clyde;
Score score; Score score;
void step(std::chrono::milliseconds delta, InputState inputState); void step(std::chrono::milliseconds delta, InputState inputState);