|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
fang.GameWindow
fang.FrameAdvancer
fang.GameLoop
fang.GameRedirection
fang.Game
public class Game
The class representing a FANG video game. This is an "empty" game box. By
extending it, a program gets the pretty window, the buttons, and the behavior
of every FANG video game. Because the box is empty, there is no actual game
contained in this class.
Programmers extend Game to create their own games. The extension is usually
by defining new versions of setup() and GameRedirection.advance(double) (or
advance() if you don't care about elapsed time between frames).
Create and initialize game attributes in the setup() method and then
update their state in the GameRedirection.advance(double) method. In FANG, a game
runs something like this (the following is not actually Java):
create Window, create Game g, etc. setup(); while (!g.isGameOver()) {
draw all known Sprites check for input from all input devices calculate
timeSinceLastCall to advance advance(timeSinceLastCall); }
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JApplet |
|---|
JApplet.AccessibleJApplet |
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
static Color |
DEFAULT_BACKGROUND_COLOR
the color to use when clearing the background |
static Dimension |
DEFAULT_GAME_DIMENSIONS
default size of canvas |
| Fields inherited from class fang.GameRedirection |
|---|
finishingGame, firstGame, restarting |
| Fields inherited from class fang.GameLoop |
|---|
client, player, random, SEED |
| Fields inherited from class fang.FrameAdvancer |
|---|
canvas, timeInterval |
| Fields inherited from class fang.GameWindow |
|---|
cards, connectButton, container, createOwnFrame, displayControlButtons, frame, fullScreen, help, helpPlay, loadingMessage, mute, pause, players, playersSelectable, playersSpinner, quit, serverField, serverLabel, serverSelectable, sessionComboBox, sessionLabel, sessionSelectable, title |
| Fields inherited from class javax.swing.JApplet |
|---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
Game()
Create a new Game with the default size and default background color. |
|
Game(Color backgroundColor)
|
|
Game(Dimension gameDimensions)
Create a new Game with the default size and default background color. |
|
Game(Dimension gameDimensions,
Color backgroundColor)
Create a new Game with the given size and given background color. |
|
Game(int gamePixelWidth,
int gamePixelHeight)
Create a new Game with the given size and default background color. |
|
Game(int gamePixelWidth,
int gamePixelHeight,
Color backgroundColor)
Create a new Game with the given size and given background color. |
|
| Method Summary | |
|---|---|
void |
addBottom(Sprite... sprite)
|
static void |
addColor(String name,
Color color)
|
static void |
addColor(String name,
String rgb)
|
void |
addSprite(double layer,
Sprite... sprite)
|
void |
addSprite(Sprite... sprite)
|
void |
advance()
|
boolean |
containsSprite(Sprite sprite)
|
boolean |
downPressed()
Was the down-arrow key pressed as the last key by the default (local) player? |
boolean |
downPressed(int id)
Was the down-arrow key pressed as the last key by the given player? |
void |
flattenLayers()
|
Sprite[] |
getAllSprites()
Get an array of all of the sprites in the game. |
double |
getAspect()
|
Location2D |
getClick2D()
Get location for the default (local) player's mouse when any button was clicked. |
Location2D |
getClick2D(int id)
Get location for the given player's mouse when any button was clicked. |
double |
getClickX()
Return the x-coordinate of the default (local) player's mouse when any button was clicked. |
double |
getClickX(int id)
Return the x-coordinate of the given player's mouse when any button was clicked. |
double |
getClickY()
Return the y-coordinate of the default (local) player's mouse when any button was clicked. |
double |
getClickY(int id)
Return the y-coordinate of the given player's mouse when any button was clicked. |
static Color |
getColor(int red,
int green,
int blue)
Create a solid, opaque color with the given red, gree, and blue values. |
static Color |
getColor(int red,
int green,
int blue,
int opacity)
Create a solid, translucent color with the given red, gree, and blue values. |
static Color |
getColor(String name)
|
static Color |
getColor(String name,
int transparency)
|
static Color |
getColorFromRGB(String rgb)
|
static Color |
getColorFromRGB(String rgb,
int transparency)
|
static String |
getColorName(Color color)
|
static String |
getColorName(int r,
int g,
int b)
|
static String |
getColorName(String rgb)
|
char |
getKeyPressed()
Returns the last key pressed for the default (local) player. |
char |
getKeyPressed(int id)
Returns the last key pressed for the given player. |
Sprite[] |
getLayer(double layer)
|
double |
getLayer(Sprite sprite)
|
Location2D |
getLeftClick2D()
Get location for the default (local) player's mouse when the left button was clicked. |
Location2D |
getLeftClick2D(int id)
Get location for the given player's mouse when the left button was clicked. |
double |
getLeftClickX()
Return the x-coordinate of the default (local) player's mouse when left button was clicked. |
double |
getLeftClickX(int id)
Return the x-coordinate of the given player's mouse when left button was clicked. |
double |
getLeftClickY()
Return the y-coordinate of the default (local) player's mouse when left button was clicked. |
double |
getLeftClickY(int id)
Return the y-coordinate of the given player's mouse when left button was clicked. |
int |
getLives()
|
int |
getLives(int id)
|
char |
getLowerCaseKeyPressed()
Returns the last key pressed for the default (local) player converted to lowercase. |
char |
getLowerCaseKeyPressed(int id)
Returns the last key pressed for the given player converted to lowercase. |
double |
getMaxX()
|
double |
getMaxY()
|
Object |
getMessage()
|
Object |
getMessage(int id)
|
Location2D |
getMiddleClick2D()
Get location for the default (local) player's mouse when the middle button was clicked. |
Location2D |
getMiddleClick2D(int id)
Get location for the given player's mouse when the middle button was clicked. |
double |
getMiddleClickX()
Return the x-coordinate of the default (local) player's mouse when middle button was clicked. |
double |
getMiddleClickX(int id)
Return the x-coordinate of the given player's mouse when middle button was clicked. |
double |
getMiddleClickY()
Return the y-coordinate of the default (local) player's mouse when middle button was clicked. |
double |
getMiddleClickY(int id)
Return the y-coordinate of the given player's mouse when middle button was clicked. |
Location2D |
getMouse2D()
Get location for the default (local) player's mouse. |
Location2D |
getMouse2D(int id)
Get location for a given player. |
double |
getMouseX()
Return the x-coordinate of the mouse for the default (local) player. |
double |
getMouseX(int id)
Return the x-coordinate of the mouse for a given player id. |
double |
getMouseY()
Return the y-coordinate of the mouse for the default (local) player. |
double |
getMouseY(int id)
Return the y-coordinate of the mouse for a given player id. |
int |
getPlayerID()
|
String |
getPlayerName()
|
String |
getPlayerName(int id)
|
Random |
getRandom()
Return this Game's random number generator. |
Color |
getRandomColor()
Deprecated. |
Location2D |
getRightClick2D()
Get location for the default (local) player's mouse when the right button was clicked. |
Location2D |
getRightClick2D(int id)
Get location for the given player's mouse when the right button was clicked. |
double |
getRightClickX()
Return the x-coordinate of the default (local) player's mouse when right button was clicked. |
double |
getRightClickX(int id)
Return the x-coordinate of the given player's mouse when right button was clicked. |
double |
getRightClickY()
Return the y-coordinate of the default (local) player's mouse when right button was clicked. |
double |
getRightClickY(int id)
Return the y-coordinate of the given player's mouse when right button was clicked. |
int |
getScore()
|
int |
getScore(int id)
|
char |
getUpperCaseKeyPressed()
Returns the last key pressed for the default (local) player converted to UPPERCASE. |
char |
getUpperCaseKeyPressed(int id)
Returns the last key pressed for the given player converted to UPPERCASE. |
boolean |
hasMessage()
|
boolean |
hasMessage(int id)
|
boolean |
keyPressed()
Was any key pressed by the default (local) player? |
boolean |
keyPressed(int id)
Was any key pressed by the given player? |
boolean |
leftPressed()
Was the left-arrow key pressed as the last key by the default (local) player? |
boolean |
leftPressed(int id)
Was the left-arrow key pressed as the last key by the given player? |
boolean |
mouseLeftPressed()
Was the left button on the default (local) player's mouse pressed during the last frame? |
boolean |
mouseLeftPressed(int id)
Was the left button on the given player's mouse pressed during the last frame? |
boolean |
mouseMiddlePressed()
Was the middle button on the default (local) player's mouse pressed during the last frame? |
boolean |
mouseMiddlePressed(int id)
Was the middle button on the given player's mouse pressed during the last frame? |
boolean |
mousePressed()
Was any button on the default (local) player's mouse pressed during the last frame? |
boolean |
mousePressed(int id)
Was any button on the given player's mouse pressed during the last frame? |
boolean |
mouseRightPressed()
Was the right button on the default (local) player's mouse pressed during the last frame? |
boolean |
mouseRightPressed(int id)
Was the right button on the given player's mouse pressed during the last frame? |
boolean |
randomBoolean()
Return a randomly selected boolean value. |
Color |
randomColor()
Returns a random color. |
double |
randomDouble()
Return a uniformly distributed random double on the range [0.0, 1.0). |
double |
randomDouble(double max)
|
double |
randomDouble(double min,
double max)
|
int |
randomInt()
|
int |
randomInt(int max)
|
int |
randomInt(int min,
int max)
|
void |
removeAllSprites()
|
void |
removeCursor()
removes the cursor from the game canvas |
void |
removeSprite(Sprite... sprite)
|
void |
restoreCursor()
adds the default cursor back to the screen |
boolean |
rightPressed()
Was the right-arrow key pressed as the last key by the default (local) player? |
boolean |
rightPressed(int id)
Was the right-arrow key pressed as the last key by the given player? |
void |
setAspect(double aspect)
|
void |
setCursor(URL url)
sets the cursor for the game engine |
void |
setLives(int lives)
|
void |
setLives(int lives,
int id)
|
void |
setPlayerName(String name)
|
void |
setPlayerName(String name,
int id)
|
void |
setScore(int score)
|
void |
setScore(int score,
int id)
|
void |
setup()
|
boolean |
upPressed()
Was the up-arrow key pressed as the last key by the default (local) player? |
boolean |
upPressed(int id)
Was the up-arrow key pressed as the last key by the given player? |
| Methods inherited from class fang.GameLoop |
|---|
getGameOverLevel, getGameResource, getResource, main, postAdvanceFrame |
| Methods inherited from class fang.FrameAdvancer |
|---|
setBackground |
| Methods inherited from class fang.GameWindow |
|---|
actionPerformed, getDefaultSize, getHash, getHelpStyleSheet, getHostname, init, isCreatingOwnFrame, setCreateOwnFrame, setDefaultHelp, setLoadMessage, windowStateChanged |
| Methods inherited from class javax.swing.JApplet |
|---|
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update |
| Methods inherited from class java.applet.Applet |
|---|
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Color DEFAULT_BACKGROUND_COLOR
public static final Dimension DEFAULT_GAME_DIMENSIONS
| Constructor Detail |
|---|
public Game()
DEFAULT_GAME_DIMENSIONS and DEFAULT_BACKGROUND_COLOR for
definitions of the default values. The game will keep the same aspect ratio
(ratio between width and height) even when resized after creation.
public Game(Color backgroundColor)
public Game(Dimension gameDimensions)
DEFAULT_GAME_DIMENSIONS and DEFAULT_BACKGROUND_COLOR for
definitions of the default values. The game will keep the same aspect ratio
(ratio between width and height) even when resized after creation.
gameDimensions - initial dimensions of the game field in pixels
public Game(int gamePixelWidth,
int gamePixelHeight)
DEFAULT_BACKGROUND_COLOR for definitions of the default values.
The game will keep the same aspect ratio (ratio between width and height)
even when resized after creation.
gamePixelWidth - initial width of the game field in pixelsgamePixelHeight - initial height of the game field in pixels
public Game(int gamePixelWidth,
int gamePixelHeight,
Color backgroundColor)
gamePixelWidth - initial width of the game field in pixelsgamePixelHeight - initial height of the game field in pixelsbackgroundColor - inital background color of the game field
public Game(Dimension gameDimensions,
Color backgroundColor)
gameDimensions - initial dimensions of the game field in pixelsbackgroundColor - inital background color of the game field| Method Detail |
|---|
public Location2D getMouse2D(int id)
id - -
the identifier of the player to get the mouse for
public double getMouseX(int id)
id - -
player id to get coordinate for
public double getMouseY(int id)
id - -
player id to get coordinate for
public Location2D getMouse2D()
public double getMouseX()
public double getMouseY()
public Location2D getClick2D(int id)
id - -
player id to get coordinate for
public double getClickX(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic double getClickY(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic Location2D getClick2D()
public double getClickX()
Double.NaN.
Double.NaN if no mouse click this framepublic double getClickY()
Double.NaN.
Double.NaN if no mouse click this framepublic Location2D getLeftClick2D(int id)
id - -
player id to get coordinate for
public double getLeftClickX(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic double getLeftClickY(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic Location2D getLeftClick2D()
public double getLeftClickX()
Double.NaN.
Double.NaN if no mouse click this framepublic double getLeftClickY()
Double.NaN.
Double.NaN if no mouse click this framepublic Location2D getMiddleClick2D(int id)
id - -
player id to get coordinate for
public double getMiddleClickX(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this
framepublic double getMiddleClickY(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this
framepublic Location2D getMiddleClick2D()
public double getMiddleClickX()
Double.NaN.
Double.NaN if no mouse click this
framepublic double getMiddleClickY()
Double.NaN.
Double.NaN if no mouse click this
framepublic Location2D getRightClick2D(int id)
id - -
player id to get coordinate for
public double getRightClickX(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic double getRightClickY(int id)
Double.NaN.
id - player to find mouse click location for
Double.NaN if no mouse click this framepublic Location2D getRightClick2D()
public double getRightClickX()
Double.NaN.
Double.NaN if no mouse click this framepublic double getRightClickY()
Double.NaN.
Double.NaN if no mouse click this framepublic boolean mousePressed(int id)
id - player whose mouse should be checked
public boolean mousePressed()
id - player whose mouse should be checked
public boolean mouseLeftPressed(int id)
id - player whose mouse should be checked
public boolean mouseLeftPressed()
id - player whose mouse should be checked
public boolean mouseMiddlePressed(int id)
id - player whose mouse should be checked
public boolean mouseMiddlePressed()
id - player whose mouse should be checked
public boolean mouseRightPressed(int id)
id - player whose mouse should be checked
public boolean mouseRightPressed()
id - player whose mouse should be checked
public char getKeyPressed(int id)
id - -
identifer for player owning the keyboard to be checked
public char getKeyPressed()
public char getLowerCaseKeyPressed(int id)
id - -
identifer for player owning the keyboard to be checked
public char getLowerCaseKeyPressed()
public char getUpperCaseKeyPressed(int id)
id - -
identifer for player owning the keyboard to be checked
public char getUpperCaseKeyPressed()
public boolean upPressed(int id)
id - identifier for the player owning the keyboard to be checked
public boolean upPressed()
public boolean downPressed(int id)
id - identifier for the player owning the keyboard to be checked
public boolean downPressed()
public boolean rightPressed(int id)
id - identifier for the player owning the keyboard to be checked
public boolean rightPressed()
public boolean leftPressed(int id)
id - identifier for the player owning the keyboard to be checked
public boolean leftPressed()
public boolean keyPressed(int id)
id - identifier for the player owning the keyboard to be checked
public boolean keyPressed()
public void setAspect(double aspect)
public void restoreCursor()
FrameAdvancer
restoreCursor in class GameRedirectionpublic void removeCursor()
FrameAdvancer
removeCursor in class GameRedirectionpublic void setCursor(URL url)
FrameAdvancer
setCursor in class GameRedirectionpublic double getMaxX()
public double getMaxY()
public void addSprite(Sprite... sprite)
public void addSprite(double layer,
Sprite... sprite)
public double getLayer(Sprite sprite)
public Sprite[] getLayer(double layer)
public void flattenLayers()
public void removeSprite(Sprite... sprite)
public void removeAllSprites()
public boolean containsSprite(Sprite sprite)
public Sprite[] getAllSprites()
public void addBottom(Sprite... sprite)
public double getAspect()
public static Color getColor(int red,
int green,
int blue)
red - the amount of red to include; range is [0..255] with 0 meaning no
redgreen - the amount of green to include; range is [0..255] with 0 meaining
no greenblue - the amount of blue to include; range is [0..255] with 0 meaning no
blue
Color object for the given shade
public static Color getColor(int red,
int green,
int blue,
int opacity)
red - the amount of red to include; range is [0..255] with 0 meaning no
redgreen - the amount of green to include; range is [0..255] with 0 meaining
no greenblue - the amount of blue to include; range is [0..255] with 0 meaning no
blueopacity - the amount of opaqueness for the color; range is [0..255] with 0
meaning transparent and 255 meaning opaque
Color object for the given shadepublic static Color getColor(String name)
public static Color getColor(String name,
int transparency)
public static String getColorName(int r,
int g,
int b)
public static String getColorName(String rgb)
public static String getColorName(Color color)
public static Color getColorFromRGB(String rgb)
public static Color getColorFromRGB(String rgb,
int transparency)
public static void addColor(String name,
Color color)
public static void addColor(String name,
String rgb)
@Deprecated public Color getRandomColor()
public Color randomColor()
public Random getRandom()
Game's random number generator.
Random used by this game to generate
random numbers.public boolean randomBoolean()
true and
false half of the time each.
public double randomDouble()
public double randomDouble(double max)
public double randomDouble(double min,
double max)
public int randomInt()
public int randomInt(int max)
public int randomInt(int min,
int max)
public int getLives(int id)
public int getLives()
public void setLives(int lives,
int id)
public void setLives(int lives)
public String getPlayerName(int id)
public String getPlayerName()
public void setPlayerName(String name,
int id)
public void setPlayerName(String name)
public int getScore(int id)
public int getScore()
public void setScore(int score,
int id)
public void setScore(int score)
public int getPlayerID()
public boolean hasMessage(int id)
public boolean hasMessage()
public Object getMessage(int id)
public Object getMessage()
public void advance()
advance in class GameRedirectionpublic void setup()
setup in class GameRedirection
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||