PuyoPuyo Documentation


puyopuyo
Class backEnd

java.lang.Object
  extended by puyopuyo.puyo
      extended by puyopuyo.backEnd
Direct Known Subclasses:
frontEnd

public class backEnd
extends puyo

Holds all the logic that drives the game.

The main engine of the game is comprised of the following four methods:


Field Summary
private  puyo[][] boardMap
          This two dimensional array is the heart of the game.
private  boolean gameOver
          A boolean value that tells whether the game is over or not.
private  java.util.Stack nextSetOfPuyos
          Holds the next set of puyos which have to be settled down and then checks have to be made once they cannot move downwards anymore.
(package private)  int popmin
          Holds the minimum length of the chain in terms of puyos that will cause puyos to be popped from the board.
private  puyo[] puyoPair
          Stores the pair of puyos pushed onto the board.
(package private)  int puyosOnXAxis
          Holds the number of puyos on X Axis.
(package private)  int puyosOnYAxis
          Holds the number of puyos on Y Axis.
private  java.util.Stack puyosToBePopped
          Holds all the puyos to be removed from the boardMap due to them forming a chain of popmin length.
private  java.util.HashSet removePuyos
          Holds the puyos to be popped from boardMap as they form chains of length >= popmin.
private  int score
          Integer value that holds the score of the game.
 
Constructor Summary
backEnd()
          Creates a new instance of backEnd, initialises the board and pushes a pair of puyos in boardMap using pushPuyos.
 
Method Summary
 puyo[][] getBoardMap()
          Returns boardMap.
private  puyo getNewPuyo()
          Generates a new puyo and randomly assigns color to the generated puyo.
 puyo[] getPuyoPair()
          Returns a pair of puyos in form of an one dimensional array.
 int getScore()
          Returns the current score.
private  boolean insertInBoardMap(puyo p, int X, int Y)
          Returns true if insertion successfully takes place in boardMap.
 boolean isGameOver()
          Logically tells if the game is over or not by returning the (boolean) value of gameOver.
 boolean moveDown(puyo p)
          Moves the puyo passed as parameter one positon down in boardMap.
 boolean moveLeft(puyo p)
          Moves the puyo passed as parameter one positon to left in boardMap.
 boolean moveRight(puyo p)
          Moves the puyo passed as parameter one positon to right in boardMap.
private  puyo[] popAndMarkDroppings(java.util.HashSet deletePuyos)
          Pop the puyos marked by probe(puyo) and also identifies all the puyos which have to be moved down because of popping.
 void popPuyos(puyo[] p)
          It is the entry point for frontEnd.
private  java.util.HashSet probe(puyo p)
          Returns the set of puyos to be moved down because of chains formed by puyo, being passed as the argument.
 void pushPuyos()
          Pushes a new pair of puyos in boardMap at the top of the board.
private  void removeFromBoardMap(int X, int Y)
          Removes puyo from the boardMap.
 void rotate(puyo[] p)
          Rotates clockwise the puyo p[1] around p[0].
 void setGameOver(boolean status)
          This method allows frontEnd to set the gameOver to true.
private  void settleDown(puyo p)
          Settles the puyo passed as parameter down to the floor and also all the puyos above it.
 
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

puyosOnXAxis

int puyosOnXAxis
Holds the number of puyos on X Axis. Modify this value to effectively change the size of the board. Logic has been made to depend on it.


puyosOnYAxis

int puyosOnYAxis
Holds the number of puyos on Y Axis. Modify this value to effectively change the size of the board. Logic has been made to depend on it.


popmin

int popmin
Holds the minimum length of the chain in terms of puyos that will cause puyos to be popped from the board.


puyoPair

private puyo[] puyoPair
Stores the pair of puyos pushed onto the board.


score

private int score
Integer value that holds the score of the game. Popping of one puyo adds 10 to the current score.


gameOver

private boolean gameOver
A boolean value that tells whether the game is over or not.

