Exemplo n.º 1
0
        private BombingResult GetResultOfBombing(Cell cell)
        {
            if (Ships == null)
            {
                return(BombingResult.Miss);
            }

            var ship = Ships.FirstOrDefault(s => s.OccupiedCells.Contains(cell));

            if (ship == null)
            {
                return(BombingResult.Miss);
            }

            if (ship.IsSunk)
            {
                if (IsGameOver())
                {
                    return(BombingResult.AllShipsSunk);
                }

                return(BombingResult.Sink);
            }

            return(BombingResult.Hit);
        }
Exemplo n.º 2
0
        //private void InitializeShips()
        //{
        //    Ships.Add(new Ship(1));
        //    Ships.Add(new Ship(1));
        //    Ships.Add(new Ship(1));
        //    Ships.Add(new Ship(1));
        //    Ships.Add(new Ship(4));
        //    Ships.Add(new Ship(3));
        //    Ships.Add(new Ship(3));
        //    Ships.Add(new Ship(2));
        //    Ships.Add(new Ship(2));
        //    Ships.Add(new Ship(2));
        //}

        public void Shoot(int x, int y)
        {
            var cell = Field[x][y];

            if (cell.State == CellState.Hidden)
            {
                var ship = Ships.FirstOrDefault(s => s.Coords.Contains(cell));
                if (ship != null)
                {
                    Console.WriteLine("DEAD");
                }
            }
        }
Exemplo n.º 3
0
        public CellStateName?AttackCellOnBoard(int xCoordinate, int yCoordinate)
        {
            Attack = new Attack
            {
                XCoordinate = xCoordinate,
                YCoordinate = yCoordinate
            };

            var result = Board.AttackCellOnBoard(Attack);

            if (result == CellStateName.Hit)
            {
                var ship = Ships.FirstOrDefault(x => x.ShipRange.Contains(new Tuple <int, int>(xCoordinate, yCoordinate)));
                if (ship != null)
                {
                    ship.Hits += 1;
                }

                Attack.SuccessfulAttack = true;
            }

            return(result);
        }
Exemplo n.º 4
0
        public AttackResult ProcessAttack(Location location)
        {
            Square square = GameBoard.Squares.At(location.Row, location.Column);

            if (square.IsOccupied)
            {
                var ship = Ships.FirstOrDefault(x => x.Name == square.Ship.Name);
                ship.Hits++;
                square.Hits++;
                Console.WriteLine($"{Name}: I've been HIT at ({location.Row}, {location.Column})");
                if (ship.IsSunk)
                {
                    Console.WriteLine($"{Name} says my {ship.Name} SUNK!!!");
                }

                return(AttackResult.Hit);
            }
            else
            {
                Console.WriteLine($"{Name}: Ha ha! You MISSED it!");
                square.Hits++;
                return(AttackResult.Miss);
            }
        }
Exemplo n.º 5
0
        public void UpdateStatus()
        {
            LowCondition   = false;
            HeavilyDamaged = false;
            NeedCharge     = false;
            Repairing      = false;
            foreach (var ship in Ships)
            {
                LowCondition   |= ship.Condition < 40;
                HeavilyDamaged |= !ship.IsEscaped && ship.DamageControl == null && ship != Ships.FirstOrDefault() && ship.HP.Current * 4 <= ship.HP.Max;
                NeedCharge     |= !(ship.Fuel.IsMax && ship.Bull.IsMax);
                Repairing      |= ship.IsRepairing;
            }
#pragma warning disable CC0014
            if (InSortie)
            {
                Status = HeavilyDamaged ? FleetStatus.Warning : FleetStatus.InSortie;
            }
            else if (MissionState != FleetMissionState.None)
            {
                Status = FleetStatus.InMission;
            }
            else if (NeedCharge || HeavilyDamaged || LowCondition || Repairing || CanHomeportRepairing)
            {
                Status = FleetStatus.NotReady;
            }
            else
            {
                Status = FleetStatus.Ready;
            }
#pragma warning restore CC0014
            AirFightPower = Ships.Where(x => !x.IsEscaped).Aggregate(new int[8], (x, y) => x.Zip(y.AirFightPower, (a, b) => a + b).ToArray());
            if (Ships.Any())
            {
                mincondition = Ships.Min(x => x.Condition);
            }
            else
            {
                mincondition = 49;
                Status       = FleetStatus.Empty;
            }
            OnPropertyChanged(nameof(AirFightPower));
            OnPropertyChanged(nameof(LevelSum));
            OnPropertyChanged(nameof(LevelAverage));
            OnPropertyChanged(nameof(LoSInMap));
            OnPropertyChanged(nameof(ChargeCost));
            OnPropertyChanged(nameof(RepairCost));
            OnPropertyChanged(nameof(CanHomeportRepairing));
        }