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]); } }
public int GetComputerSinkShipCount(ShipType shipType) { int count = 0; ShipFactory.GetInstance(shipType).AllShips.ForEach(ship => { if (GetRedSquareCount(ship) == ship.Count) { count++; } }); return(count); }
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); } } }
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); }
public SinkStatus CheckOpponentShipSink() { var ship = ShipFactory.GetInstance(CurrentRedSquare.ShipType); return(ship.CheckSink(OpponentOcean)); }