public void SetPointState(Point point, PointStates pointState)
 {
     if (!IsPointOnBoard(point))
     {
         throw new PointOutsideOfBoardException(point, this);
     }
     pointStatesMatrix[point.Y, point.X] = pointState;
 }
        public bool IsValidPointToShoot(Point point)
        {
            if (!IsPointOnBoard(point))
            {
                return(false);
            }
            PointStates pointState = GetPointState(point);

            return(pointState == PointStates.Empty || pointState == PointStates.Ship);
        }
        public PointStates ShootPoint(Point point)
        {
            if (!IsPointOnBoard(point))
            {
                throw new PointOutsideOfBoardException(point, this);
            }
            switch (GetPointState(point))
            {
            case PointStates.Empty:
                SetPointState(point, PointStates.Miss);
                return(PointStates.Empty);

            case PointStates.Ship:
                Ship hitShip = GetShipAtPoint(point);
                hitShip.HitElementAtPoint(point);
                if (hitShip.IsDestroyed())
                {
                    foreach (Ship.Element element in hitShip.Elements)
                    {
                        SetPointState(element.Point, PointStates.DestroyedShip);
                    }
                    if (!Options.AllowAdjacentShips)
                    {
                        Point initialShipPoint = hitShip.GetInitialPoint();
                        for (int y = initialShipPoint.Y - 1; y <= initialShipPoint.Y + hitShip.ShipType.Size.Height; y++)
                        {
                            for (int x = initialShipPoint.X - 1; x <= initialShipPoint.X + hitShip.ShipType.Size.Width; x++)
                            {
                                Point checkPoint = new Point(x, y);
                                if (IsPointOnBoard(checkPoint))
                                {
                                    PointStates pointStateAtCheckPoint = GetPointState(checkPoint);
                                    if (pointStateAtCheckPoint == PointStates.Empty)
                                    {
                                        SetPointState(checkPoint, PointStates.Miss);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    SetPointState(point, PointStates.HitShipElement);
                    return(PointStates.Ship);
                }
                break;
            }
            return(GetPointState(point));
        }
Beispiel #4
0
 public void ReadChildData(BinaryReader reader)
 {
     _bitmap.ReadString(reader);
     _bitmap2.ReadString(reader);
     for (int x = 0; x < _pointStates.Count; x++)
     {
         PointStates.AddNew();
         PointStates[x].Read(reader);
     }
     for (int x = 0; x < _pointStates.Count; x++)
     {
         PointStates[x].ReadChildData(reader);
     }
 }
Beispiel #5
0
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                _bitmap.ReadString(reader);
                _bitmap2.ReadString(reader);
                for (x = 0; (x < _pointStates.Count); x = (x + 1))
                {
                    PointStates.Add(new ContrailPointStatesBlock());
                    PointStates[x].Read(reader);
                }
                for (x = 0; (x < _pointStates.Count); x = (x + 1))
                {
                    PointStates[x].ReadChildData(reader);
                }
            }