Inheritance: System.Entity
示例#1
0
        /// <summary>
        /// Places the dragged ship onto the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GridAIDragDrop(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;

            ShipButton shipButton    = (ShipButton)e.Data.GetData(DataFormats.Serializable);
            Ship       selectedShip  = SelectShip(shipButton.ShipSize);
            Point      relativePoint = gridAI.PointToClient(new Point(e.X, e.Y));
            int        shipSize      = selectedShip.Length;

            Coordinates     coordinates = gridAI.GetCoordinatesFromMouse(relativePoint.X, relativePoint.Y);
            ShipOrientation direction   = shiftKey_Down(e.KeyState)
                ? ShipOrientation.Horizontal
                : ShipOrientation.Vertical;
            int modX = direction == ShipOrientation.Horizontal ? 1 : 0;
            int modY = direction == ShipOrientation.Vertical ? 1 : 0;

            int count = 0;

            for (int x = coordinates.X; x <= coordinates.X + ((shipSize - 1) * modX); x++)
            {
                for (int y = coordinates.Y; y <= coordinates.Y + ((shipSize - 1) * modY); y++)
                {
                    Coordinates coords = new Coordinates(x, y);
                    gridAI.SetCellShip(coords, shipButton.ShipPiece, count++, direction);
                }
            }
            selectedShip.Place(coordinates, direction);
            shipButton.Visible  = false;
            gridAI.CurrentHover = null;
            gridAI.Invalidate();
            AttemptPlayMatch();
        }
示例#2
0
 /// <summary>
 /// Copies an existing <see cref="Ship"/>.
 /// </summary>
 /// <param name="shipCopy"></param>
 public Ship(Ship shipCopy)
     : base(null)
 {
     ID = Guid.NewGuid().GetHashCode();
     IsPlaced = shipCopy.IsPlaced;
     Location = shipCopy.Location;
     Orientation = shipCopy.Orientation;
     Length = shipCopy.Length;
 }
 protected internal override void PerformOperation()
 {
     if (Match.Players.Contains(Player))
     {
         throw new InvalidEventException(this, "Match already contains the player.");
     }
     Match.Players.Add(Player);
     Player.Ships = new HashSet<Ship>();
     Player.Match = Match;
     foreach (Ship startShip in Match.StartingShips)
     {
         Ship newShip = new Ship(Player, startShip.Length);
         newShip.Owner = Player;
         Player.Ships.Add(newShip);
     }
 }
 /// <summary>
 /// Constructs this event with the player who owns the destroyed ship.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="destroyedShip"></param>
 public ShipDestroyedEvent(Ship destroyedShip)
     : base(destroyedShip)
 {
 }
示例#5
0
 public ShipHitEvent(Ship ship, Coordinates coords)
     : base(ship)
 {
     HitCoords = coords;
 }
 public ShipResetEvent(Ship ship)
     : base(ship)
 {
 }
 public ShipMovedEvent(Ship ship, Coordinates position, ShipOrientation orientation)
     : base(ship)
 {
     Position = position;
     Orientation = orientation;
 }
示例#8
0
 protected ShipEvent(Ship ship)
     : base(ship)
 {
     Ship = ship;
 }
示例#9
0
        /// <summary>
        /// Checks if another <see cref="Ship"/> occupies any cells that this <see cref="Ship"/> occupies.
        /// </summary>
        /// <param name="otherShip">The <see cref="Ship"/> to check for confliction with.</param>
        /// <returns>A value indicating the state of conflicting with the <paramref name="otherShip"/>.</returns>
        public bool ConflictsWith(Ship otherShip)
        {
            foreach (var otherShipLocation in otherShip.GetAllLocations())
            {
                if (this.IsAt(otherShipLocation))
                {
                    return true;
                }
            }

            return false;
        }
示例#10
0
 private void ASCIIWriteShip(IDNumber ctrlIdx, Ship ship, char character, ConsoleColor colorText, ConsoleColor colorBack)
 {
     foreach (Coordinates coord in ship.Locations)
     {
         ModifyASCII(ctrlIdx, coord.X, coord.Y, character, colorText, colorBack);
     }
 }