Exemplo n.º 1
0
        public void DeployUnit(Unit unit, Position position)
        {
            if (unit.Deployed)
            {
                throw new GameException("Tried to deploy a unit that has already been deployed");
            }
            Hex hex = Map.GetHex(position);

            if (hex == null)
            {
                throw new GameException("Encountered an invalid deployment position in a deployment request");
            }
            if (hex.InitialDeploymentZone == null || hex.InitialDeploymentZone.Value != Identifier)
            {
                throw new GameException("Tried to deploy a unit outside the deployment zone");
            }
            if (hex.Owner == null || hex.Owner.Value != Identifier)
            {
                throw new GameException("Tried to deploy a unit in a deployment zone that is currently not controlled by the player");
            }
            if (hex.Unit != null)
            {
                throw new GameException("Tried to deploy a unit on a hex that is already occupied");
            }
            unit.MoveToHex(hex);
        }
Exemplo n.º 2
0
        public void InitialUnitDeployment(Unit unit, Position position)
        {
            if (unit.Deployed)
            {
                throw new GameException("Tried to specify the position of a unit that has already been deployed");
            }
            if (!Map.IsInInitialDeploymentZone(Identifier, position))
            {
                throw new GameException("Tried to deploy units outside the player's deployment zone");
            }
            Hex hex = Map.GetHex(position);

            if (hex.Unit != null)
            {
                throw new GameException("Tried to deploy a unit on a hex that is already occupied");
            }
            unit.MoveToHex(hex);
        }
Exemplo n.º 3
0
        public void MoveUnit(Unit unit, Position newPosition, out int movementPointsLeft, out List <Hex> captures)
        {
            if (!unit.Deployed)
            {
                throw new GameException("Tried to move an undeployed unit");
            }
            var  movementMap = Map.CreateMovementMap(unit);
            Path pathUsed;

            if (!movementMap.TryGetValue(newPosition, out pathUsed))
            {
                throw new GameException("The unit can't reach the specified hex");
            }
            unit.MovementPoints = pathUsed.MovementPointsLeft;
            Hex hex = Map.GetHex(newPosition);

            unit.MoveToHex(hex);
            captures           = CaptureHexes(pathUsed);
            movementPointsLeft = pathUsed.MovementPointsLeft;
        }
Exemplo n.º 4
0
 public void MoveUnit(Unit unit, Position newPosition, out int movementPointsLeft, out List<Hex> captures)
 {
     if (!unit.Deployed)
         throw new GameException("Tried to move an undeployed unit");
     var movementMap = Map.CreateMovementMap(unit);
     Path pathUsed;
     if (!movementMap.TryGetValue(newPosition, out pathUsed))
         throw new GameException("The unit can't reach the specified hex");
     unit.MovementPoints = pathUsed.MovementPointsLeft;
     Hex hex = Map.GetHex(newPosition);
     unit.MoveToHex(hex);
     captures = CaptureHexes(pathUsed);
     movementPointsLeft = pathUsed.MovementPointsLeft;
 }
Exemplo n.º 5
0
 public void InitialUnitDeployment(Unit unit, Position position)
 {
     if (unit.Deployed)
         throw new GameException("Tried to specify the position of a unit that has already been deployed");
     if (!Map.IsInInitialDeploymentZone(Identifier, position))
         throw new GameException("Tried to deploy units outside the player's deployment zone");
     Hex hex = Map.GetHex(position);
     if (hex.Unit != null)
         throw new GameException("Tried to deploy a unit on a hex that is already occupied");
     unit.MoveToHex(hex);
 }
Exemplo n.º 6
0
 public void DeployUnit(Unit unit, Position position)
 {
     if (unit.Deployed)
         throw new GameException("Tried to deploy a unit that has already been deployed");
     Hex hex = Map.GetHex(position);
     if (hex == null)
         throw new GameException("Encountered an invalid deployment position in a deployment request");
     if (hex.InitialDeploymentZone == null || hex.InitialDeploymentZone.Value != Identifier)
         throw new GameException("Tried to deploy a unit outside the deployment zone");
     if (hex.Owner == null || hex.Owner.Value != Identifier)
         throw new GameException("Tried to deploy a unit in a deployment zone that is currently not controlled by the player");
     if (hex.Unit != null)
         throw new GameException("Tried to deploy a unit on a hex that is already occupied");
     unit.MoveToHex(hex);
 }