edu.trinity.cs.gamecore.basic
Class BasicGameSetup

java.lang.Object
  extended by edu.trinity.cs.gamecore.basic.BasicGameSetup
All Implemented Interfaces:
GameSetup<BasicBlock,BasicEntity>

public class BasicGameSetup
extends java.lang.Object
implements GameSetup<BasicBlock,BasicEntity>

This is a simple implementation of the GameSetup interface. It tells the game infrastructure how to render things and is a good place to put things that you need to get to from anywhere.

Students are given this code with assignment #2. The class itself uses the singleton pattern not only so that only one is created, but also so that you can easily get to that one instance from anywhere in your code. For the singleton pattern, the constructor is made private and we put in a static method called instance that checks to see if we have created an instance, creates one if not, and returns the instance.

Feel free to add whatever other methods or members you want into your implementation of GameSetup. This can be a simple way to keep track of information that lots of different entities or blocks need to get hold of.


Method Summary
 BasicPlayer getLocalPlayer()
          Returns the instance of your Player subclass that should be used in this game.
 javax.swing.JMenuBar getMenuBar()
          This function returns a JMenuBar object that will be added to the main display window.
 PriorityQueue<BasicBlock,BasicEntity> getPriorityQueue()
          Return the priority queue that you are using for the game.
 int getScrollingX()
          Tells the display class is this game has a scrolling background in the x direction.
 int getScrollingY()
          Tells the display class is this game has a scrolling background in the y direction.
static BasicGameSetup instance()
          This method returns the singleton of the BasicGameSetup class.
 void setMainFrame(MainFrame<BasicBlock,BasicEntity> mf)
          This method is called in the constructor of a main frame so that the GameSetup class will be able to communicate with the frame that the game is being played in.
 void stopGame()
          This function will automatically be called when the player begins to return something other than GAME_RUNNING.
 boolean useDrawOptimization()
          If this returns true, the drawing routine will use an optimization of drawing the images for all the blocks once to a large image and just putting up that image as long as the player hasn't changed screens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static BasicGameSetup instance()
This method returns the singleton of the BasicGameSetup class.


setMainFrame

public void setMainFrame(MainFrame<BasicBlock,BasicEntity> mf)
This method is called in the constructor of a main frame so that the GameSetup class will be able to communicate with the frame that the game is being played in.

Specified by:
setMainFrame in interface GameSetup<BasicBlock,BasicEntity>
Parameters:
mf - The MainFrame object the game is being played in.

getLocalPlayer

public BasicPlayer getLocalPlayer()
Returns the instance of your Player subclass that should be used in this game.

Specified by:
getLocalPlayer in interface GameSetup<BasicBlock,BasicEntity>

getPriorityQueue

public PriorityQueue<BasicBlock,BasicEntity> getPriorityQueue()
Return the priority queue that you are using for the game. You will write two of these during the semester.

Specified by:
getPriorityQueue in interface GameSetup<BasicBlock,BasicEntity>

getScrollingX

public int getScrollingX()
Tells the display class is this game has a scrolling background in the x direction.

Specified by:
getScrollingX in interface GameSetup<BasicBlock,BasicEntity>
Returns:
This value tells the program how many squares across it should draw around the player. Return -1 for no scrolling.

getScrollingY

public int getScrollingY()
Tells the display class is this game has a scrolling background in the y direction.

Specified by:
getScrollingY in interface GameSetup<BasicBlock,BasicEntity>
Returns:
This value tells the program how many squares vertically it should draw around the player. Return -1 for no scrolling.

useDrawOptimization

public boolean useDrawOptimization()
If this returns true, the drawing routine will use an optimization of drawing the images for all the blocks once to a large image and just putting up that image as long as the player hasn't changed screens. This can be significantly faster. However, if it is true, it means that changes to blocks won't normally be drawn so you can't have animated blocks, or moving blocks, or blocks that disappear (doors). This flag is checked at every step so you could have it return true most of the time, but return false when some event has occured that should require the blocks to be redrawn.

Specified by:
useDrawOptimization in interface GameSetup<BasicBlock,BasicEntity>
Returns:
Whether or not the framework should double-buffer the blocks as a background image.

getMenuBar

public javax.swing.JMenuBar getMenuBar()
This function returns a JMenuBar object that will be added to the main display window. All of the functions that you want the menus to be able to doo will need to be connected from here.

Specified by:
getMenuBar in interface GameSetup<BasicBlock,BasicEntity>

stopGame

public void stopGame()
This function will automatically be called when the player begins to return something other than GAME_RUNNING.

Specified by:
stopGame in interface GameSetup<BasicBlock,BasicEntity>