bool Map::CheckPosition(int x, int y) { if (false == CheckOutOfMap(x, y)) { return false; } Tile* tile = GetTile(x, y); _ASSERT(tile != nullptr); Ship* occupiedShip = tile->GetOccupiedShip(); if (nullptr != occupiedShip) { return false; } return true; }
HitResult Player::hitCheck(Point p) { Tile* targetTile = m_Map->GetTile(p.getX(), p.getY()); if (targetTile == nullptr || targetTile->isAttacked()) { return ERROR; } Ship* targetShip = targetTile->GetOccupiedShip(); if ( targetShip != nullptr) { targetShip->OnHit(); if (targetShip->GetHp() == 0 ) { switch (targetShip->GetSize()) { case 2: return D_DESTROY; case 3: return C_DESTROY; case 4: return B_DESTROY; case 5: return A_DESTROY; default: return ERROR; } } targetTile->SetOccupiedShip(nullptr); return HIT; } return MISS; }