[xplode~subversion:18] code clean up...

  • From: ktoso@kenai.com
  • To: commits@xplode.kenai.com
  • Subject: [xplode~subversion:18] code clean up...
  • Date: Thu, 20 Aug 2009 14:44:48 +0000

Project:    xplode
Repository: subversion
Revision:   18
Author:     ktoso
Date:       2009-08-20 10:14:07 UTC
Link:       

Log Message:
------------
code clean up...


Revisions:
----------
18


Modified Paths:
---------------
Xplode/src/xplode/model/Xplodable.java
Xplode/src/xplode/ui/XplodeCanvas.java
Xplode/src/xplode/tools/Tools.java
Xplode/src/xplode/ui/BgCanvas.java
Xplode/src/xplode/model/Dot.java
Xplode/src/xplode/ui/MenuCanvas.java
Xplode/src/xplode/XplodeMidlet.java


Diffs:
------
Index: Xplode/src/xplode/model/Dot.java
===================================================================
--- Xplode/src/xplode/model/Dot.java    (revision 17)
+++ Xplode/src/xplode/model/Dot.java    (revision 18)
@@ -77,9 +77,6 @@
 
         this.field = field;
 
-        x = Tools.nextInt(Resources.SCREEN_WIDTH);
-        y = Tools.nextInt(Resources.SCREEN_HEIGHT);
-
         vX = (Tools.nextInt(1) - 2) * Resources.DOT_BASE_SPEED + 
Tools.nextInt(Resources.DOT_MAX_SPEED);
         vY = (Tools.nextInt(1) - 2) * Resources.DOT_BASE_SPEED + 
Tools.nextInt(Resources.DOT_MAX_SPEED);
 
@@ -171,6 +168,9 @@
         return imploding;
     }
 
+    /**
+     * @return the dots current radius
+     */
     public int getRadius() {
         return radius;
     }
@@ -200,10 +200,16 @@
         return false;
     }
 
+    /**
+     * Checks if the dot can move
+     */
     public boolean canMove() {
         return move;
     }
 
+    /**
+     * Toggles the ability to move for this dot
+     */
     public void setMove(boolean can) {
         move = can;
     }
@@ -288,6 +294,12 @@
         return color;
     }
 
+    /**
+     * Checks if the dot is "dead",
+     * a dead dot will not be drawn on the gameplay field
+     * @return true if the dot is alive, and should be drawn on the field,
+     * false otherwhise
+     */
     public boolean isDead() {
         if (radius <= 0) {
             return true;
@@ -296,6 +308,10 @@
         return false;
     }
 
+    /**
+     * @return true if the dot will explode when touched by another dot
+     * false otherwhise
+     */
     public boolean isXplodeOnTouch() {
         return xplodeOnTouch;
     }
@@ -304,6 +320,9 @@
         this.xplodeOnTouch = xplodeOnTouch;
     }
 
