PuyoPuyo Documentation


puyopuyo
Class frontEnd

java.lang.Object
  extended by puyopuyo.puyo
      extended by puyopuyo.backEnd
          extended by puyopuyo.frontEnd
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

public class frontEnd
extends backEnd
implements java.awt.event.KeyListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener

frontEnd manages the screen using ScreenManager and calls on backEnd to execute the logic.


Field Summary
private  java.awt.Color boardColor
          Color of the board.
private  int boardX
          Stores X co-ordinate of the board (board contains playing area)
private  int boardY
          Stores Y Co-ordinate of the board (board contains playing area)
private  java.awt.Color borderColor
          Color of the border surrounding the playing area.
private  int borderWidth
          Width of the border surrounding the playing area, in pixels.
private  java.awt.Point centerLocation
          Holds the center point of the screen.
private  java.awt.DisplayMode[] dm
          Array of supported display modes.
private  int DOWN
          Direction in which to rotate the puyo.
private  java.awt.Font f
          Font used for printing text on the screen.
private  int fontsize
          Size of the font used for printing text on the screen.
private  java.awt.Graphics2D g
          Used for printing on screen.
private  boolean isRecentering
          Boolean telling if the mouse is re-centering or not.
private  int LEFT
          Direction in which to rotate the puyo.
private  java.awt.Point mouseLocation
          Point object storing the mouse's location.
private  java.awt.image.ImageObserver observer
          ImageObserver object used to wait on puyo's image to load so that its heigth and width can be determined.
private  boolean paused
          Tells whether the game is paused or not.
private  int playingAreaHeight
          playingAreaHeight = puyoHeight * puyosOnYAxis.
private  int playingAreaWidth
          playingAreaWidth = puyoWidth * puyosOnXAxis.
private  int puyoHeight
          Holds the height of the image representing the puyo.
private  int puyoWidth
          Holds the width of the image representing the puyo.
private  int RIGHT
          Direction in which to rotate the puyo.
private  java.awt.Robot robot
          Object of Robot class used for recentering the mouse.
private  int ROTATE
          It directs movementWrapper to rotate the pair.
private  int scoreX
          X co-ordinate of the point where score has to be printed.
private  int scoreY
          Y co-ordinate of the point where score has to be printed.
private  ScreenManager screen
          Object of ScreenManager.
 
Fields inherited from class puyopuyo.backEnd
popmin, puyosOnXAxis, puyosOnYAxis
 
Constructor Summary
frontEnd()
          Creates a new instance of frontEnd
frontEnd(boolean autodetect)
          Creates an instance of the class. Initialises backEnd by calling on its constructor. Adds the mouse and keyboard listeners. Draws the complete screen for the first time.
 
Method Summary
 void drawBoardMap()
          Draws puyos according to the boardMap within the playing area drawn by drawScreen.
 void drawScreen()
          Fills the screen with background color and draws the outline of the playing area.
private  java.awt.Graphics2D getG()
          Returns the current graphics context.
 void goodbye()
          Kills the thread and exits from the game while restoring the screen and unhiding the mouse pointer.
private  void initializeFont()
          Set the font file to use, over-riding the default font created during initialization.
private  void initializeGraphics(boolean autodetect)
           Switch to most appropriate display resolution. Switch to full screen if system allows to, else exit. Determine the co-ordinates at which to print the score. Initialize mouse. Set the current Graphics context. Initialize the font.
private  void initializeMouse(java.awt.Window window)
          Initializes the mouse, recenters it and hides the mouse pointer.
 void keyPressed(java.awt.event.KeyEvent e)
          KeyEvent listener that is responsible for firing appropriate actions corresponding to the key pressed.
 void keyReleased(java.awt.event.KeyEvent e)
          KeyListener Interface: keyReleased.
 void keyTyped(java.awt.event.KeyEvent e)
          KeyListener Interface: keyTyped.
static void main(java.lang.String[] args)
          'Mainest' Method Of ALL :D
 void mouseClicked(java.awt.event.MouseEvent e)
          From the MouseListener interface.
 void mouseDragged(java.awt.event.MouseEvent e)
          From the MouseMotionListener interface.
 void mouseEntered(java.awt.event.MouseEvent e)
          From the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          From the MouseListener interface.
 void mouseMoved(java.awt.event.MouseEvent e)
          From the MouseMotionListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          From the MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent e)
          From the MouseListener interface.
 void movementWrapper(int direction)
          Takes care of the movements on screen.
private  void recenterMouse()
          Uses the Robot class to try to position the mouse in the center of the screen.
private  void setG(java.awt.Graphics2D gr)
          Sets the current graphics context.
 
Methods inherited from class puyopuyo.backEnd
getBoardMap, getPuyoPair, getScore, isGameOver, moveDown, moveLeft, moveRight, popPuyos, pushPuyos, rotate, setGameOver
 
Methods inherited from class puyopuyo.puyo
getColor, getImage, getX, getY, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

observer

private java.awt.image.ImageObserver observer
ImageObserver object used to wait on puyo's image to load so that its heigth and width can be determined.


