Put the ghosts in a tuple to reduce duplication
This commit is contained in:
parent
3e84746cee
commit
ced6cd829c
3 changed files with 9 additions and 16 deletions
|
@ -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);
|
||||
|
|
13
lib/Game.cpp
13
lib/Game.cpp
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue