Movable.cc (668B)
1 #include "Movable.hpp" 2 3 Movable::Movable(int x, int y, int dir, char sym) 4 :x(x), y(y), dir(dir), sym(sym) 5 { 6 } 7 8 Movable::~Movable() 9 { 10 } 11 12 void 13 Movable::set_newpos(int dir, int xmax, int ymax) 14 { 15 switch (dir) { 16 case Direction::LEFT: 17 if (--x < 0) 18 x = 0; 19 break; 20 case Direction::RIGHT: 21 if (++x > xmax - 2) 22 x = xmax - 2; 23 break; 24 case Direction::UP: 25 if (--y < 0) 26 y = 0; 27 break; 28 case Direction::DOWN: 29 if (++y > ymax - 1) 30 y = ymax - 1; 31 break; 32 } 33 this->dir = dir; 34 } 35 36 int 37 Movable::get_x() const 38 { 39 return x; 40 } 41 42 int 43 Movable::get_y() const 44 { 45 return y; 46 } 47 48 int 49 Movable::get_dir() const 50 { 51 return dir; 52 } 53 54 char 55 Movable::get_sym() const 56 { 57 return sym; 58 }