Exemplo n.º 1
0
        /// <summary>
        /// Verifies that the unit can be placed in the specified position.
        /// </summary>
        /// <param name="unit">Unit being added to the squad.</param>
        /// <param name="position">Position within the squad to place the unit.</param>
        /// <returns>
        /// Whether or not the unit will be able to be added to the squad in this position.
        /// </returns>
        public bool IsPositionValid(CombatUnit unit, UnitPosition position)
        {
            bool twoRows    = ((unit.Space == CombatUnit.UnitSpace.OneByTwo) || (unit.Space == CombatUnit.UnitSpace.TwoByTwo));
            bool twoColumns = ((unit.Space == CombatUnit.UnitSpace.TwoByOne) || (unit.Space == CombatUnit.UnitSpace.TwoByTwo));

            // Verify that the position data is valid.
            if (position.Row < 0 ||
                (twoRows && (position.Row > 0)) ||
                (!twoRows && (position.Row > 1)))
            {
                return(false);
            }

            if (position.Column < 0 ||
                (twoColumns && (position.Column > 3)) ||
                (!twoColumns && (position.Column > 4)))
            {
                return(false);
            }

            // Verify that the proposed space is not occupied.

            /*if (occupied[position.Row, position.Column] ||
             *      (twoRows && occupied[position.Row + 1, position.Column]) ||
             *      (twoColumns && occupied[position.Row, position.Column + 1]) ||
             *      (twoRows && twoColumns && occupied[position.Row + 1, position.Column + 1]))
             *      return false;*/

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to add the specified unit to the squad.
        /// </summary>
        /// <param name="unit">Unit being added to the squad.</param>
        /// <param name="position">Position within the squad to place the unit.</param>
        /// <returns>
        /// Whether or not the unit was successfully added.
        /// </returns>
        public bool AddUnit(CombatUnit unit, UnitPosition position)
        {
            // Verify that the unit will fit within the squad.
            if ((Size + unit.UnitSize) >= MAX_UNITS_PER_SQUAD)
            {
                return(false);
            }

            if (!IsPositionValid(unit, position))
            {
                return(false);
            }

            UnitData unitData = new UnitData();

            unitData.Unit     = unit;        //(CombatUnit)Instantiate(unit);
            unitData.Position = position;

            Units.Add(unitData);

            return(true);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Verifies that the unit can be placed in the specified position.
		/// </summary>
		/// <param name="unit">Unit being added to the squad.</param>
		/// <param name="position">Position within the squad to place the unit.</param>
		/// <returns>
		/// Whether or not the unit will be able to be added to the squad in this position.
		/// </returns>
		public bool IsPositionValid(CombatUnit unit, UnitPosition position)
		{
			bool twoRows = ((unit.Space == CombatUnit.UnitSpace.OneByTwo) || (unit.Space == CombatUnit.UnitSpace.TwoByTwo));
			bool twoColumns = ((unit.Space == CombatUnit.UnitSpace.TwoByOne) || (unit.Space == CombatUnit.UnitSpace.TwoByTwo));

			// Verify that the position data is valid.
			if (position.Row < 0 ||
				(twoRows && (position.Row > 0)) ||
				(!twoRows && (position.Row > 1)))
				return false;

			if (position.Column < 0 ||
				(twoColumns && (position.Column > 3)) ||
				(!twoColumns && (position.Column > 4)))
				return false;

			// Verify that the proposed space is not occupied.
			/*if (occupied[position.Row, position.Column] ||
				(twoRows && occupied[position.Row + 1, position.Column]) ||
				(twoColumns && occupied[position.Row, position.Column + 1]) ||
				(twoRows && twoColumns && occupied[position.Row + 1, position.Column + 1]))
				return false;*/

			return true;
		}
Exemplo n.º 4
0
		/// <summary>
		/// Attempts to add the specified unit to the squad.
		/// </summary>
		/// <param name="unit">Unit being added to the squad.</param>
		/// <param name="position">Position within the squad to place the unit.</param>
		/// <returns>
		/// Whether or not the unit was successfully added.
		/// </returns>
		public bool AddUnit(CombatUnit unit, UnitPosition position)
		{
			// Verify that the unit will fit within the squad.
			if((Size + unit.UnitSize) >= MAX_UNITS_PER_SQUAD)
				return false;

			if (!IsPositionValid(unit, position))
				return false;

			UnitData unitData = new UnitData();
			unitData.Unit = unit;//(CombatUnit)Instantiate(unit);
			unitData.Position = position;

			Units.Add(unitData);
			
			return true;
		}