예제 #1
0
        public bool AddShip(IBattleShip ship, IBoardPosition position)
        {
            var y       = position.Row - 1;
            var x       = position.Column - 1;
            var counter = 0;

            for (int i = y; i < y + ship.Height; i++)
            {
                for (int j = x; j < x + ship.Width; j++, counter++)
                {
                    this[i, j] = ship.Parts[counter];
                }
            }
            return(true);
        }
예제 #2
0
        public void Visit(IBattleShip battleShip)
        {
            if (PelletsAreInOrder(pellet.source))
            {
                var temp  = minOrderPerShip[pellet.source].GetList();
                var max   = pellet.order;
                var temp1 = minOrderPerShip[pellet.source].RemoveMin(false);
                while (temp1 != null && temp1.order == minValues[pellet.source])
                {
                    var result = minOrderPerShip[pellet.source].RemoveMin(true);
                    Console.WriteLine($"Reducing health by {result} for ship with shipid {result.source} details =>{battleShip}");
                    battleShip.ReduceHealth(result);

                    if (result.order > max)
                    {
                        max = result.order;
                    }
                    minValues[pellet.source]++;
                }
                minOrderPerShip[pellet.source].Clear();
                Console.WriteLine($"Health of ship with shipId {pellet.source} " + battleShip);
            }
        }
예제 #3
0
 public BattleShipPart(IBattleShip parent)
 {
     Parent        = parent;
     RemainingHits = parent.Type == UnitType.P ? 1 : 2;
     Health        = UnitHealth.Fresh;
 }
예제 #4
0
 /// <summary>
 /// Constructor of the battleship in the game
 /// </summary>
 /// <param name="game"></param>
 /// <param name="battleShip"></param>
 public GameBattleShip(IGameBattleField gameBattleField, IBattleShip battleShip)
 {
     _gameBattleField = (GameBattleField)gameBattleField;
     _battleShip      = (BattleShip)battleShip;
     _state           = BattleShipState.Full;
 }