Beispiel #1
0
 /// <summary>
 /// Merges the current Cell with the 3 other Cells in a 2x2 block with this Cell as the top left
 /// </summary>
 /// <param name="grid"> The grid of Units currently in the simulation </param>
 /// <param name="row"> The row of the grid that this Cell resides in </param>
 /// <param name="col"> The column of the grid that this Cell resides in </param>
 protected override void Merge(Unit[,] grid, Environment gameEnv)
 {
     KillMergedUnits(grid, gameEnv);
     // Replace the current Cell with a newly created Colony
     grid[Location.r, Location.c] =
         UnitFactory.CreateUnit(Enums.UnitType.Colony, Location.r, Location.c);
 }
Beispiel #2
0
 /// <summary>
 /// Merge a Colony with neighboring Colonies into a Multicellular organism.
 /// Precondition: the Colony should be merged (that is, it is the top left block
 /// in a 2x2 square of neighboring colonies).
 /// </summary>
 /// <remarks>
 /// Author: Rudy Ariaz
 /// </remarks>
 /// <param name="grid">The grid in which the Colony is.</param>
 /// <param name="gameEnv">The Environment of the Colony.</param>
 protected override void Merge(Unit[,] grid, Environment gameEnv)
 {
     // Kill the Colonies that should be merged
     KillMergedUnits(grid, gameEnv);
     // Replace the current Colony with a newly created Plant or Animal, depending
     // on the environmental conditions
     grid[Location.r, Location.c] =
         UnitFactory.CreateUnit(GetMergeType(gameEnv), Location.r, Location.c);
 }
Beispiel #3
0
        /// <summary>
        /// Loads a single Unit represented in a string of parameters.
        /// </summary>
        /// <remarks>
        /// Author: Nicole Beri
        /// </remarks>
        /// <param name="unitString">A string representation of a Unit, according to the format
        /// described in UnitFileFormat.</param>
        /// <returns>The Unit represented by "unitString", or null if the description is not valid.</returns>
        private static Unit LoadUnit(string unitString)
        {
            // The string representation is semicolon-separated, so split the representation into
            // the various parameters
            string[] unitArray = unitString.Split(';');

            // Stores the unit type
            int u;

            // Get the unit type
            int.TryParse(unitArray[UnitFileFormat.UNIT_TYPE], out u);
            // Cast the unit type from integer to unit ytpe
            Enums.UnitType unitType = (Enums.UnitType)u;
            // Use the UnitFactory to create the Unit with the given parameters
            return(UnitFactory.CreateUnit(unitType, unitArray));
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new unit of a given type at the given location using unit factory
 /// </summary>
 /// <param name="row"> the row index of the unit's location </param>
 /// <param name="col"> the column index of the unit's location </param>
 /// <param name="UnitType"> the type of unit </param>
 public void CreateUnit(int row, int col, Enums.UnitType UnitType)
 {
     currentState.UnitGrid[row, col] = UnitFactory.CreateUnit(UnitType, row, col);
 }