Computer Science & Software Engineering |
CSCI 136 |
In this assignment, you will be extending your previous Ultima 0 assignment. You will be implementing monsters using Java threads. |
The Avatar's line in the game text file now has 5 numbers, for example:public class Avatar ---------------------------------------------------------------------------------------- Avatar(int x, int y, int hp, int damage, double torch) int getHitPoints() // Get the number of hit points left void incurDamage(int damage) // Reduce the Avatar's hit points by the amount damage int getDamage() // Get the amount of damage the Avatar causes monsters void passTime(int timeMs) // Inform the Avatar that some time has passed
The above means the Avatar starts at (11,2), has 20 hit points, causes 3 damage, and has an initial torch radius of 100.11 2 20 3 100.0
Monster. The Monster class represents a monster that roams around the World randomly. A monster knows things like its location, its remaining hit points, the amount of damage it causes when it attacks, and the type of monster it is. Monster objects also keep a reference to the World object so they can call methods in World from their run() method (namely the monsterMove() method). Just like the Avatar, if damaged a monster displays its remaining hit points in red text over the monster image for 3 seconds. If a monster's hit points are 0 or less, the monster is longer drawn.public class Tile ----------------------------------------------------------------------------------------- int getDamage() // Return the damage caused by this type of Tile
Name | Filename | Image | Code |
Skeleton | skeleton.gif | SK | |
Orc | orc.gif | OR | |
Slime | slime.gif | SL | |
Bat | bat.gif | BA |
Monsters are defined at the end of the game text file. You can assume the values in the file are valid starting locations, monsters won't start on top of each other, etc. Here is an example:public class Monster implements Runnable ----------------------------------------------------------------------------------------- Monster(World world, String code, int x, int y, int hp, int damage, int sleepMs) void incurDamage(int damage) // Reduce the monster's hit points by the amount damage void draw() // Draw the monster int getHitPoints() // Get the number of remaining hit points of this monster int getDamage() // Get how much damage the monster causes int getX() // Get current x-position int getY() // Get current y-position void setLocation(int x, int y) // Move monster to a new location void run() // Worker thread that periodically moves monster
This defines:SK 3 3 10 3 1000 OR 6 19 8 2 1000 BA 20 10 4 1 500 SL 25 16 6 2 1500
The monsterMove() should be called by a monster's run() method. If the proposed location is not valid or not passable, then there is nothing happens. If there is currently another monster at the proposed location, then nothing happen either (monsters don't attack each other). If the Avatar is at the proposed location, then the monster gets to attack the Avatar and go the appropriate damage. In this case, the monster stays at its current location (Avatar and monsters never overlap). Otherwise, the monster makes its move to the new location incurring any damage associated with the new location (i.e. lava).public class World ----------------------------------------------------------------------------------------- boolean avatarAlive() // Is the Avatar still alive? void monsterMove(int x, int y, Monster monster) // Attempt to move given monster to (x, y) void avatarMove(int x, int y) // Attempt to move Avatar to (x, y) int getNumMonsters() // Return number of alive monsters void passTime(int timeMs) // Inform world that some time has passed
Extra credit.
Make the game better.
Submission. Submit your programs Avatar.java, Tile.java, World.java and Monster.java, using Moodle. Be sure each submitted source file has the required header with your name, username, and a description of the program. For extra-credit, please submit a single zip file containing all your programs/graphics/sounds via the special Assignment #6 extra-credit drop box. Page last updated: August 16, 2012 |