Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if !defined SNAKE_HPP
- #define SNAKE_HPP
- #include <prg_interactive.hpp>
- enum class Direction {
- North = 1, East, South, West
- };
- struct Position final {
- int x{0}, y{0};
- Position(int ix, int iy) : x{ix}, y{iy} {}
- };
- class Snake {
- public:
- virtual ~Snake() {}
- virtual void move();
- void render(prg::Canvas& canvas) const;
- void changeDirection(Direction new_direction);
- const Position& getPosition() const {return position_;}
- void setPosition(const Position& position){ position_ = position;}
- private:
- Direction direction_ {Direction::North};
- Position position_ {0,0};
- };
- class PlayerSnake : public Snake,
- public prg::IKeyEvent {
- public:
- PlayerSnake();
- virtual ~PlayerSnake();
- bool onKey(const prg::IKeyEvent::KeyEvent& key_event) override;
- };
- #endif // SNAKE_HPP
Advertisement
Add Comment
Please, Sign In to add comment