Computer Science This is for a model-view -controller framework in C# Question 2 (Marks: 40) Class Structure
Question:
Computer Science
This is for a model-view -controller framework in C#
Question 2 (Marks: 40) Class Structure Q.2.1 Createan abstract base class called Tile. Tile is the base class for all in-game objects that have positions on the map. It has the following protected member variables, as well as public accessors for these variables: X Y A public enum called TileType that defines the type of tile: Hero, Enemy, Gold or Weapon. Thiswill be used by other classes to determine what kind of tiles to create. You should create a relevant constructor that receives and sets initial values for these variables. This class is a struct-like class, and only defines fields (attributes), and no methods besides the constructor. After this, createthe Obstacle subclass. It contains nothing extra, and its constructor simply calls the base class's constructor with X and Y parameters. The obstacle class only exists currently to border our map with Obstacle tiles that no Character can move past (Hero or Swamp Creature). Createanother class called EmptyTile, identical to Obstacle, that merely exists to denote an empty tile. (5) Q.2.2 Createanother abstract base class called Character that inherits from Tile. This is your true base class for your Hero and Swamp Creature classes. It has the following protected member variables, as well as public accessors for necessary variables: HP Max HP Damage A Tile array for a Character's vision (the tiles that are to the north, south, east and west of thecharacter on the map during its turn), which is used to check for valid movement. A public enum for Movement which contains definitions for: o No movemento Up o Down o Lefto Right (10) Q.2.3 The Character class should contain the following methods, most of which define generic implementations for all characters to use: A constructor that receives X and Y positions and a symbol and delegates the setting of thosevariables to the Tile class via a constructor initialiser. Public virtual void Attack(Character target): Attacks a target and decreases its health by theattacking character's damage. This is declared as virtual for later overriding by specific enemy types. Public bool IsDead(): Checks if the character is dead. Public virtual bool CheckRange(Character target): Checks if a target is in range of a character(barehanded range is always 1, but this will be extended with weapon types later). It determines distance via the DistanceTo() method and returns true or false. Private int DistanceTo(target) - used by CheckRange(): Determines the absolute distance(number of spaces needed to move - e.g., diagonal is one up + one across = 2) between a character and its target. Public void Move(MovementEnum move): Edits a unit's X and Y values to move itup/down/left/right based on the identifier from the enum. Public abstract MovementEnum ReturnMove(MovementEnum move = 0) - this will be definedby the Character subclasses. The method returns a direction of movement based on how the character should move, based on the validity of that move against a Character's vision array. Public abstract override ToString(): This is defined in the Character subclasses and overridesthe traditional Object ToString() method. (10) Q.2.4 Create the abstract Enemy class which inherits from Character. It contains a single protected member variable that is used internally by subclasses: A random object used for randomising numbers It also contains: A constructor that receives X and Y positions, an enemy's damage and it is starting HP (andthus also max HP) and its symbol. It delegates its X and Y position to the Character subclass via a constructor initialiser. It then sets all the relevant member variables. An overridden ToString method that, using the enemy's class, outputs a string that looks asfollows: EnemyClassName at [X, Y] (Amount DMG) This will be used by the Enemy subclasses. (5) Q.2.5. Create the concrete Swamp Creature class which inherits from Enemy. It contains: A constructor that receives only an X and Y position, but delegates its variable setting mostlyto the Enemy class along the following parameters: o Swamp Creatures have 10 HPo Swamp Creatures do 1 damage An overridden ReturnMove() method: This method does not use the optional movement parameter. Instead, it randoms a direction for the Swamp Creature to move in and checks that movement against the Swamp Creature's vision array. If something is in the way (a Hero or a Wall for now), the random position should be rerolled. When a valid position is chosen, it is returned from the method. (5) Q.2.6. Create the concrete Hero subclass, which inherits from Character. It should have the following methods: A constructor that receives an X and Y position and HP, but calls the Character constructorinitialiser, passing it the X and Y position. It should then set the HP and max HP of the hero based on the parameter. Additionally, a Hero's damage is always 2. An overridden ReturnMove() method: This method receives a movement indicator based on adirectional button press (either on the Windows Form or via the keyboard). It then checks that potential movement (up/down/left/right) against the vision array and returns that same number if it is valid. If it is not valid, it returns a MovementEnum.None, which signals to the calling method that a movement should not be made. An overridden ToString() method: This returns the formatted Player Stats as shown below: Player Stats: HP: HP/Max HP Damage: 2 [X, Y] (5)
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall