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);
renderPacMan(game.pacMan);
renderGhost(game.blinky);
renderGhost(game.speedy);
renderGhost(game.inky);
renderGhost(game.clyde);
std::apply([&](const auto&... ghost) {
(renderGhost(ghost),...);
}, game.ghosts);
renderScore(game.score.points);
renderLives(game.score.lives);

View File

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

View File

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