Last modified: April 08, 2026
In this lab we will add three major features: lives, levels and game over.
To make it easy to make levels, you should make a top level World class that has common methods and fields that all levels will have. Then make subclasses of that top level class that override methods, such as a method that draws the level and sets values of fields as needed.
Here is an outline to get you started:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Represents a lode runner level.
* Every level will be a subclass of this one.
*/
public class Level extends World {
// declare instance variables such as lives and level
// or references to Text objects
// Make a class variable representing the hud height
public static int HUD_HEIGHT = 48;
public Level() {
// Create a new world with the desired dimensions with room for HUD
super(600, 480 + HUD_HEIGHT, 1);
drawBackground();
drawLevel();
drawHud();
}
/** fill the world with a black background **/
public void drawBackground() {
// YOUR CODE HERE
}
/**
* Subclasses should override this to add walls, ladders, bars,
* players, enemies...etc.
*/
public void drawLevel() {
// Nothing to do here except in subclasses
}
/**
* Draw the HUD text at the bottom that shows score, lives and level.
**/
public void drawHud() {
// YOUR CODE HERE
}
/**
* Subclasses should override this method to return an instance
* of the next level. If this returns null, then there is no next level.
*/
public Level getNextLevel() {
// Nothing to do here except in subclasses
return null;
}
/**
* Get an instance of the next level by calling the getNextLevel() method.
* If there is a next level, then:
* - Set the lives of the next level to the same as the current level
* - Set the active world to be the next level
* (See setWorld in the Greenfoot class API)
*/
public void goToNextLevel() {
// YOUR CODE HERE
}
// add a method to handle losing a life and restarting level (see below)
// make setters and getters for instance variables
// Don't forget to update the Text objects in HUD when values change.
}
When an enemy touches a player, reduce lives by one and reset the level. Except, if reducing lives by one results in zero lives, then display GameOver and add a button that takes you back to the main menu / title screen.
Possible strategy for resetting the world after losing a life that isn't the last life:
getObjects and removeObjectsdrawLevel()Simple version: When the player has collected all the gold in the world, go to the next level.
Original Game Version: When the player has collected all the gold in the world AND they are in the top row of the level (the world edge is just above them), then they gain a life and go to the next level. In some levels it is possible to reach the top row at any time, but in other levels an extra ladder (or multiple ladders) appears that allows them to reach the top.
Implement the goToNextLevel() method as described in the code outline above, so you can just call that method to go to the next level.
While you now have a playable version of Lode Runner, there are many features you could still add to make the game better. Here is the version made by Mr. McLeod. In the following sections, you will see some ideas for adding these features. You can also come up with your own features. Be creative!
Zip your entire project folder and submit it below.
PX_LastName_FirstName_LodeRunner.PX_LastName_FirstName_LodeRunner.zip. For example if you were in 3rd period and named Michael Wang, then you would name the file P3_Wang_Michael_LodeRunner.zipYou must Sign In to submit to this assignment