Book Image

Creative Greenfoot: RAW

By : Michael Haungs
Book Image

Creative Greenfoot: RAW

By: Michael Haungs

Overview of this book

Table of Contents (17 chapters)
Creative Greenfoot
About the Author
About the Reviewers

Implementing game difficulty settings and HUD controls

We have a few things to take care of before our new version of MazeWorld is ready. First, we need to incorporate the difficulty level chosen by the player on the introduction screen, and we need to implement the functionality of the HUD we added to the game. These changes involve three classes: MazeWorld, ScrollingEnemy, and Snake.

Here is the code for MazeWorld where the changes needed are highlighted:

import greenfoot.*;
import java.util.List;
import java.util.ListIterator;
import java.util.Stack;

public class MazeWorld extends World {
  private int xOffset = 0;
  private Hiker hiker;
  private final static int SWIDTH = 600;
  private final static int SHEIGHT = 400;
  private final static int WWIDTH = 1200;
  private final static int TWIDTH = 25;
  private final static int THEIGHT = TWIDTH;
  private final static int TILEOFFSET = TWIDTH/2;
  private final static String validSpaces = "WG";
  private int playMode = 0;
  private final...