back to projects page
Project 3
The Legend of Zelba
Concepts Covered: Writing a large program consisting of several smaller files, Inheritance, Polymorphism
Due: Tuesday, February 25 at midnight
Files you need: MapSpace.java, Mountain.java, Desert.java, sampleMap
Turn In: Map.java, Link.java, MapSpace.java, (VariousMapSpaces).java, LegendOfZelba.java
Background:
If you're into video games like I am, there is no doubt that you've
played one of Nintendo's fantastic Legend of Zelda games! I can safely
say that my favorite game of all time is Legend of Zelda: The Ocarina
of Time for the Nintendo 64. For those of you that are not familiar
with the game, you play as Link, the hero, and you are generally on
some sort of quest. In some of the games your quest is to save the
Princess Zelda from the vile clutches of Gannon. In the game, you
basically travel throughout Hyrule (the land where the game is based)
and get into various adventures on your way to the goal. Most of these
adventures involve solving puzzles, fighting monsters, finding items,
etc. Your job is to write an extraordinarily simplified version of this
game.
Requirements: The simple premise of our version
of the game (which will be called the Legend of Zelba to avoid any
lawsuits over "intellectual property") will be the following: Link is
traveling through Hyrule (which will be represented by a 2D array of
objects implementing the MapSpace interface) trying to save Zelba who
is at a randomly generated position of the map.
Each space on
the map will implement the MapSpace interface, which consists of three
methods : onLanding(), onLeaving() and getName(). Your main program
(LegendOfZelba.java) will create the Map, create a Link object and then
repeatedly let Link move either north, south, east, or west, calling
the OnLeaving() method of the MapSpace on which he is leaving and the
OnLanding() method of the MapSpace on which he lands. If he makes it to
the space that Zelba is located, then you win! Of course, there has to
be some way that Link can lose as well, so the Link class has an
instance variable called health. His health can be lost throughout the
game in various places.
You should think of this game as a
piece of interactive fiction. Make your descriptions detailed - attempt
to immerse the player into the experience as much as possible. If
you've never actually played any interactive fiction before, I highly
recommend that you try out The Hitchhikers Guide to the Galaxy.
I spent many many hours playing this game when I was younger - but I
was never able to beat it. (Note that you have to scroll down to the
bottom of the page and enter the number from the screen to start
playing it).
Implementation Details: You should
probably write the classes in the following order, and test each one
thoroughly (write a simple test program that tests all of the methods)
before moving on to the next.
- Map.java -
This is the class that represents Link's world. It is a 2D Array (note:
NOT an ArrayList) of objects that implement the MapSpace interface. The
constructor should read a representation of the map from a text file
and fill out all associated attributes of the MapSpace. For extra
credit (and a game that is more fun), you can add a constructor that
randomly generates a map (but don't attempt this until you've completed
all of the other requirements). Remember, the map should randomly
generate a place for the princess, and she should be denoted by a space
marked Z on the string representation of the map. The instance
variables should consist of the 2DArray (obviously) and Zelda's row and
column position on the map. You'll probably want the following methods:
- getHeight()
- getWidth()
- getMapSpace(int row, int column)
- isZelbaSpace(int row, int column)
- toString() -- returns a string representation of the map
- linkToString(int row, int col) -- returns a string with link's location specified via row, col
- Link.java - This is
the class that represents your character in the game. He will have
instance variables that will represent his health, his location the Map
(the row and column), and any other attributes you wish him to have. You probably want the following methods:
- damage(int i)
- getColumn() -- get column position
- getRow() -- get row position
- getHealth() -- returns link's health
- heal(int i) -- heals Link
- isAlive() -- returns true if Link is still alive
- move(int direction) -- the direction specifies north, south, east, west
- LegendOfZelba.java
- This is your main game class. It should consist of a loop that
continues executing while Link is still alive and Zelba has not been
rescued. Each round of the loop will display a prompt, where the player
can type in a command. The minimal set of commands that your program
should understand are the following: north (or n), south (or s), east
(or e), west (or w), help (or h) and map. You can achieve this
functionality by prompting for the command and then using a nested
if-else statement, ie
//prompt and get command
if(command.equalsIgnoreCase("north") || command.equalsIgnoreCase("n")) {
//move Link north
}
else if(command.equalsIgnoreCase("south") || command.equalsIgnoreCase("s")) {
//move Link south
}
...
else if(command.equalsIgnoreCase("help") || command.equalsIgnoreCase("h")) {
//output a list of commands
}
else if(command.equalsIgnoreCase("map")) {
//print out the map
}
else {
System.out.println("I don't understand that command!");
}
The game is over when either Link dies or rescues the princess.
- Additional Map Spaces
- You are required to come up with at least two more classes that
implement the MapSpace interface, and you need to create a map file
that uses your additional constructs.
Grading:
This is an opportunity to earn a massive amount of project extra
credit. Implementing the minimum requirements above will make you
eligible for full credit for the project. If you go beyond the minimum
requirements, you can earn up to 150%! You can add any play mechanic to
the game that you would like, but the more complex it is, the more
extra credit you can earn. Here are some ideas:
- Randomly Generated Map: This could be really
cool. Add a constructor to your Map class that randomly generates a
map, but do it in such a way that certain types of MapSpaces are likely
to appear together (this will require some clever manipulation of your
randomly generated numbers). This should create a natural terrain, i.e.
lots of mountains together, lots of deserts together, etc.
- Monsters:
What fun is an adventure game without any monsters? Create a class
hierarchy of monsters that extend the abstract monster class. Your
LegendOfZelba class should maintain an array list of monsters and
should generate random locations for each (but make sure you don't have
two monsters at any given location). Each time Link lands on a
location, after the onLanding() method is executed, see if he
encounters a monster (this can be achieved by traversing the array list
and seeing if Link's location matches any of the Monsters' locations.
If so, have them fight it out using turn based attack() and defend()
methods. Also give Link the option to flee. The battle continues until
either Link or the Monster dies, or until either Link or the Monster
flees. If Link flees, simply move him in a random direction.
- Moving Monsters:
Have the monsters randomly move in a direction after each turn. This
could make your game a lot more fun - Link will have to tread through
the map very carefully.
- Items: What fun is an
adventure game without items? Create an item interface and let Link
maintain an ArrayList of items that he can use. The item interface
should specify some sort of onUsing() method that does something.
- Complex Battle/Experience System:
Create an attribute in the Link class that maintains an experience
level and experience points. After each battle or event, Link gains
some sort of experience points and after a certain amount of experience
points, he increases a level. The level should increase his attacks,
his defense, his max health or his accuracy.
- MapSpace Minigames:
Certain MapSpaces could be designed to play mini games, such as a
simple lottery game or a guess the number game. Link could be rewarded
with health or experience points for winning mini games.
- Gannon:
Create a Gannon Monster that is very powerful and put him on the same
space as Zelda. Link has to fight him to beat the game. This would be
particularly fun if you also added the complex battle/experience
system, so that Gannon could only be defeated after Link is
sufficiently powerful.
Implementing one or two of
these very well would be sufficient for a significant amount of extra
credit. You may also be as creative as you wish and add any game
mechanic that you can think of. Make sure all of your extra mechanics
are documented in your README file, so I know to look for them in your
code.
Things to watch out for:
- A
lot of these classes require the others in order to be compiled. It's
probably a good idea to go ahead and create skeleton versions of the
classes before you begin. This way, you can compile your code while
you're working.
- Don't let Link move off the edge of the map.
- Make sure Zelba is not generated at Link's starting position.
- Every
location must have randomly generated events occurring (ie, in the
desert link may get too hot and lose health, or he may find a pool of
water).
- Other requirements will be discussed in class