/// <summary> /// Constructor instantiates a new LivingUnit object given required parameters to describe the Unit. /// </summary> /// <remarks> /// Author: Rudy Ariaz /// </remarks> /// <param name="type">The type of Unit.</param> /// <param name="speciesComplexity">The complexity of the Unit's species.</param> /// <param name="senescence">The senescence value of the Unit.</param> /// <param name="foodRequirement">The food requirement of the Unit.</param> /// <param name="waterRequirement">The water requirement of the Unit.</param> /// <param name="gasRequirement">The gas requirement of the Unit.</param> /// <param name="inputGas">The input gas of the Unit.</param> /// <param name="outputGas">The output gas of the Unit.</param> /// <param name="idealTemperature">The ideal temperature of the Unit.</param> /// <param name="infectionResistance">The infection resistance of the Unit.</param> /// <param name="decompositionValue">The decomposition value of the Unit.</param> /// <param name="row">Optional: The row of the Unit (within the grid).</param> /// <param name="col">Optional: The column of the Unit (within the grid).</param> public LivingUnit(Enums.UnitType type, int speciesComplexity, int senescence, int foodRequirement, int waterRequirement, int gasRequirement, Enums.GasType inputGas, Enums.GasType outputGas, int idealTemperature, double infectionResistance, double decompositionValue, int row = -1, int col = -1) : base(type, decompositionValue, speciesComplexity, row, col) { // Set the senesence value Senescence = senescence; // Set the food requirement FoodRequirement = foodRequirement; // Set the water requirement WaterRequirement = waterRequirement; // Set the gas requirement GasRequirement = gasRequirement; // Set the input gas InputGas = inputGas; // Set the output gas OutputGas = outputGas; // Set the ideal temperature IdealTemperature = idealTemperature; // Set the infection resistance InfectionResistance = infectionResistance; // Update the max resistance if needed MaxResistance = Math.Max(MaxResistance, InfectionResistance); // Set the infection status to false Infected = false; // Initialize the number of generations left to be cured CuredGenerationsLeft = 0; }
/// <summary> /// Creates a new multicellular organism /// </summary> /// <param name="type"> The type of the Unit (Animal or Plant) </param> /// <param name="senescence"> The maximum age of the unit </param> /// <param name="foodRequirement"> The amount of food required per generation to survive </param> /// <param name="waterRequirement"> The amount of water required per generation to survive </param> /// <param name="gasRequirement"> The amount of gas converted </param> /// <param name="inputGas"> The type of gas that is taken in from the environment </param> /// <param name="outputGas"> The type of gas that is returned to the environment </param> /// <param name="idealTemperature"> The ideal temperature of this unit </param> /// <param name="infectionResistance"> The amount of infection resistance of this unit </param> /// <param name="decompositionValue"> The amount of food the unit returns to the environment after death </param> /// <param name="row"> The row of the grid the unit resides in </param> /// <param name="col"> The column of the grid the unit resides in </param> public Multicellular(Enums.UnitType type, int senescence, int foodRequirement, int waterRequirement, int gasRequirement, Enums.GasType inputGas, Enums.GasType outputGas, int idealTemperature, double infectionResistance, double decompositionValue, int row = -1, int col = -1) : base(type, 4, senescence, foodRequirement, waterRequirement, gasRequirement, inputGas, outputGas, idealTemperature, infectionResistance, decompositionValue, row, col) { }
/// <summary> /// Constructor used by child classes to create new instances of the clases. Uses /// base constructor of LivingUnit to assign all values. /// </summary> /// <param name="speciesComplexity">The species complexity of the Unit.</param> /// <param name="senescence">The senescence value of the Unit.</param> /// <param name="foodRequirement">The food requirement of the Unit.</param> /// <param name="waterRequirement">The water requirement of the Unit.</param> /// <param name="gasRequirement">The amount of gas requirement of the Unit.</param> /// <param name="inputGas">The input gas of the Unit.</param> /// <param name="outputGas">The output gas of the Unit.</param> /// <param name="idealTemperature">The ideal temperature of the Unit.</param> /// <param name="infectionResistance">The infection resistance of the Unit.</param> /// <param name="decompositionValue">The decomposition value of the Unit.</param> /// <param name="row">Optional: The row of the Unit (within the grid).</param> /// <param name="col">Optional: The column of the Unit (within the grid).</param> public MergeableUnit(Enums.UnitType type, int speciesComplexity, int senescence, int foodRequirement, int waterRequirement, int gasRequirement, Enums.GasType inputGas, Enums.GasType outputGas, int idealTemperature, double infectionResistance, double decompositionValue, int row = -1, int col = -1) : base(type, speciesComplexity: 2, senescence: 16, foodRequirement: 1, waterRequirement: 1, gasRequirement: 1, inputGas: Enums.GasType.Oxygen, outputGas: Enums.GasType.CarbonDioxide, idealTemperature: 30, infectionResistance: 3, decompositionValue: 0.5, row: row, col: col) { }
/// <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)); }
public UnitType(Enums.UnitType type) { // all units GlobalVariables.unitID++; unitID = GlobalVariables.unitID; unitType = type; displayAvailableCells = false; canAct = false; canMove = false; rally = false; stamina = 100; balance = 100; lightAttackRange = 1; heavyAttckRange = 1; // certain unit types switch (type) { // CHARACTERS case Enums.UnitType.Hunter: name = "Hunter"; // stats movementPoints = 4; hitPoints = 16; hitPointMax = 16; balRecovery = 0; staRecovery = 0; accuracy = 11; // 6 critical = 10; speed = 1; defense = 3; lowDamage = 1; highDamage = 6; // 6 break; case Enums.UnitType.Gatherer: name = "Gatherer"; // stats movementPoints = 5; hitPoints = 15; hitPointMax = 15; balRecovery = 2; staRecovery = 2; accuracy = 14; // 4 critical = 0; speed = 5; defense = 8; lowDamage = 1; highDamage = 4; break; case Enums.UnitType.Bandit: name = "Bandit"; // stats movementPoints = 5; hitPoints = 14; hitPointMax = 14; balRecovery = 5; staRecovery = 0; accuracy = 8; // 3 critical = 5; speed = 4; defense = 5; lowDamage = 1; highDamage = 5; break; case Enums.UnitType.Nomad: name = "Nomad"; // stats movementPoints = 4; hitPoints = 18; hitPointMax = 18; balRecovery = 0; staRecovery = 5; accuracy = 7; // 2 critical = 7; speed = 0; defense = 4; lowDamage = 1; highDamage = 6; break; // MONSTERS case Enums.UnitType.BarbedToad: name = "Barbed Toad"; // stats movementPoints = 3; hitPoints = 4; hitPointMax = 4; balRecovery = 0; staRecovery = 0; accuracy = 8; // 3 critical = 5; speed = 10; // 0 defense = 1; lowDamage = 1; highDamage = 2; // 2 // traits passThroughGrass = true; passThroughGrassRough = true; passThroughWaterShallow = true; passThroughWaterDeep = true; break; case Enums.UnitType.SaberToothWolf: name = "Saber Tooth Wolf"; // stats movementPoints = 5; hitPoints = 8; hitPointMax = 8; balRecovery = 10; staRecovery = 10; accuracy = 6; // 1 critical = 2; // 2 speed = 14; // 4 defense = 5; lowDamage = 1; highDamage = 5; // 5 break; } }
/// <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); }
/// <summary> /// Create a unit of the given type with the given parameters as its property values /// Used for loading Units from file /// </summary> /// <param name="type">The type of unit to create</param> /// <param name="parameters">The values of the unit's properties</param> /// <returns></returns> public static Unit CreateUnit(Enums.UnitType type, string[] parameters) { return(modelUnits.ElementAtOrDefault((int)type)?.Create(parameters)); }
/// <summary> /// Create a unit of the given type at the given location /// </summary> /// <param name="type">The type of unit to create</param> /// <param name="row">The row index</param> /// <param name="col">The column index</param> /// <returns>The newly created object of the given type</returns> public static Unit CreateUnit(Enums.UnitType type, int row, int col) { return(modelUnits.ElementAtOrDefault((int)type)?.Create(row, col)); }
/// <summary> /// Event handler for mouse clicking that processes the user's actions /// </summary> /// <remarks> Tiffanie </remarks> private void GameForm_MouseDown(object sender, MouseEventArgs e) { // Only attempt to interact with the grid if toolbar selection was made if (toolbarSelection != Enums.UnitType.None || eraseToolSelected) { // Loop through all rows in the grid to see if the user clicked in this one for (int j = 0; j < grid.GetLength(GridHelper.ROW); j++) { // Loop through all columns in the grid to see if the user clicked in this one for (int k = 0; k < grid.GetLength(GridHelper.COLUMN); k++) { // Check if the user clicked the current grid cell to process an action here if (grid[j, k].Contains(e.Location)) { //check that the game is not paused if (!isPaused) { //indicate that the game must be paused MessageBox.Show("Pause game to interact with board"); continue; } // CASE 1: user is trying to erase a unit at the clicked location if (manager.GetUnit(j, k) != null && eraseToolSelected) { manager.KillUnit(j, k); } // CASE 2: user is trying to create a new unit else { manager.CreateUnit(j, k, toolbarSelection); } return; } } } } // Otherwise, check for a selection in the toolbar for (int i = 0; i < TOOLBAR_SIZE; i++) { if (toolbar[i].Contains(e.Location)) { // Only hide the cursor if it is currently visible (not already hidden due to a previous unit choice) // since the number of calls to Hide() and Show() must be balanced (calls are counted) if (toolbarSelection == Enums.UnitType.None) { Cursor.Hide(); } // Save the new Unit that the user selected toolbarSelection = (Enums.UnitType)i; // Record if the user selected the erase tool (used for error checking) if (toolbarSelection == Enums.UnitType.None) { eraseToolSelected = true; } else { eraseToolSelected = false; } // Store the current location for a new 'colored' cursor imageDragBox.Location = e.Location; // Stop processing possible mouse down cases return; } } // Show the cursor if it is currently hidden (user has something currently selected) if (toolbarSelection != Enums.UnitType.None || eraseToolSelected) { Cursor.Show(); } // User did not click grid nor a unit in toolbar toolbarSelection = Enums.UnitType.None; eraseToolSelected = false; // Redraw form graphics Refresh(); }