puyoWidth

private final int puyoWidth
Holds the width of the image representing the puyo. It is assumed that all the images representing puyos have same height and width.


puyoHeight

private final int puyoHeight
Holds the height of the image representing the puyo. It is assumed that all the images representing puyos have same height and width.


g

private java.awt.Graphics2D g
Used for printing on screen.


screen

private ScreenManager screen
Object of ScreenManager.


dm

private java.awt.DisplayMode[] dm
Array of supported display modes.


f

private java.awt.Font f
Font used for printing text on the screen.


borderColor

private java.awt.Color borderColor
Color of the border surrounding the playing area.


boardColor

private java.awt.Color boardColor
Color of the board. This color is also used as a background color to fill the screen.


borderWidth

private int borderWidth
Width of the border surrounding the playing area, in pixels.


boardX

private int boardX
Stores X co-ordinate of the board (board contains playing area)


boardY

private int boardY
Stores Y Co-ordinate of the board (board contains playing area)


playingAreaWidth

private final int playingAreaWidth
playingAreaWidth = puyoWidth * puyosOnXAxis.


playingAreaHeight

private final int playingAreaHeight
playingAreaHeight = puyoHeight * puyosOnYAxis.


fontsize

private int fontsize
Size of the font used for printing text on the screen.


scoreX

private int scoreX
X co-ordinate of the point where score has to be printed.


scoreY

private int scoreY
Y co-ordinate of the point where score has to be printed.


LEFT

private final int LEFT
Direction in which to rotate the puyo. This value tells movementWrapper to move the pair one step left.

See Also:
Constant Field Values

RIGHT

private final int RIGHT
Direction in which to rotate the puyo. This value tells movementWrapper to move the pair one step right.

See Also:
Constant Field Values

DOWN

private final int DOWN
Direction in which to rotate the puyo. This value tells movementWrapper to move the pair one step down, or in other words, accelerate their fall.

See Also:
Constant Field Values

ROTATE

private final int ROTATE
It directs movementWrapper to rotate the pair.

See Also:
Constant Field Values

paused

private boolean paused
Tells whether the game is paused or not. If it is, all the Mouse and Keyboard events are ignored. However, user is allowed to exit from the game.


robot

private java.awt.Robot robot
Object of Robot class used for recentering the mouse.


mouseLocation

private java.awt.Point mouseLocation
Point object storing the mouse's location.


centerLocation

private java.awt.Point centerLocation
Holds the center point of the screen.


isRecentering

private boolean isRecentering
Boolean telling if the mouse is re-centering or not.

Constructor Detail

frontEnd

public frontEnd()
Creates a new instance of frontEnd


frontEnd

public frontEnd(boolean autodetect)

Parameters:
autodetect - Whether to autodetect the resolution at which to run the game.
Method Detail

getG

private java.awt.Graphics2D getG()
Returns the current graphics context.


setG

private void setG(java.awt.Graphics2D gr)
Sets the current graphics context.


initializeGraphics

private void initializeGraphics(boolean autodetect)

Parameters:
autodetect - Enable autodetection of graphics mode or not.

initializeFont

private void initializeFont()
Set the font file to use, over-riding the default font created during initialization.


drawScreen

public void drawScreen()
Fills the screen with background color and draws the outline of the playing area.


drawBoardMap

public void drawBoardMap()
Draws puyos according to the boardMap within the playing area drawn by drawScreen.


movementWrapper

public void movementWrapper(int direction)
Takes care of the movements on screen.

Converts the pair of puyos on screen to single puyos and operates on them.
Note that all calls to backEnd have been synchronized. This also ensures that though operations are performed on a pair, logically operations are performed individually on each puyo.

Parameters:
direction - Direction in which to move the pair, or rotate it clockwise.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
KeyEvent listener that is responsible for firing appropriate actions corresponding to the key pressed.


keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
KeyListener Interface: keyReleased. Ignored.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
KeyListener Interface: keyTyped. Ignored.

Specified by:
keyTyped in interface java.awt.event.KeyListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
From the MouseListener interface. MouseListener responsible for firing appropriate events corresponding to the key pressed.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
From the MouseListener interface. Ignored.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
From the MouseListener interface. Ignored.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
From the MouseListener interface. Ignored.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
From the MouseListener interface. Ignored.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
From the MouseMotionListener interface. Ignored.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
From the MouseMotionListener interface. Determines in which direction has the mouse moved and then recenters it.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

initializeMouse

private void initializeMouse(java.awt.Window window)
Initializes the mouse, recenters it and hides the mouse pointer.

Parameters:
window - Window for which to initialize the mouse.

recenterMouse

private void recenterMouse()
Uses the Robot class to try to position the mouse in the center of the screen.

Note that use of the Robot class may not be available on all platforms.


goodbye

public void goodbye()
Kills the thread and exits from the game while restoring the screen and unhiding the mouse pointer.


main

public static void main(java.lang.String[] args)
'Mainest' Method Of ALL :D

Parameters:
args - the command line arguments

Dev Ghai