const Piece *Game::getPiece(unsigned int x, unsigned int y) const { if(__grid[((x*__width) + y)] != nullptr) { return __grid[((x*__width) + y)]; } throw PositionEmptyEx(x,y); }
const Piece* Game::getPiece(unsigned int x, unsigned int y) const { if(y >= __width || x >=__height) throw OutOfBoundsEx(__height, __width, x, y); if (__grid[y + (x * __width)] == nullptr) throw PositionEmptyEx(x, y); return __grid[y + (x * __width)]; }
const Piece *Game::getPiece(unsigned int x, unsigned int y) const { //TODO would i return the piece that is at that location?? int location = y +(x* __width); //will look for this location on the grid if (x < 0 || x >= __height || y < 0 || y >= __width) throw OutOfBoundsEx(__width, __height, x, y); if (__grid[location] == nullptr) throw PositionEmptyEx(x, y); return __grid[location]; //returns the location on the grid }
const Piece * Game::getPiece(unsigned int x, unsigned int y) const { if (x > __width || y > __height) throw OutOfBoundsEx(__width, __height, x, y); for (int it = 0; it < __grid.size(); it++) { if (__grid[it] != nullptr) if (__grid[it]->getPosition().x == x && __grid[it]->getPosition().y == y) return __grid[it]; } throw PositionEmptyEx(x, y); return __grid[0]; }
const Piece *Game::getPiece(unsigned int x, unsigned int y) const { if (y >= __width || x >= __height) { throw OutOfBoundsEx(__width, __height, x, y); } if (__grid[x * __width + y] == nullptr) { throw PositionEmptyEx(x, y); } int location = x * __width + y; return __grid[location]; }
const Piece *Game::getPiece(unsigned int x, unsigned int y) const { if(__grid[y*__width + x] != nullptr) return __grid[y*__width + x]; throw PositionEmptyEx(x, y); }