Example #1
0
 /// <summary>
 /// Remove pawn from the occupied pawns
 /// </summary>
 /// <param name="pawn"></param>
 public void RemovePawn(Pawn pawn)
 {
     if (OccupiedBy.Count > 0 && OccupiedBy[0].Owner.ID == pawn.Owner.ID)
     {
         OccupiedBy.RemoveAll(x => x.ID == pawn.ID);
         Update();
     }
 }
Example #2
0
 public TimeSlotDTO ToDTO()
 {
     return(new TimeSlotDTO()
     {
         ID = this.ID,
         Start = this.Start,
         End = this.End,
         OccupiedBy = OccupiedBy.Select(e => new HabitantDTO(e)).ToList(),
         Gym = this.Gym.Name
     });
 }
Example #3
0
 /// <summary>
 /// Moves the <see cref="ChessPiece"/> that occupies this <see cref="Square"/> into another if it is a valid move,
 /// freeing up this <see cref="Square"/>.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="board"></param>
 /// <param name="capturedPiece"></param>
 /// <param name="isMock"></param>
 /// <returns></returns>
 public bool Move(int x, int y, Board board, out ChessPiece capturedPiece, bool isMock)
 {
     if (OccupiedBy is null)
     {
         capturedPiece = null;
         return(false);
     }
     else
     {
         return(OccupiedBy.Move(x, y, board, out capturedPiece, isMock));
     }
 }
Example #4
0
        /// <summary>
        /// Add pawn to the cell occupants
        /// </summary>
        /// <param name="pawn"></param>
        public void AddPawn(Pawn pawn)
        {
            if (CanAddPawn(pawn))
            {
                if (GlobalID == 97 || GlobalID == 98)
                {
                    pawn.IsAchieved = true;
                }

                KillOpponentPawns(pawn);
                OccupiedBy.Add(pawn);
                Update();
            }
        }
Example #5
0
        /// <summary>
        /// Kill the opponent pawns occupying the cell
        /// </summary>
        /// <param name="pawn"></param>
        private void KillOpponentPawns(Pawn pawn)
        {
            if (OccupiedBy == null || OccupiedBy.Count == 0)
            {
                return;
            }

            if (OccupiedBy[0].Owner.ID != pawn.Owner.ID)
            {
                foreach (Pawn p in OccupiedBy)
                {
                    p.Kill();
                }
                OccupiedBy.Clear();
            }
        }
Example #6
0
        /// <summary>
        /// Returns all squares that are protected by this square.
        /// </summary>
        /// <param name="board">The board in which search for the squares.</param>
        /// <returns>A <see cref="List{T}"/> with all the squares.</returns>
        public List <Square> FindProtectedSquares(Board board)
        {
            var result = new List <Square>();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (OccupiedBy.Protects(i, j, board))
                    {
                        result.Add(board[i, j]);
                    }
                }
            }

            return(result);
        }
Example #7
0
 /// <summary>
 /// Update cell status
 /// </summary>
 public override void Update()
 {
     base.Update();
     if (OccupiedBy != null)
     {
         int hw = (int)((Bound.R.Width - (OccupiedBy.Count() * Pawn.SIZE)) / (OccupiedBy.Count() + 1));
         int hh = (int)(Bound.R.Height - Pawn.SIZE) / 2;
         int vw = (int)(Bound.R.Width - Pawn.SIZE) / 2;
         int vh = (int)((Bound.R.Height - (OccupiedBy.Count() * Pawn.SIZE)) / (OccupiedBy.Count() + 1));
         if (IsHorizontal)
         {
             for (int i = 0; i < OccupiedBy.Count(); i++)
             {
                 OccupiedBy[i].Bound.SetRect(new System.Drawing.Rectangle(
                                                 Bound.R.Left + hw + (i * (Pawn.SIZE + hw)),
                                                 Bound.R.Top + hh,
                                                 Pawn.SIZE,
                                                 Pawn.SIZE
                                                 ));
             }
         }
         else
         {
             for (int i = 0; i < OccupiedBy.Count(); i++)
             {
                 OccupiedBy[i].Bound.SetRect(new System.Drawing.Rectangle(
                                                 Bound.R.Left + vw,
                                                 Bound.R.Top + vh + (i * (Pawn.SIZE + vh)),
                                                 Pawn.SIZE,
                                                 Pawn.SIZE
                                                 ));
             }
         }
     }
     // GameApp.Instance.Update();
 }
Example #8
0
 /// <inheritdoc/>
 public override string ToString()
 {
     return(OccupiedBy?.ToString() ?? "0");
 }
Example #9
0
 /// <summary>
 /// Checks if the pawn can move to cell
 /// </summary>
 /// <param name="pawn"></param>
 /// <returns></returns>
 public bool CanAddPawn(Pawn pawn)
 {
     return(OccupiedBy.Count() == 0 || OccupiedBy[0].Owner.ID == pawn.Owner.ID || !IsShield);
 }