Addsy

snake.hpp

Apr 13th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #if !defined SNAKE_HPP
  2. #define SNAKE_HPP
  3.  
  4. #include <prg_interactive.hpp>
  5.  
  6.  
  7. enum class Direction {
  8.     North = 1, East, South, West
  9. };
  10.  
  11. struct Position final {
  12.     int x{0}, y{0};
  13.     Position(int ix, int iy) : x{ix}, y{iy} {}
  14. };
  15.  
  16. class Snake {
  17. public:
  18.     virtual ~Snake() {}
  19.     virtual void move();
  20.     void render(prg::Canvas& canvas) const;
  21.     void changeDirection(Direction new_direction);
  22.     const Position& getPosition() const {return position_;}
  23.     void setPosition(const Position& position){ position_ = position;}
  24.  
  25.  private:
  26.     Direction direction_ {Direction::North};
  27.     Position position_ {0,0};
  28. };
  29.  
  30.  
  31.     class PlayerSnake : public Snake,
  32.                         public prg::IKeyEvent {
  33.     public:
  34.         PlayerSnake();
  35.         virtual ~PlayerSnake();
  36.         bool onKey(const prg::IKeyEvent::KeyEvent& key_event) override;
  37. };
  38.  
  39.  
  40. #endif // SNAKE_HPP
Advertisement
Add Comment
Please, Sign In to add comment