Part 1 – A Grid of Tiles (25 Points)

Part 1 – A Grid of Tiles (25 Points)

The first part of this game is around constructing the game world! At a high level, this task requires you to implement two classes, the Tile class and the Grid class. A Tile represents a single cell in the grid and the Grid represents a collection of tiles arranged in the x and y grid coordinate system. The Grid Coordinate system is explained in the Assignment Reference Material!

Remember that all class data member variables should be private and all class method members should be public (unless otherwise specified).

Tile Class (10 Points):

You must implement the Tile class according to the following functionality requirements:

The tile class should store at least the following 4 data members:
An integer representing the tiles x position in the grid.
An integer representing the tiles y position in the grid.
A boolean representing if the tile is visible or not visible.
A collection of Strings that holds a description of the current items that are on this tile.
You could use an ArrayList for this or another collection type. As long as it has the ability to hold multiple Strings and the ability to easily add and remove Strings from the collection.
The Tile constructor should take two integers as arguments, the first being its x coordinate and the second being its y coordinate.
You should store the x and y coordinates passed into the constructor in the respective class data members.
The tile should be visible by default.
You should also initialise your collection of String data member to an empty collection.
Implement a method called getXPosition that simply returns the x coordinate of this tile.
Implement a method called getYPosition that simply returns the y coordinate of this tile.
Implement a method called getVisibility that simply returns if the tile is visible (true) or not visible (false).
Implement a method called setVisibility that takes a boolean as a parameter and updates the data member responsible for holding whether the tile is visible or not.
Implement a method called addItemToTile which will take a single String as an argument and will add it to the data member collection of item Strings only if that String is not already in the collection.
Make sure not to allow the addition of the same String multiple times.
An example of items that can be added to the tile include “Player”, “Exit” and “Obstacle”. It is possible for both the “Player” and “Exit” items to be on the same tile which is why we need to use some collection of items.
Your method should accept any item String. For example: “Unknown Item” or “Obstacle” or “Weapon” etc.
Implement a method called removeItemFromTile that will take a single String as an argument and will remove it from the collection if a matching string exists in that collection.
Implement a method called isItemOnTile that will take a single String as an argument and return true if that item exists on the tile and false if it doesn’t.
Implement a toString method which should return a String representation of the item that is currently on the tile. The specific strings that should be returned if your collection of item Strings matches is detailed below:
Regardless of what items are on the tile, if your tile is not visible, you should return the HIDDEN_SYMBOL.
If your tile is visible then:
If a “Player” and “Exit” item exists on this tile then you should return the PLAYER_ON_EXIT_TILE_SYMBOL.
If a “Player” item exists on this tile (and not an “Exit” item) then you should return the PLAYER_TILE_SYMBOL.
If an “Exit” item exists on this tile then you should return the EXIT_TILE_SYMBOL.
If an “Obstacle” item exists on this tile then you should return the OBSTACLE_TILE_SYMBOL.
If an item exists on this tile that is not any of the items described above, then you should return the UNKNOWN_ITEM_SYMBOL.
If no items exists on this tile then you should return the EMPTY_TILE_SYMBOL.
The Grid Class (7 Points):

You must implement the Grid class according to the below functionality requirements:

The Grid class should store at least the following 3 data members:
An integer representing the width of the grid.
An integer representing the height of the grid.
Some collection of Tile objects that make up this grid.
The constructor should take two integers as arguments, the first being the width of the grid and the second being the height of the grid.
You should store these width and height values in the corresponding data members.
You should create and store all Tile objects that are needed to make up this grid. The tile’s x and y positions should match the format described in the 2D Coordinate System explanation at the top of this slide.
Implement both a getGridWidth and getGridHeight functions that simply returns the grids width and height respectively.
Implement a getTileAtPosition function which takes two arguments, the first being the x coordinate of the tile you want to retrieve and the second being the y coordinate of the tile you want to receive. It should then return the Tile object that is located at that x and y position.
If the x and y positions are not valid, i.e. no such tile exists at that given x and y position, you should return null.
Implement a getPlayerTile function which takes no arguments and returns the Tile object that currently contains the “Player” item. If there is no “Player” item in the grid, you should return null.
The printGrid() method (8 Points):

The printGrid function should be implemented in the Grid class. The below description should be matched with the coordinate system described in the reference material, as in the tile at position x==0 and y==0 should be positioned in the top left and so on (refer back to that description so that you arrange your tiles correctly).

For a grid with width 5 and height 4, with a player positioned at the coordinate (0, 3),

and an exit positioned at (4, 0), your grid should be printed to the terminal

as follows:

+-+-+-+-+-+

| | | | |X|

+-+-+-+-+-+

| | | | | |

+-+-+-+-+-+

| | | | | |

+-+-+-+-+-+

|P| | | | |

+-+-+-+-+-+

At the top of the grid class, you are provided with these three symbols that make up the grid:

private static final String GRID_CORNER_SYMBOL = “+”;

private static final String GRID_HORIZONTAL_SYMBOL = “-“;

private static final String GRID_VERTICAL_SYMBOL = “|”;

and your Tile classes toString() method should return the String symbol that should be printed on the inside of the individual grid cells (assuming you have correctly implemented that function).

You are free to create any other methods in your Grid or Tile classes that may help you. The only methods that will be run against test cases are those that have been described in this section.

Good Luck

Complete Answer:

Get Instant Help in Homework Asap
Get Instant Help in Homework Asap
Calculate your paper price
Pages (550 words)
Approximate price: -
Open chat
1
Hello 👋
Thank you for choosing our assignment help service!
How can I help you?