示例#1
0
void Map::ShipOccupy(int x, int y, Direction dir, Ship* ship)
{
	int deltaX = 0;
	int deltaY = 0;
	switch (dir)
	{
	case DIR_UP:
		deltaY = 1;
		break;
	case DIR_DOWN:
		deltaY = -1;
		break;
	case DIR_LEFT:
		deltaX = -1;
		break;
	case DIR_RIGHT:
		deltaX = 1;
		break;
	}

	for (int i = 0; i < ship->GetSize(); ++i)
	{
		Tile* tile = GetTile(x, y);
		_ASSERT(tile != nullptr);
		tile->SetOccupiedShip(ship);
		x += deltaX;
		y += deltaY;
	}
}
示例#2
0
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;
}