Tino Intro To Java

Last modified: April 08, 2026

Lode Runner HW 10 Final Version

In this lab we will add three major features: lives, levels and game over.

Levels

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.

}

Lose Lives and Game Over

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:

  1. reduce lives by one
  2. remove all the actors from the world: see World methods getObjects and removeObjects
  3. Draw the level again: just call drawLevel()

Go to Next Level

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.

(optional) Gold Challenges

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!

  1. To make your current game as enjoyable as the original Lode Runner arcade game:
    1. Add more levels
    2. Add undiggable walls
    3. Add false walls (see below)
    4. Improve enemy AI
  2. Add a twist to your game that was not in the original:
    1. Levers / switches / pressure plates that change things (raise/lower ladder), move or extend platforms...etc
    2. Portals (teleports you to another place in the level)
    3. Lava (instant death)
    4. Walls that appear and disappear regularly
    5. Spikes that shoot up or down and then go back into the wall on regular intervals.

(optional) Adding False Wall

  1. Create a class to represent a false wall and choose the brick image.
  2. When a player touches the false wall, it changes its image to the "false_brick.png", revealing it is false.
  3. Since it won't be the same class as other walls, the player will naturally fall through it because there will be no wall below.

Submission

Zip your entire project folder and submit it below.

  • Name your project folder PX_LastName_FirstName_LodeRunner.
  • Right click on your project folder and Send To -> Compressed (zipped) folder. On a mac compressing is similar, using a right click, but has a slightly different option.
    • You should end up with a zip file named 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.zip
  • Make sure your Google Doc has Editing permissions for "anyone with the link". This is for your teacher and TAs.
  • Paste the link to your Google Doc in the Submission Comments section on this submission form (which becomes visible after you enter a file to submit)

You must Sign In to submit to this assignment

Dark Mode

Outline