Exemple #1
0
        public Tuple <char, int> SelectSquare()
        {
            if (CurrentRedSquare is not null)
            {
                var ship = ShipFactory.GetInstance(CurrentRedSquare.ShipType);

                return(ship.FindNextSquer(OpponentOcean, CurrentRedSquare.Position));
            }
            else
            {
                List <Tuple <char, int> > blankSquares;

                if (OpponentOcean.Any(r => r.Status is PositionStatus.Red && !r.IsSinked))
                {
                    blankSquares = OpponentOcean.Where(r => r.Status is PositionStatus.Red && !r.IsSinked).Select(r => r.Position).ToList();
                }
                else
                {
                    blankSquares = OpponentOcean.Where(r => r.Status == PositionStatus.Empty).Select(r => r.Position).ToList();
                }

                Random random = new Random();
                var    index  = random.Next(1, blankSquares.Count);
                return(blankSquares[index]);
            }
        }
Exemple #2
0
        public int GetComputerSinkShipCount(ShipType shipType)
        {
            int count = 0;

            ShipFactory.GetInstance(shipType).AllShips.ForEach(ship =>
            {
                if (GetRedSquareCount(ship) == ship.Count)
                {
                    count++;
                }
            });
            return(count);
        }
Exemple #3
0
        public void Process(Tuple <char, int> position, PositionStatus positionStatus, ShipType?shipType, bool isSinked)
        {
            if (CurrentRedSquare is not null)
            {
                var ship = ShipFactory.GetInstance(CurrentRedSquare.ShipType);

                ship.RefreshPosibilities(position, positionStatus, isSinked, shipType);

                if (isSinked)
                {
                    Sinked(ship);
                }
            }
        }
Exemple #4
0
        public void BuildShips(ShipType shipType)
        {
            void setInBoard(List <List <Tuple <char, int> > > ships, ShipType shipType)
            {
                ships.ForEach(ship =>
                {
                    ship.ForEach(position =>
                    {
                        ComputerOcean.Single(r => r.Position.Equals(position)).ShipType = shipType;
                    });
                });
            }

            var ships = ShipFactory.GetInstance(shipType).Build(ComputerOcean);

            setInBoard(ships, shipType);
        }
Exemple #5
0
        public SinkStatus CheckOpponentShipSink()
        {
            var ship = ShipFactory.GetInstance(CurrentRedSquare.ShipType);

            return(ship.CheckSink(OpponentOcean));
        }