Question: Your task is to create a simple text-based map that allows the user to move their character, the hero, around on the map. Hero Class

Your task is to create a simple text-based map that allows the user to move their character, the

hero, around on the map.

Hero Class

A private String instance variable name

A private int instance variable row (indicates the hero's vertical position on the map)

A private int instance variable column (indicates the hero's

horizontal position on the map)

Constructor that takes in a name

Public getters for the name, row, and column

Public setters for the row and column

Map Class

A private Hero instance variable called hero for the hero on the map

A private char[][] instance variable called tiles that represents the tiles of the map

A private int instance variable called width for how many columns the map has

A private int instance variable called height for how many rows the map has

Constructor that takes in a hero, width, and height and also sets up the tiles

A public void method moveUp() that moves the hero up a tile

A public void method moveDown() that moves the hero down a tile

A public void method moveRight() that moves the hero right a tile

A public void method moveLeft() that moves the hero left a tile

Override the toString() method to return a text representation of the map, putting the first

letter of the hero's name in the position where the hero is currently located on the map

Game Class

Create a main() method that gets a name from the user and makes a Hero object and a Map

object

Repeatedly print the map and get a command from the user

Here's a sample run of the program:

Enter Name:

Jim

J . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

u - up

d - down

r - right

l - left

q - quit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!