+    /**
+     * Searches
+     */
     private void handleBallsCollision() {
         //Xplode colliding dots
         int coutDot = field.countDots();
Index: Xplode/src/xplode/model/Xplodable.java
===================================================================
--- Xplode/src/xplode/model/Xplodable.java      (revision 17)
+++ Xplode/src/xplode/model/Xplodable.java      (revision 18)
@@ -20,17 +20,26 @@
 import javax.microedition.lcdui.Graphics;
 
 /**
- * Defines all the methods explodable object have to have.
+ * Defines all the methods explodable object need to implement
  * @author ktoso
  */
 public interface Xplodable {
+    /** Initialize the explosion of an object */
     public void initXplode();
+    /** Process explosion connected data */
     public void processXplode();
 
+    /** draw the object on the screen */
     public void draw(Graphics g);
 
+    /**
+     * Checks if the object is exploding
+     * @return true if the object is exploding, false otherwise
+     */
     public boolean isXploding();
+    /**
+     * Checks if the object is imploding
+     * @return true if the object is imploding, false otherwise
+     */
     public boolean isImploding();
-    
-    //public void drawXplosion(Graphics g); //dropped
 }
Index: Xplode/src/xplode/tools/Tools.java
===================================================================
--- Xplode/src/xplode/tools/Tools.java  (revision 17)
+++ Xplode/src/xplode/tools/Tools.java  (revision 18)
@@ -8,7 +8,7 @@
 import java.util.Random;
 
 /**
- *
+ * A simple tools helper class
  * @author ktoso
  */
 public class Tools {
@@ -17,7 +17,14 @@
     private Tools(){
         //dont allow instances
     }
-
+    /**
+     * Can be used to provide one single Random instance across all other 
classes.
+     * I found this apparoach to give better results than creating a local 
Random
+     * in each of the Dot classes, as that method didn't provide enought 
"random"
+     * places for the dot's to be initialy positioned...
+     *
+     * @return java.util.Random instance - always the same one
+     */
     private static Random getRand(){
         if(rand == null){
             rand = new Random(System.currentTimeMillis());
@@ -25,10 +32,23 @@
         return rand;
     }
 
+    /**
+     * Simple helper method<br/>
+     * Calls: Random.nextInt();
+     *
+     * @return a "random" integer
+     */
     public static int nextInt(){
         return getRand().nextInt();
     }
 
+    /**
+     * Simple helper method<br/>
+     * Calls: Random.nextInt();
+     *
+     * @param n the number "cap", must be posotive
+     * @return a "random" integer, between 0 and n
+     */
     public static int nextInt(int n){
         return getRand().nextInt(n);
     }
Index: Xplode/src/xplode/XplodeMidlet.java
===================================================================
--- Xplode/src/xplode/XplodeMidlet.java (revision 17)
+++ Xplode/src/xplode/XplodeMidlet.java (revision 18)
@@ -78,6 +78,9 @@
         }
     }
 
+    /**
+     * Used to switch between currently shown screens, unused screens are 
nulled
+     */
     public void switchCanvas(int canvas_ID) {
         switch (canvas_ID) {
             case Resources.COMMAND_LOAD_MENU:
Index: Xplode/src/xplode/ui/MenuCanvas.java
===================================================================
--- Xplode/src/xplode/ui/MenuCanvas.java        (revision 17)
+++ Xplode/src/xplode/ui/MenuCanvas.java        (revision 18)
@@ -131,6 +131,9 @@
         running = false;
     }
 
+    /**
+     * The main loop
+     */
     public void run() {
         while (running) {
             process();
Index: Xplode/src/xplode/ui/BgCanvas.java
===================================================================
--- Xplode/src/xplode/ui/BgCanvas.java  (revision 17)
+++ Xplode/src/xplode/ui/BgCanvas.java  (revision 18)
@@ -121,7 +121,7 @@
     }
 
     public synchronized Dot getDot(int i) {
-        if (i > 0 || i < dots.length) {
+        if (i > 0 || i < getDots().length) {
             if (BG_STYLE == Resources.BG_STYLE_MENU && 
dots[i].isDead())//only for the MENU background - in order to keep it alive 
and fun!
             {
                 dots[i] = new Dot(this);//rly good?
@@ -135,9 +135,9 @@
     }
 
     public synchronized int countDots() {
-        return dots.length;
+        return getDots().length;
     }
-
+    
     /**
      * Process dot movement etc
      */
Index: Xplode/src/xplode/ui/XplodeCanvas.java
===================================================================
--- Xplode/src/xplode/ui/XplodeCanvas.java      (revision 17)
+++ Xplode/src/xplode/ui/XplodeCanvas.java      (revision 18)
@@ -97,7 +97,10 @@
         this.midlet.commandAction(c, d);
     }
 
-    public void doInit() {
+    /**
+     * Initializes the object
+     */
+    public final void doInit() {
         running = true;
         pause = false;
         chain_started = false;
@@ -114,10 +117,16 @@
         t.start();
     }
 
+    /**
+     * Stops the main game loop
+     */
     public void doDie() {
         running = false;
     }
 
+    /**
+     * The main loop
+     */
     public void run() {
         points = 0;
         while (running) {
@@ -145,7 +154,7 @@
 
         int countDead = 0;
 
-        for (int i = chain_started ? 0 : 1; i < getMobiles().length; i++) {
+        for (int i = chain_started ? 0 : 1; i < getDots().length; i++) {
             dots[i].move();
 
             //TODO: count deads, if deads == xploded -> end the game
@@ -203,7 +212,7 @@
                 }
             }
         } else {
-            for (int i = chain_started ? 0 : 1; i < getMobiles().length; 
i++) {
+            for (int i = chain_started ? 0 : 1; i < getDots().length; i++) {
                 dots[i].draw(g);
             }
         }
@@ -212,6 +221,9 @@
         drawSpriteLifes(g);
     }
 
+    /**
+     * Draws the big chain number between levels, using the apropriate Sprite
+     */
     private void drawSpriteNumber(Graphics g, int numb) {
         //TODO: could use fading (Gfx.blend) here!
         int i = 0;
@@ -226,10 +238,14 @@
         }
     }
 
+    /**
+     * Draws the chain status numbers using a sprite
+     * (Originaly just created to test such an apparoach out, can be OK but 
not always I guess)
+     */
     private void drawSpriteChainStatus(Graphics g) {
         //TODO: could use fading (Gfx.blend) here!
         int i = 0;
-        int num = countMobiles();
+        int num = countDots();
         while (num > 0) {
             //gets digits starting from the end of the integer
             int digit = num % 10;
@@ -273,11 +289,10 @@
     /**
      * Trigger events if the pointer was released over a "button"
      */
-    private void triggerPointer() {
-        if(level_delay > 0)
+    private synchronized void triggerPointer() {
+        if(level_delay > 0){
             return;
-        
-        if (!chain_started) {
+        }else if (!chain_started) {
             dots[0] = new Dot(this, pX, pY);
             dots[0].setMove(false);
             dots[0].setXplodeOnTouch(true);
@@ -288,10 +303,17 @@
         }
     }
 
+    /**
+     * Toggles the execution of the main game loop
+     */
     public void doPause() {
         pause = !pause;
     }
 
+    /**
+     * Triggers an gameover event, it also does check if the Highscore was 
broken.
+     * Highscore is not yet implemented though...
+     */
     private void gameOver() {
         if(Highscores.isHighScore(dots_xploded)){
             //TODO: implement me
@@ -300,6 +322,10 @@
         }
     }
 
+    /**
+     * Initializes the passed level. Creates new dots and so on...
+     * @param level the level number to be initialised, counting from 0
+     */
     private synchronized void initLevel(int level) {
         super.doInit();
 
@@ -329,10 +355,10 @@
     }
 
     /**
-     * Initialises when needed and returns the mobiles array
-     * @return array of Mobile objects on the current field
+     * Initialises when needed and returns the Dots array
+     * @return array of Dot objects on the current field
      */
-    public synchronized Dot[] getMobiles() {
+    public synchronized Dot[] getDots() {
         if (dots == null) {
             dots = new Dot[Resources.BG_STYLE_MENU_DOTS + 
Tools.nextInt(Resources.BG_STYLE_MENU_DOTS_EXTRA)];
             for (int i = 0; i < dots.length; i++) {
@@ -350,7 +376,10 @@
         return dots;
     }
 
-    public synchronized Dot getMobile(int i) {
+    /**
+     *
+     */
+    public synchronized Dot getDot(int i) {
         if (i > 0 || i < dots.length) {
             return dots[i];
         } else {
@@ -358,10 +387,18 @@
         }
     }
 
-    public synchronized int countMobiles() {
+    /**
+     * Counts dots array lenght
+     * @return dots array lenght
+     */
+    public synchronized int countDots() {
         return dots.length;
     }
 
+    /**
+     * Substracts one live from the players lifes. If lifes == 0, triggers 
gameOver()
+     * @see gameOver()
+     */
     private void loseLife() {
         if (lifes > 0) {
             --lifes;





[xplode~subversion:18] code clean up...

ktoso 08/20/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close