Lab 11

No code for this lab, just create a class called Maps

I am not going to explain this one too much because you should already know how this one works. You can create whatever methods you want as long as it gets the correct result.

So the goal for this lab is to use a HashMap as a lookup for objects in a game level. Imagine you have a level saved as a text file, it might look something like this:

#        #
#        #
#        #
#        #
#        #
#        #
#        #
#        #
#s  #   e#
##########

When you are reading through all of these you could have an if statement for each different character and say "if it's this character then print this tile, else if..." and do that forever. This isn't very good when you start working with 40-50 different tiles though

A better way to do this is to use a HashMap! We dump all of our different types of tiles into a map and we check the file, character by character, for those tiles within the map.

Step 1 is to populate the map, so for this first one we only have 3 tile types (# = floor, s = start, e = end)

We will add more tiles to this in Thursday's lab final, but for now we will just get it started. Once those are populated you should create a txt file in your project called level0.txt and copy and paste the level text into it.

Now set up a file reader of some sort (You should probably use BufferedReader since it's read method will give you a single char) and read in each character. For every character read in you should check if it is in the map you made, if it is the print out the value, otherwise print out that it is empty space

In this case any garbage data gets eaten up and is assumed to be empty space since it wouldn't be in the map.

The print out for the first line of this file should look like this:

Tile exists: Floor
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile does not exist: Empty
Tile exists: Floor

The rest should be self explanitory for what should be printed. You can use some of your other labs as an example for the FileIO stuff you need, but I think a quick google search for BufferedReader would be easier.

Zip up the folder and submit to dropbox!