Milestone 1 Description - GUC MET

German University in Cairo
Media Engineering and Technology
Prof. Dr. Slim Abdennadher
Computer Programming Lab, Spring 2017
Harry Potter: Return of the Triwizard Tournament
Milestone 1
Deadline: Sat 4.3.2017 @23:59
This milestone is an exercise on the concepts of Object Oriented Programming (OOP).
The following sections describe the requirements of the milestone.
By the end of this milestone, you should have:
• A packaging hierarchy for your code
• An initial implementation for all the needed data structures
• Basic data loading capabilities from a csv file
1
Build the Project Hierarchy
1.1
Add the packages
Create a new Java project and build the following hierarchy of packages:
1. harrypotter.model.magic
2. harrypotter.model.world
3. harrypotter.model.character
4. harrypotter.model.tournament
5. harrypotter.controller
6. harrypotter.view
7. harrypotter.exceptions
8. harrypotter.tests
Afterwards, proceed by implementing the following classes. You are allowed to add more classes, attributes and methods. However, you must use the same names for the provided attributes and methods.
1.2
Naming and privacy conventions
Please note that all your class attributes must be private and all methods should be public unless
otherwise stated. You should implement the appropriate setters and getters conforming with the access
constraints. Throughout the whole milestone, if a variable is said to be READ then we are allowed to get
its value. If the variable is said to be WRITE then we are allowed to change its value. Please note that
getters and setters should match the Java naming conventions. If the instance variable is of type boolean,
1
the getter method name starts by is followed by the exact name of the instance variable. Otherwise,
the method name starts by the verb (get or set) followed by the exact name of the instance variable;
the first letter of the instance variable should be capitalized. Please note that the method names are
case sensitive.
Example 1 You want a getter for an instance variable called milkCount → Method name = getMilkCount()
MAGIC COMPONENTS
2
Build the (Collectible) Class
Name : Collectible
Package : harrypotter.model.magic
Type : Class
Description : A class representing an item that can be collected by the champions. No objects of type
Collectible can be instantiated.
2.1
Attributes
All the class attributes are READ ONLY.
1. String name: The name of the collectible.
2.2
Constructors
1. public Collectible(String name): Constructor that initializes a Collectible object.
3
Build the (Potion) Class
Name : Potion
Package : harrypotter.model.magic
Type : Class
Description : A subclass of Collectible representing a potion that can be used by wizards to recover
their ip.
3.1
Attributes
All the class attributes are READ ONLY unless otherwise specified.
1. int amount: The value by which the potion recovers the champion’s current ip.
3.2
Constructors
1. public Potion(String name, int amount): Constructor that initializes a Potion object. This
constructor should utilize the Collectible constructor.
2
4
Build the (Spell) Class
Name : Spell
Package : harrypotter.model.magic
Type : Class
Description : A class representing a spell that a champion can cast during the tournament. No objects
of type Spell can be instantiated.
4.1
Attributes
All the class attributes are READ ONLY unless otherwise specified.
1. String name: The spell’s name.
2. int cost: The ip cost needed for casting the spell.
3. int defaultCooldown: The amount of turns the champion needs to wait before being able to cast
this specific spell again. It is only set once to the corresponding value read from the csv file.
4. int coolDown: The number of turns left for this spell to finish its cooldown. Initially, it is set to
0. This attribute is READ and WRITE.
4.2
Constructors
1. public Spell(String name, int cost, int defaultCoolDown): Constructor that initializes a
Spell object.
4.3
Subclasses
There are 3 different types of spells available in the game. Each spell type is modelled as a subclass of
the Spell class. Each spell type should be implemented in a separate class within the same package as
the Spell class. The constructor of each of the subclasses should have its own constructor that utilizes
the Spell constructor. Carefully consider the design of each constructor.
1. RelocatingSpell: A spell that relocates another player or obstacle within a given range. The
class attribute int range is READ ONLY. The range represents the maximum number of cells
that this spell can move objects to relative to their initial location.
2. HealingSpell: A spell that the champion casts to recover his hp by a specific amount. The
class attribute int healingAmount is READ ONLY and represents the amount that this spell will
restore to the champion’s hp.
3. DamagingSpell: A spell that damages merpersons, physical obstacles and other players by the
given damage amount. The class attribute int damageAmount is READ ONLY. The damageAmount
represents the value that this spell will remove from the target’s hp.
WORLD
5
Direction
Name : Direction
3
Package : harrypotter.model.world
Type : Enum
Description : An enum representing the different moving directions. Possible values are: FORWARD,
BACKWARD, RIGHT and LEFT.
6
Obstacle
Name : Obstacle
Package : harrypotter.model.world
Type : Class
Description : A superclass representing an obstacle within the map that is preventing the contestants
from passing through. No objects of type Obstacle can be instantiated.
6.1
Attributes
All the class attributes are READ ONLY.
1. int hp: The health points of the obstacle itself. It represents how much damage the obstacle can
withstand.
There are 2 different obstacle types available in the game. Each type is modelled as a subclass of the
(Obstacle) class. Each obstacle should be implemented in a separate class within the same package
as the Obstacle class. The constructors of the subclasses should make use of the constructor of the
Obstacle class and take the corresponding attributes as inputs.
The different obstacle types are:
1. Physical Obstacle: Represents a physical obstacle blocking the champion’s path. (Class name:
PhysicalObstacle).
2. Merperson: Represents a merperson that blocks the champion’s path and inflicts damage on him
upon being in an adjacent cell. (Class name: Merperson). The Merperson has one additional
READ ONLY attribute representing the damage amount that can be inflicted by the merperson
on the champions: int damage.
7
Cell
Name : Cell
Package : harrypotter.model.world
Type : Class
Description : A superclass representing a single cell in the map that any character can pass through.
No objects of type Cell can be instantiated.
There are 7 different cell types available in the game. Each cell type is modelled as a subclass of the
(Cell) class. Each cell should be implemented in a separate class within the same package as the Cell
class. Carefully consider the design of the constructors of each subclass.
The different cell types are:
1. Empty Cell: Empty cells contain nothing. The champions just passes through them and move
to the next cell. (Class name: EmptyCell)
4
2. Champion Cell: Champion cells are ones that currently have a champion positioned in them.
(Class name: ChampionCell). The ChampionCell has one READ ONLY attribute representing
the champion within the cell: Champion champ. The constructor of the ChampionCell should take
the champ as input.
3. Collectible Cell: Collectible cells have collectible items of type Collectible in them. (Class
name: CollectibleCell). The CollectibleCell has one READ ONLY attribute representing
the collectible within the cell: Collectible collectible. The constructor of the CollectibleCell
should take the collectible as input.
4. Cup Cell: The cup cell is the one containing the triwizard cup in the third task. (Class name:
CupCell)
5. Obstacle Cell: Obstacle cells are the ones containing the obstacles that the champions may encounter during any task. Namely, the physical obstacles in the first and third task and merpersons
in the second task. (Class name: ObstacleCell). The ObstacleCell has one READ ONLY
attribute representing the obstacle in the cell: Obstacle obstacle.
6. Treasure Cell: Treasure cells are the ones containing the treasure belonging to each champion
in the second task. (Class name: TreasureCell). The TreasureCell has one READ ONLY
attribute representing the champion who owns the treasure within the cell: Champion owner. The
constructor of the TreasureCell should take the owner as input.
7. Wall Cell: Wall cells represent the walls of the maze that the champions cannot go through in
the third task. (Class name: WallCell)
CHARACTERS
8
Champion Interface
Name : Champion
Package : harrypotter.model.character
Type : Interface
Description : Interface containing the methods available to wizards who participate in the tournament
i.e. champions.
8.1
Methods
1. void useTrait(): Method for activating the special traits available to champions of each house
during the tasks.
9
Build the (Wizard) Class
Name : Wizard
Package : harrypotter.model.character
Type : Class
Description : A class representing a wizard character. No objects of type Wizard can be instantiated.
5
9.1
Attributes
All the class attributes are READ and WRITE unless otherwise specified.
1. String name: The wizard’s name.
2. int defaultHp: The default health points belonging to this wizard. This is the upper bound of
wizard’s hp.
3. int defaultIp: The default intelligence points belonging to this wizard.
4. int hp: The actual health points the wizard currently has. Initially this value is set to the
defaultHP.
5. int ip: The actual intelligence points the wizard currently has available to cast spells. Initially
this value is set to the defaultIp.
6. ArrayList<Spell> spells: The list of the wizard’s currently chosen spells. This attribute is
READ ONLY.
7. ArrayList<Collectible> inventory: The list of the wizard’s belongings that he gathers during
the tournament. This attribute is READ ONLY.
8. Point location: A point representing the wizard’s location in the map. The Point here is the
Java built-in Point in the AWT package.
9. int traitCooldown: The amount of turns the champion needs to wait before activating his house
trait again.
9.2
Constructors
1. public Wizard(String name): Constructor that initializes a Wizard object.
9.3
Subclasses
There are 4 different types of wizards available in the game. Each wizard type is modelled as a subclass of
the Wizard class. Each wizard type should be implemented in a separate class within the same package
as the Wizard class. The four subclasses all represent participants of the triwizard tournament and
thus implement the Champion interface. Each of the subclasses representing the different wizard houses
should have its own constructor that utilizes the Wizard constructor. Carefully consider the design of
the constructor of each subclass.
The following table gives different class names with their respective initial values.
Class name
Default HP
Default IP
GryffindorWizard
HufflepuffWizard
RavenclawWizard
SlytherinWizard
900
1000
750
850
500
450
700
550
The default values of the remaining attributes should be as follows:
• hp: defaultHP
• ip: defaultIP
• traitCooldown: 0
• inventory: empty
• spells: empty
6
All wizard types only have the attributes they inherit from the Wizard class. SlytherinWizards have
an additional READ and WRITE class attribute Direction traitDirection which represents the
direction of the move resulting from activating their trait.
TOURNAMENT
10
Build the (Task) Class
Name : Task
Package : harrypotter.model.tournament
Type : Class
Description : A class representing a tournament task. No objects of type Task can be instantiated.
10.1
Attributes
All the class attributes are READ ONLY unless otherwise specified.
1. ArrayList<Champion> champions: Represents the champions competing in this task.
2. Champion currentChamp: Represents the champion whose turn it currently is in this task. This
attribute is READ and WRITE.
3. Cell[][] map: A 2D array representing the map that the task is taking place in.
4. int allowedMoves: Indicates the number of moves allowed for the currentchamp in the current
turn. Initially it is set to 1. This attribute is READ and WRITE.
5. boolean traitActivated: Indicates whether the currentchamp’s trait is activated in the current
turn or not. Initially it is set to false. This attribute is READ and WRITE.
6. ArrayList<Potion> potions: List of potions available to be distributed in the maps of the three
tasks. The list is loaded from the provided CSV file in the beginning of the game.
10.2
Constructors
1. public Task(ArrayList<Champion> champions): Constructor that initializes a Task object.
The map should be initialized as a 10x10 array of cells. In this constructor, the correct method
should be invoked to load the CSV file containing the potions.
10.3
Subclasses
The tournament represented in the game consists of 3 different tasks. Each task is modelled as a subclass
of the Task class. Each task should be implemented in a separate class within the same package as the
Task class. Each of the subclasses representing the different tournament tasks should have its own
constructor that utilizes the Task constructor. Carefully consider the design of each constructor, where
the constructor of the FirstTask and SecondTask randomly shuffles the champions list to determine
the starting order. The constructor of all three subclasses should eventually generate the map by calling
the appropriate method.
1. FirstTask: This represents the first task.
2. SecondTask: This represents the second task.
3. ThirdTask: This represents the third task. This class should have the implementation of the
readMap(String filePath) method.
7
10.4
Methods
1. void generateMap(): This method generates the map according to the requirements needed for
each task. The map is a 10x10 array of cells where no cell can contain more than one item i.e.
each cell has exactly one type. In the first and second task the champions should be placed in
the four corners of the map. Their placement order should be as follows: the first champion in the
champions array list should be placed in the bottom left corner (0,9), the next champion in the
bottom right corner (9,9), the one after in the top right corner(9,0) and the final one in the top
left corner (0,0). In the third task the champion’s location is read from the csv files. In any of
the three maps you should only place the champions that are currently still participating in the
tournament and haven’t been excluded in earlier tasks. Each map should contain 10 randomly
chosen potions from array list potions. Make sure that no potions are removed from the original
array list while placing them in the map. The potions should be randomly placed in the map. The
method behaves for each task as follows:
(a) FirstTask: 40 ObstacleCells should also be randomly distributed over the map. These
cells will only contain PhysicalObstacles. The hp of the PhysicalObstacles within the
cells should be randomly chosen within the range of 200 and 300 (inclusive). You should
ensure that cell (4,4) remains empty as it should hypothetically contain the 4 eggs belonging
to the four champions i.e. the champion that reaches it should complete the task.
(b) SecondTask: Each of the champions’ treasures should be randomly placed. 40 ObstacleCells
should also be randomly distributed over the map. These cells will only contain Merpersons.
The hp of the Merpersons within the cells should be randomly chosen within the range of
200 and 300 (inclusive) and their damage should be randomly chosen within the range of 100
and 300 (inclusive).
(c) ThirdTask: The map for this task should be read from the provided task3map.csv file using
the readMap method in the ThirdTask class. In case of reading a PhysicalObstacle from
the map its hp should be randomly generated from the range of 200 and 300 (inclusive).
2. private void loadPotions(String filePath): Reads the CSV file with filePath and loads
the potions into the potions ArrayList.
11
Build the (Tournament) Class
Name : Tournament
Package : harrypotter.model.tournament
Type : Class
Description : Class representing the whole game play i.e. the Triwizard Tournament.
11.1
Attributes
All the class attributes are READ ONLY.
1. ArrayList<Champion> champions: Represents the champions competing in the tournament.
2. ArrayList<Spell> spells: List of spells available for champions to choose from throughout the
whole tournament. The list is loaded from the provided CSV file in the beginning of the game.
3. FirstTask firstTask: The first task of the tournament.
4. SecondTask secondTask: The second task of the tournament.
5. ThirdTask thirdTask: The third task of the tournament.
8
11.2
Constructors
1. public Tournament(): Empty constructor that initializes a Tournament object and initializes the
champions array list. In this constructor, the correct methods should be invoked to load the CSV
files containing the spells.
11.3
Methods
1. private void loadSpells(String filePath): Reads the CSV file with filePath and loads the
spells into the spells ArrayList.
11.4
Description of CSV files format
1. You should add throws Exception to the header of any constructor or method that reads from a
csv file to compensate for any exceptions that could arise.
2. Spells
(a) The spells are found in a file titled Spells.csv.
(b) Each line represents a spell.
(c) The data has no header, i.e. the first line represents the first spell.
(d) The parameters are separated by a comma (,).
(e) The line represents the spell’s data as follows: Type, Name, Cost, Value, Default
Cooldown.
i. Type: DMG for damaging spells, HEL for healing spells and REL for relocating spells.
ii. Name
iii. Cost
iv. Value: This corresponds to the damageAmount, healingAmount and range in case of
damaging, healing and relocating spells respectively.
v. Default Cooldown
Example 2 An entry for a Spell will look like:
DMG,Expelliarmus,10,10,10
3. Potions
(a) The potions are found in a file titled Potions.csv.
(b) Each line represents a potion.
(c) The data has no header, i.e. the first line represents the first potion.
(d) The parameters are separated by a comma (,).
(e) The line represents the potion’s data as follows: Name, Amount.
Example 3 An entry for an Potion will look like:
LiquidLuck,100
4. Task3 Map
(a) The map are found in a file titled task3map.csv.
(b) Each line represents a row in the map.
(c) The data has no header, i.e. the whole file represents the whole map
(d) Each entry in the file represents one cell of the 10x10 map grid.
(e) The map cells are separated by a comma (,).
(f) The different cell types are represented in the csv as follows:
• 0: Empty Cell.
9
• 1-4: The champions in their given order from 1 till 4.
• 5: Wall.
• 6: Obstacle.
• 7: Cup.
Example 4 An row in the Map will look like:
5,0,0,4,6
This translates to:
Wall, Empty Cell, Empty Cell, Player No. 4, Obstacle.
10