Commits

Anonymous committed 9889ee0

Documentations.

Comments (0)

Files changed (14)

src/Game/Ball.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 11/10/11
- * Time: 12:11 AM
+ * @author Meitian Huang
+ * @since 11/10/11
  */
 package Game;
 
 import com.jme3.math.Vector3f;
 import com.jme3.scene.Node;
 
-/*
- *   Ball - This class represents a ball in the game.
- *
- *   This class is a wrap of the RigidBodyControl offered by the engine
+/**
+ * Represents a ball in the game.
  */
 
 public class Ball extends RigidBody {
     public float getRadius() {
         return radius;
     }
+
+    public void zeroVelocity() {
+        ball.setLinearVelocity(Vector3f.ZERO);
+    }
 }

src/Game/Cell.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 4/10/11
- * Time: 11:51 PM
+ * @author Meitian Huang
+ * @since 4/10/11
  */
 
 package Game;
 
 /**
- * Cell - This class represent a single cell on the board which can have one
- * or more walls.
- * This class heavily uses bit operations along with arithmetic operations.
+ * Represent a single cell on the board during randomly maze generating.
  */
 
 public class Cell {
-    /* Here x and y represent the location of the cell on the board of which the
-     * is (0, 0)
+    /**
+     * x and y represent the location of the cell on the board of which the
+     * centre is (0, 0)
      */
     private float x, y;
     private float sideLength;
     /**
      * Visit a cell by setting its direction to the specified direction and 'push
      * down' the wall at that direction.
+     *
      * @param direction The direction we want to set up the cell for.
      */
     public void visit(int direction) {
         this.visited = true;
 
         /**
-        * & is another bit operation. Here, it is used to test if a certain bit is 1.
-        * e.g. 1010 & 1000 = 1000 > 0
-        */
+         * & is another bit operation. Here, it is used to test if a certain bit is 1.
+         * e.g. 1010 & 1000 = 1000 > 0
+         */
         if ((direction & wall) > 0) {
             wall -= direction;
         }
 
     /**
      * Converts the index of the cell to the coordinate on the board.
-     * @param indexI The first index of the cell
-     * @param indexJ The second index of the cell
+     *
+     * @param indexI  The first index of the cell
+     * @param indexJ  The second index of the cell
      * @param offsetI The first index of the central cell
      * @param offsetJ The second index of the central cell
      */

src/Game/DFS.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 4/10/11
- * Time: 9:46 PM
+ * @author Meitian Huang
+ * @since 4/10/11
  */
 
 package Game;
 import java.util.Random;
 
 /**
- * DFS - This class uses Depth-first search to generate a random maze.
+ * Uses Depth-first search to generate a random maze.
  */
 
 public class DFS {
     private Cell[][] grid;
 
     /**
-     * I will use bit operations.
      * Note:
      * N(north) is    0001_2,
      * E(east) is     0010_2,
      * S(south) is    0100_2,
      * W(west) is     1000_2.
      */
-    final int N = 1;
-    final int E = 2;
-    final int S = 4;
-    final int W = 8;
+    final private int N = 1;
+    final private int E = 2;
+    final private int S = 4;
+    final private int W = 8;
 
-    ArrayList<Integer> directions;
-    float unit;
+    private ArrayList<Integer> directions;
+    private float unit;
 
     public DFS(int level) {
         height = 1 + level * 2;
     }
 
     /**
-     * Adds the locations of horizontal walls and vertical walls in a random maze
-     * to the ArrayList.
+     * Adds the locations of horizontal walls and vertical walls in a random
+     * maze to the ArrayList.
      *
      * @param vWallLocations The ArrayList of locations of vertical walls
      * @param hWallLocations The ArrayList of locations of horizontal walls

src/Game/EndPoint.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 13/10/11
- * Time: 4:55 AM
+ * @author Meitian Huang
+ * @since 13/10/11
  */
 
 package Game;
 
 /**
- * EndPoint - This class represents the endPosition of a game.
- * An EndPoint is similar to a Hole but it has a different behaviour on
- * collision detection.
+ * Represents the end of a game.
  */
 public class EndPoint extends Hole {
     public EndPoint(Handler handler) {
         super(handler);
     }
 
+    /**
+     * Note:
+     * The ball collides with the end if the distance between their centres
+     * is less than the threshold.
+     *
+     * @param ball The ball we want to test for.
+     * @return If the end collides with the ball.
+     */
     @Override
     public boolean collideWith(Ball ball) {
-//        The ball collides with the end if the distance between their centres
-//        is less than a certain value.
         return location.distance(ball.getPhysicsLocation()) < threshold;
     }
 }

src/Game/Handler.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 18/10/11
- * Time: 10:44 PM
+ * @author Meitian Huang
+ * @since 18/10/11
  */
 
 package Game;
 import com.jme3.scene.Node;
 
 /**
- * Handler - A workaround for the fact that Java does not support callback
- * functions.
+ * Is a workaround for the fact that Java does not support callback functions.
  */
 public interface Handler {
     public void rotateBoard(float x, float y, float z);

src/Game/Hole.java

 /**
- * Created by IntelliJ IDEA.
- * User: Zunyi Liu, u4499582
- * Date: 29/09/11
- * Time: 12:09 AM
+ * @author Zunyi Liu, u4499582
+ * @since 29/09/11
  */
 
 package Game;
 import com.jme3.math.Vector3f;
 
 /**
- * Hole - represents a hole in the game.
+ * Represents the hole in the game.
  */
 
 public class Hole extends RigidBody {
-    private CylinderCollisionShape cylinderCollisionShape;
     private float radius;
 
     protected float threshold;
 
     @Override
     public void attach() {
-        cylinderCollisionShape =
-                new CylinderCollisionShape(
-                        new Vector3f(radius, handler.getBoardThickness(), 0.1f),
-                        1);
+        CylinderCollisionShape cylinderCollisionShape = new CylinderCollisionShape(
+                new Vector3f(radius, handler.getBoardThickness(), 0.1f),
+                1);
         handler.addShapeToBase(cylinderCollisionShape, location);
     }
 
+    /**
+     * Note:
+     * The ball collides with the hole if the distance between their centres
+     * is less than a certain value AND the magnitude of the linear speed of
+     * the ball is less than a certain value.
+     *
+     * @param ball The ball we want to test for.
+     * @return If the end collides with the ball.
+     */
     public boolean collideWith(Ball ball) {
-        /**
-         * The ball collides with the end if the distance between their centres
-         * is less than a certain value AND the velocity of the ball is less than
-         * a certain value.
-         */
         return location.distance(ball.getPhysicsLocation()) < threshold
                 && ball.getLinearVelocity() < 1.1f;
     }

src/Game/Key.java

 /**
- * Created by IntelliJ IDEA.
- * User: Zunyi Liu, u4499582
- * Date: 29/09/11
- * Time: 4:39 AM
+ * @author Zunyi Liu, u4499582
+ * @since 29/09/11
  */
 
 package Game;
 import com.jme3.input.controls.KeyTrigger;
 
 /**
- * Key - This class defines some keybindings in this game.
- * There are two types of keybindings defined, ActionListener and AnalogListener.
- * The differences between them include:
- * "Mappings registered to the AnalogListener are triggered repeatedly and
- * gradually while mappings registered to the ActionListener are digital
- * either-or actions"
+ * Registers keybindings for this game.
  */
 
 public class Key {
-    private Handler handler;
+    private final Handler handler;
 
     public Key(Handler handler) {
         this.handler = handler;
     }
 
-    private ActionListener actionListener = new ActionListener() {
+    /**
+     * Mappings registered to the AnalogListener are triggered repeatedly and
+     * gradually
+     */
+    private final ActionListener actionListener = new ActionListener() {
         public void onAction(String name, boolean pressed, float tpf) {
             if (name.equals("Reset") && !pressed) {
                 handler.resetGame();
         }
     };
 
-    private AnalogListener analogListener = new AnalogListener() {
+    /**
+     * Mappings registered to the AnalogListener are triggered repeatedly and
+     * gradually while mappings registered to the ActionListener are digital
+     * either-or actions
+     */
+    private final AnalogListener analogListener = new AnalogListener() {
         public void onAnalog(String name, float value, float tpf) {
             if (name.equals("Lefts")) {
                 handler.rotateBoard(0, 0, 0.0003f);

src/Game/Maze.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 4/10/11
- * Time: 9:46 PM
+ * @author Meitian Huang
+ * @since 4/10/11
  */
 
 package Game;
 
 import java.util.ArrayList;
 
+/**
+ * Is the main component of the game.
+ */
 public class Maze extends SimpleApplication {
 
     private BulletAppState bulletAppState;
     private CompoundCollisionShape base;
     private ArrayList<Hole> holes;
     private EndPoint end;
-    private ArrayList<Wall> walls;
     private BitmapText bitmapText;
     private int timeLeft;
     private boolean isLost;
 
 
     private void initWall() {
-        walls = new ArrayList<Wall>();
+        ArrayList<Wall> walls = new ArrayList<Wall>();
 
         for (Vector3f location : pref.vWallLocations) {
             Wall wall = new Wall(handler);
         initEnd();
 
         ball.setPhysicsLocation(pref.ballPosition);
+        ball.zeroVelocity();
     }
 }

src/Game/Pref.java

 /**
- * Created by IntelliJ IDEA.
- * User: Yiwei Xu, u4834608
- * Date: 29/09/11
- * Time: 1:15 AM
+ * @author Yiwei Xu
+ * @since 29/09/11
  */
 
 package Game;
 import java.util.ArrayList;
 
 /**
- * Pref - This class contains every information the game needs to run.
+ * Generates (almost) every information the game needs to run.
  */
 public class Pref {
     protected int level;
-    protected float sensitivity;
+    protected final float sensitivity;
 
-    protected float ballRadius;
+    protected final float ballRadius;
     protected Vector3f ballPosition;
-    protected float ballMass;
 
-    private float epsilon = 0.001f;
+    private final float epsilon = 0.001f;
 
     protected ArrayList<Vector3f> vWallLocations, hWallLocations;
     protected BoxCollisionShape vWallShape, hWallShape;
 
-    protected float boardLength, boardWidth, boardHeight;
+    protected final float boardLength, boardHeight;
+    protected float boardWidth;
 
     protected ArrayList<Vector3f> holeCentres;
     protected Vector3f endPosition;
 
     private DFS dfs;
-    protected boolean bugMe = true;
+    protected final boolean bugMe = true;
 
     public Pref() {
         level = 1;
         sensitivity = 1;
         ballRadius = 0.04f;
-        ballMass = 2f;
         boardLength = 1;
         boardHeight = 0.02f;
         init();
      */
     public void init() {
         generateWalls();
+
         boardWidth = dfs.getHeight() / dfs.getWidth();
         endPosition = new Vector3f(dfs.randomX(), 0, dfs.randomY());
-        randomiseBallLocation();
 
+        randomiseBallLocation();
+        generateHoles();
+    }
 
+    private void generateHoles() {
         holeCentres = new ArrayList<Vector3f>();
         for (int i = 0; i < (5 - level); i++) {
             Vector3f vector3f;
      */
     public void randomiseBallLocation() {
         ballPosition = new Vector3f();
+        ballPosition.setY(ballRadius * 1.1f);
         do {
             ballPosition.setX(dfs.randomX());
             ballPosition.setZ(dfs.randomY());
         }
-        while ((Math.abs(ballPosition.getX() - endPosition.getX()) < epsilon) && (Math.abs(ballPosition.getZ() - endPosition.getZ()) < epsilon));
-        ballPosition.setY(ballRadius * 1.1f);
+        while (equalVector(ballPosition, endPosition));
     }
 
     /**
         Vector3f hWallDimension = new Vector3f(dfs.getUnit(), 0.2f, boardHeight);
         vWallShape = new BoxCollisionShape(vWallDimension);
         hWallShape = new BoxCollisionShape(hWallDimension);
-
     }
 
+    /**
+     * Increases the level by one if the current level is less than five.
+     */
     public void increaseLevel() {
-        this.level += 1;
-        init();
+        if (level < 5) {
+            this.level += 1;
+        }
     }
 
-    public boolean equalVector(Vector3f a, Vector3f b) {
-        return Math.abs(a.getX() - b.getX()) < epsilon
-                && Math.abs(b.getZ() - b.getZ()) < epsilon;
+    /**
+     * Tests if two vectors are overlapping on the board
+     *
+     * @param vectorA The first vector
+     * @param vectorB The second vector
+     * @return True if two vectors are overlapping
+     */
+    public boolean equalVector(Vector3f vectorA, Vector3f vectorB) {
+        return Math.abs(vectorA.getX() - vectorB.getX()) < epsilon
+                && Math.abs(vectorB.getZ() - vectorB.getZ()) < epsilon;
     }
 
     public float getUnit() {
 
     --Contributors--
 Meitian Huang   u4700480
+Zunyi Liu       u4499582
+Yiwei Xu        u4834608
 
 
     --License--

src/Game/RigidBody.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 10/10/11
- * Time: 10:53 PM
+ * @author Meitian Huang
+ * @since 10/10/11
  */
 package Game;
 
 import com.jme3.math.Vector3f;
 
 /**
- * RigidBody - This class represents every possible rigid body in the game.
+ * Represents the rigid body in the game.
  */
 public abstract class RigidBody {
-    Handler handler;
+    final Handler handler;
     Vector3f location;
 
     /**
      * Sets up the callback functions.
      *
-     * @param handler A set of callback functions that will be used later by the
-     * object.
+     * @param handler A set of callback functions that will be used later by
+     *                the object.
      */
     public RigidBody(Handler handler) {
         this.handler = handler;

src/Game/Score.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang, u4700480
- * Date: 13/10/11
- * Time: 2:17 AM
+ * @author Meitian Huang
+ * @since 13/10/11
  */
 package Game;
 
 /**
- * Score - represents the score of the game.
+ * Represents the score of the game.
  */
 
 public class Score {
     private int score;
-    private Handler handler;
+    private final Handler handler;
 
     public Score(Handler handler) {
         score = 10;

src/Game/Starter.java

 /**
- * Created by IntelliJ IDEA.
- * User: Meitian Huang
- * Date: 29/09/11
- * Time: 12:09 AM
+ * @author Meitian Huang, u4700480
+ * @since 29/09/11
  */
 
 package Game;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+
 public class Starter {
     public static void main(String[] args) {
 

src/Game/Wall.java

 /**
- * User:
- * Date: 27/09/11
- * Time: 9:15 PM
+ * @author Meitian Huang
+ * @since 27/09/11
  */
 
 package Game;
 
 import com.jme3.bullet.collision.shapes.BoxCollisionShape;
 
+/**
+ * Represents a wall, either inner or outer, in the game.
+ */
 public class Wall extends RigidBody {
-    BoxCollisionShape wall;
+    private BoxCollisionShape wall;
 
     public Wall(Handler handler) {
         super(handler);