JAVA
A real card
Classes: Tile, Item, Obstacle, Map, Entity, Player,GameMaster.
The Tile interface:
A tile interface is a field of the map. Each tile must implementfour functions implement:- getName: Returns the name of the field.- getSymbol: Returns the symbol to dress on the map.- isLootable: True if the field can be included.- isCollidable: True if the player collides with the object.
The Item and Obstacle classes:
The Item and Obstacle classes are to implement the Tileinterface. Both have a name and an icon. Each tile has twoconstructors. The first constructor takes only a name and sets thesymbol to the first letter of the name, the second takes a name anda symbol. A field can either be pickable or the player collideswith it. If the player collides the field cannot be picked up.
The Map class:
Map is a 2-dimensional array consisting of Tile objects. Toplace or retrieve them we need the functions placeMapItem(...) andretrieveItem(...) .
Write a function checkCoordinates(...) ,which later checks if the coordinates of the player are inside themap during a move.are inside the map. The full score is only given if this functionis always used and there is no code duplicate.
Last but not least, the Map class shouldoutput the map on the command line, as shown in the sample outputbelow. Tile objects are represented by their symbols, the player byan "A". by an "A". Implement a printMap() function for this.
The abstract class Entity:
You need entities. For this you should first create the abstractclass Entity, which specifies basic functions that each entity musthave.
The entities store their position and require get methods andset methods which make the X and Y coordinates of each entityaccessible.
The Player class:
The Player class extends the abstract Entity class. A player hasa fixed-size inventory. The functions of Player are implemented asfollows: Each player should be able to pick up items withtakeItem(), take items out of the inventory with putItemDown(...)and print the inventory with the full names of the objects on theconsole with printInventory(). the full names of the items on theconsole.
- takeItem() searches for empty space in inventory, if found,saves passed Item- putItemDown(...) searches for passed name in inventory, if found,returns the Tile object back
The remaining functions work as described in the description ofentities. It starts at the coordinates (0|0).
The GameMaster class:To control the actions of the player we write a GameMaster. Thesize of the game field should be passed as a command line argument.Randomly place Tile objects.
After setting up the playing field, we now move on to the"runtime".In the function runtime() you have to convert your or our runtimealgorithm from sheet 2 into the format used here. format used herewith object orientation. However, the player does not catch pocketmonsters but picks up items. However, you do not have to save therun. It is sufficient if you output the total number of steps atthe end.
Sample output:
PS:
PLEASE CHECK YOUR ANSWER BEFORE REPLYING TO MY QUESTIONAND I WILL BE THANKFULL IF YOU EXPLAIN THE CODE WITH COMMENTS!!!!!!!!
You have chosen a 10 x 10 map. Study the map and choose your path wisely. | P I I 1 I I # IR I I # I I
JAVA A real card Classes: Tile, Item, Obstacle, Map, Entity, Player, GameMaster. The Tile interface: A tile interface is
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am