* Move the position one step in the indicated direction. * @param dir Direction to move into. * @return Position moved in the indicated direction. */
| 142 | * @return Position moved in the indicated direction. |
| 143 | */ |
| 144 | bool Position::move(Direction2 dir) |
| 145 | { |
| 146 | switch (dir) { |
| 147 | case DIR2_INVALID: |
| 148 | return true; |
| 149 | |
| 150 | case DIR2_NORTH: |
| 151 | if (this->posY > 0) { |
| 152 | this->posY--; |
| 153 | return true; |
| 154 | } |
| 155 | break; |
| 156 | |
| 157 | case DIR2_NORTH_EAST: |
| 158 | if (this->posX < WORLD_W - 1 && this->posY > 0) { |
| 159 | this->posX++; |
| 160 | this->posY--; |
| 161 | return true; |
| 162 | } |
| 163 | case DIR2_EAST: |
| 164 | if (this->posX < WORLD_W - 1) { |
| 165 | this->posX++; |
| 166 | return true; |
| 167 | } |
| 168 | break; |
| 169 | |
| 170 | case DIR2_SOUTH_EAST: |
| 171 | if (this->posX < WORLD_W -1 && this->posY < WORLD_H - 1) { |
| 172 | this->posX++; |
| 173 | this->posY++; |
| 174 | return true; |
| 175 | } |
| 176 | break; |
| 177 | |
| 178 | case DIR2_SOUTH: |
| 179 | if (this->posY < WORLD_H - 1) { |
| 180 | this->posY++; |
| 181 | return true; |
| 182 | } |
| 183 | break; |
| 184 | |
| 185 | case DIR2_SOUTH_WEST: this->posX--; this->posY++; break; |
| 186 | if (this->posX > 0 && this->posY < WORLD_H - 1) { |
| 187 | this->posX--; |
| 188 | this->posY++; |
| 189 | return true; |
| 190 | } |
| 191 | break; |
| 192 | |
| 193 | case DIR2_WEST: |
| 194 | if (this->posX > 0) { |
| 195 | this->posX--; |
| 196 | return true; |
| 197 | } |
| 198 | break; |
| 199 | |
| 200 | case DIR2_NORTH_WEST: |
| 201 | if (this->posX > 0 && this->posY > 0) { |
no outgoing calls
no test coverage detected