Skip to content

Commit

Permalink
Move reading player input outside Game class.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 6, 2024
1 parent 88d9354 commit 92ede87
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Map.h"
#include "MapUtils.h"
#include "PointUtils.h"
#include "StandardInput.h"
#include "Tank.h"
#include "Utils.h"

Expand Down Expand Up @@ -77,18 +76,16 @@ void Game::movement(Tank& tank, Direction direction)
}
}

void Game::control()
void Game::control(const std::set<InputAction>& actions)
{
moveBullets();

StandardInput input;
for (auto& tank : tanks_)
{
Direction direction{Direction::UP};
if (tank.isPlayerControlled())
{
setPower(tank);
const auto actions{input.getGameActions()};
const auto now{std::chrono::system_clock::now()};
if ((actions.find(InputAction::FIRE) != actions.end()) &&
tank.canFire(now))
Expand Down
3 changes: 1 addition & 2 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct Point;
class Display;
enum class InputAction : char;
enum class Level : char;
class Input;

class Game
{
Expand All @@ -24,7 +23,7 @@ class Game

void init(std::iostream& level);

void control();
void control(const std::set<InputAction>& actions);

bool isGameEnding(Display& display) const;

Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ int main()
if (action == InputAction::TIMER)
{
game.draw(screen);
game.control();
const std::set<InputAction> actions{input.getGameActions()};
game.control(actions);
screen.refresh();
}
}
Expand Down

0 comments on commit 92ede87

Please sign in to comment.