Site Loader
Get a Quote
Rock Street, San Francisco

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uk.ac.bradford.dungeongame;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

/**
* The GameEngine class is responsible for managing information about the game,
* creating levels, the player and monsters, as well as updating information
* when a key is pressed while the game is running.
*
* @author prtrundl
*/
public class GameEngine {

/**
* An enumeration type to represent different types of tiles that make up a
* dungeon level. Each type has a corresponding image file that is used to
* draw the right tile to the screen for each tile in a level. Floors are
* open for monsters and the player to move into, walls should be
* impassable, stairs allow the player to progress to the next level of the
* dungeon, and chests can yield a reward when moved over.
*/
public enum TileType {
WALL, FLOOR, CHEST, STAIRS
}

/**
* The width of the dungeon level, measured in tiles. Changing this may
* cause the display to draw incorrectly, and as a minimum the size of the
* GUI would need to be adjusted.
*/
public static final int DUNGEON_WIDTH = 25;

/**
* The height of the dungeon level, measured in tiles. Changing this may
* cause the display to draw incorrectly, and as a minimum the size of the
* GUI would need to be adjusted.
*/
public static final int DUNGEON_HEIGHT = 18;

/**
* The maximum number of monsters that can be generated on a single level of
* the dungeon. This attribute can be used to fix the size of an array (or
* similar) that will store monsters.
*/
public static final int MAX_MONSTERS = 40;

/**
* The chance of a wall being generated instead of a floor when generating
* the level. 1.0 is 100% chance, 0.0 is 0% chance.
*/
public static final double WALL_CHANCE = 0.15;

/**
* A random number generator that can be used to include randomised choices
* in the creation of levels, in choosing places to spawn the player and
* monsters, and to randomise movement and damage. This currently uses a
* seed value of 123 to generate random numbers – this helps you find bugs
* by giving you the same numbers each time you run the program. Remove the
* seed value if you want different results each game.
*/
private Random rng = new Random();

/**
* The current level number for the dungeon. As the player moves down stairs
* the level number should be increased and can be used to increase the
* difficulty e.g. by creating additional monsters with more health.
*/
private int depth = 1; //current dunegeon level

/**
* The GUI associated with a GameEngine object. THis link allows the engine
* to pass level (tiles) and entity information to the GUI to be drawn.
*/
private GameGUI gui;

/**
* The 2 dimensional array of tiles the represent the current dungeon level.
* The size of this array should use the DUNGEON_HEIGHT and DUNGEON_WIDTH
* attributes when it is created.
*/
private TileType tiles;

/**
* An ArrayList of Point objects used to create and track possible locations
* to spawn the player and monsters.
*/
private ArrayList spawns;

/**
* An Entity object that is the current player. This object stores the state
* information for the player, including health and the current position
* (which is a pair of co-ordinates that corresponds to a tile in the
* current level)
*/
private Entity player;

/**
* An array of Entity objects that represents the monsters in the current
* level of the dungeon. Elements in this array should be of the type
* Entity, meaning that a monster is alive and needs to be drawn or moved,
* or should be null which means nothing is drawn or processed for movement.
* Null values in this array are skipped during drawing and movement
* processing. Monsters (Entity objects) that die due to player attacks can
* be replaced with the value null in this array which removes them from the
* game.
*/
private Entity monsters;

/**
* Constructor that creates a GameEngine object and connects it with a
* GameGUI object.
*
* @param gui The GameGUI object that this engine will pass information to
* in order to draw levels and entities to the screen.
*/
public GameEngine(GameGUI gui) {
this.gui = gui;
startGame();
}

/**
* Generates a new dungeon level. The method builds a 2D array of TileType
* values that will be used to draw tiles to the screen and to add a variety
* of elements into each level. Tiles can be floors, walls, stairs (to
* progress to the next level of the dungeon) or chests. The method should
* contain the implementation of an algorithm to create an interesting and
* varied level each time it is called.
*
* @return A 2D array of TileTypes representing the tiles in the current
* level of the dungeon. The size of this array should use the width and
* height of the dungeon.
*/
private TileType generateLevel() {
TileType level = new TileTypeDUNGEON_WIDTHDUNGEON_HEIGHT;
//Add your code here to fill the level array with TileType values to create a level
for (int x = 0; x

Post Author: admin

x

Hi!
I'm Lillian

Would you like to get a custom essay? How about receiving a customized one?

Check it out
x

Hi!
I'm Camille!

Would you like to get a custom essay? How about receiving a customized one?

Check it out