This value is set in two cases -

    1. When pushPuyos is unable to push a pair on the board.
      When the user hits the Esc key, i.e. s/he wants to exit from the game.

  • boardMap

    private puyo[][] boardMap
    This two dimensional array is the heart of the game. It logically represents the game's board in memory in form of an array whose width is equal to puyosOnXAxis and height is equal to puyosOnYAxis.


    puyosToBePopped

    private java.util.Stack puyosToBePopped
    Holds all the puyos to be removed from the boardMap due to them forming a chain of popmin length.


    nextSetOfPuyos

    private java.util.Stack nextSetOfPuyos
    Holds the next set of puyos which have to be settled down and then checks have to be made once they cannot move downwards anymore.


    removePuyos

    private java.util.HashSet removePuyos
    Holds the puyos to be popped from boardMap as they form chains of length >= popmin.

    Constructor Detail

    backEnd

    public backEnd()
    Creates a new instance of backEnd, initialises the board and pushes a pair of puyos in boardMap using pushPuyos. boardMap is a two dimensional array that the heart of the game. It logically represents the game's board in memory in form of an array whose width is equal to puyosOnXAxis and height is equal to puyosOnYAxis.

    Method Detail

    getPuyoPair

    public puyo[] getPuyoPair()
    Returns a pair of puyos in form of an one dimensional array.


    getScore

    public int getScore()
    Returns the current score. score is incremented by 10 points when one puyo is popped.


    isGameOver

    public boolean isGameOver()
    Logically tells if the game is over or not by returning the (boolean) value of gameOver.


    setGameOver

    public void setGameOver(boolean status)
    This method allows frontEnd to set the gameOver to true.

    Game ends in two cases -

    1. When pushPuyos is unable to push a pair on the board.
    2. When the user hits the Esc key, i.e. s/he wants to exit from the game.

    Parameters:
    status - 'status' of the game to be copied to gameOver.

    insertInBoardMap

    private boolean insertInBoardMap(puyo p,
                                     int X,
                                     int Y)
    Returns true if insertion successfully takes place in boardMap.

    Parameters:
    p - Puyo to insert in boardMap
    X - X Co-ordinate of the insertion point.
    Y - Y co-ordinate of the insertion point.
    Returns:
    Returns if the insertion was successful or not.

    removeFromBoardMap

    private void removeFromBoardMap(int X,
                                    int Y)
    Removes puyo from the boardMap.

    Parameters:
    X - X co-ordinate in boardMap from which to remove puyo.
    Y - Y co-ordinate of boardMap from which to remove the puyo.

    getBoardMap

    public puyo[][] getBoardMap()
    Returns boardMap. One of the main purposes of this method is to provide a two dimensional array to frontEnd for printing the board onto screen. drawBoardMap uses this method to extract the logical boardMap and print it onto the screen.

    Returns:
    boardMap

    getNewPuyo

    private puyo getNewPuyo()
    Generates a new puyo and randomly assigns color to the generated puyo.

    Returns:
    A puyo with randomly generated colors.

    pushPuyos

    public void pushPuyos()
    Pushes a new pair of puyos in boardMap at the top of the board. If no new pair can be pushed, gameOver is set true via setGameOver.


    moveLeft

    public boolean moveLeft(puyo p)
    Moves the puyo passed as parameter one positon to left in boardMap. It also updates the property of the puyo after successfully moving it.

    Parameters:
    p - puyo to be moved left.
    Returns:
    True if puyo was successfully moved and its property updated, else false

    moveRight

    public boolean moveRight(puyo p)
    Moves the puyo passed as parameter one positon to right in boardMap. It also updates the property of the puyo after successfully moving it.

    Parameters:
    p - Puyo to be moved right.
    Returns:
    True if puyo was successfully moved and its property updated, else false

    moveDown

    public boolean moveDown(puyo p)
    Moves the puyo passed as parameter one positon down in boardMap. It also updates the property of the puyo after successfully moving it.

    Parameters:
    p - Puyo to be moved down.
    Returns:
    True if puyo was successfully moved and its property updated, else false

    rotate

    public void rotate(puyo[] p)
    Rotates clockwise the puyo p[1] around p[0].

    DETAILED DESCRIPTION:
    p[0] will always be the pivot around which p[1] will rotate
    Determine the orientation of the pair: HORIZONTAL or VERTICAL
    Determine position of p[1] : NORTH EAST SOUTH or WEST
    Move according to the determined position.
    Simple??

    Parameters:
    p - Pair of puyos to rotate.

    popPuyos

    public void popPuyos(puyo[] p)
    It is the entry point for frontEnd.

    It also acts as 'manager', controlling the three methods that comprise the core logic:

    Parameters:
    p - Puyo for which chain has to be identified and popped from the board.

    settleDown

    private void settleDown(puyo p)
    Settles the puyo passed as parameter down to the floor and also all the puyos above it.

    Parameters:
    p - Puyo to be moved down.

    probe

    private java.util.HashSet probe(puyo p)
    Returns the set of puyos to be moved down because of chains formed by puyo, being passed as the argument.

    Parameters:
    p - Puyo for which chains on the board have to be identified.
    Returns:
    Set of puyos to be removed from the boardMap.

    popAndMarkDroppings

    private puyo[] popAndMarkDroppings(java.util.HashSet deletePuyos)
    Pop the puyos marked by probe(puyo) and also identifies all the puyos which have to be moved down because of popping.

    Parameters:
    deletePuyos - Puyos which have to be deleted from the boardMap.
    Returns:
    Puyos which have to be moved down.

    Dev Ghai