TestMIDLet Coverage Report

Metrics: CCN: 1,769 Methods: 13
NCSS: 4,846 Classes: -
JVDC: 69.2% Packages: -
Need help?
Package # Classes Line Coverage Branch Coverage Method Coverage
KITExcellence 14
88.5% 
89.5% 
89.1% 

Class Line Coverage Branch Coverage Method Coverage
GameEngine.GameCanvasProxy
100% 
100% 
100% 

 1  
 package KITExcellence;
 2  
 import java.util.Enumeration;
 3  
 import java.util.Vector;
 4  
 
 5  
 import javax.microedition.lcdui.Displayable;
 6  
 import javax.microedition.lcdui.Graphics;
 7  
 import javax.microedition.lcdui.game.GameCanvas;
 8  
 
 9  
 /**
 10  
  * GameEngine class provides a basic game engine.
 11  
  */
 12  
 public class GameEngine implements Runnable {
 13  
 
 14  
         private GameCanvasProxy canvas;
 15  
         private Graphics graphics;
 16  
         
 17  
         private GameModel models;
 18  
         private Vector           views;
 19  
         private int                  fps;
 20  
         private GameTimer timer;
 21  
         
 22  
         private boolean paused;
 23  
         private boolean stoped;
 24  
         
 25  
         /**
 26  
          * Creates a Game Engine with the specified
 27  
          * Game model attached. The game runs at the
 28  
          * specified fps.
 29  
          * 
 30  
          * @param model game model.
 31  
          * @param fps frames per second.
 32  
          */
 33  
         protected GameEngine(GameModel model, int fps) {
 34  
                 this.canvas = new GameCanvasProxy();
 35  
                 this.views  = new Vector();
 36  
                 this.timer  = new GameTimer();
 37  
                 
 38  
                 this.graphics = this.canvas.getGraphics();
 39  
                 this.models   = model;
 40  
                 this.stoped          = true;
 41  
                 this.fps          = fps;
 42  
         }
 43  
 
 44  
         /**
 45  
          * Gets the drawing area.
 46  
          * 
 47  
          * @return drawing area.
 48  
          */
 49  
         public Displayable getDrawingArea() {
 50  
                 return this.canvas;
 51  
         }
 52  
         
 53  
         /**
 54  
          * Starts the Game.
 55  
          */
 56  
         public void start() {
 57  
                 if (stoped) {                        
 58  
                         Thread t = new Thread(this);
 59  
                         t.start();
 60  
                 }
 61  
         }
 62  
         
 63  
         /**
 64  
          * Stops the Game.
 65  
          */
 66  
         public void stop() {
 67  
                 if (!stoped) {                        
 68  
                         this.stoped = true;
 69  
                 }
 70  
         }
 71  
 
 72  
         /**
 73  
          * Resumes the Game.
 74  
          */
 75  
         public void resume() {
 76  
                 synchronized (this) {
 77  
                         if (paused) {
 78  
                                 this.paused = false;
 79  
                         }
 80  
                         this.notifyAll();
 81  
                 }
 82  
         }
 83  
         
 84  
         /**
 85  
          * Pauses the Game.
 86  
          */
 87  
         public void pause() {
 88  
                 synchronized (this) {                        
 89  
                         if (!paused) {
 90  
                                 this.paused = true;
 91  
                         }
 92  
                 }
 93  
         }
 94  
         
 95  
         /**
 96  
          * Attaches the specified view to the
 97  
          * engine.
 98  
          * 
 99  
          * @param view some view.
 100  
          */
 101  
         public void attach(GameView view) {
 102  
                 if (!this.views.contains(view)) {
 103  
                         this.views.addElement(view);
 104  
                 }
 105  
         }
 106  
         
 107  
         /**
 108  
          * Detaches the specified view from the
 109  
          * engine.
 110  
          * 
 111  
          * @param view some view.
 112  
          */
 113  
         public void detach(GameView view) {
 114  
                 this.views.removeElement(view);
 115  
         }
 116  
         
 117  
         /* (non-Javadoc)
 118  
          * @see javax.microedition.lcdui.game.GameCanvas#paint(javax.microedition.lcdui.Graphics)
 119  
          */
 120  
         public void paint(Graphics g) {
 121  
                 
 122  
                 float time_delta = 1.0f / fps;
 123  
                 int keys = this.canvas.getKeyStates();
 124  
                 
 125  
                 timer.tick(time_delta);
 126  
                 this.models.update(keys, this.canvas.getWidth(), this.canvas.getHeight(),
 127  
                                    time_delta);
 128  
                 
 129  
                 Enumeration enumeration = this.views.elements();
 130  
                 while (enumeration.hasMoreElements()) {
 131  
                         GameView view = (GameView) enumeration.nextElement();
 132  
                         view.render(g);
 133  
                 }
 134  
         }
 135  
         
 136  
         /**
 137  
          * Game Loop
 138  
          */
 139  
         public void run() {
 140  
                 this.stoped = false;
 141  
                 while (!stoped) {
 142  
                         
 143  
                         try {
 144  
                                 synchronized (this) {
 145  
                                         if (paused) {
 146  
                                                 this.wait();
 147  
                                         }
 148  
                                 }
 149  
                                 
 150  
                                 long interval = System.currentTimeMillis();
 151  
                                 graphics.setColor(255, 255, 255);
 152  
                                 graphics.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
 153  
                                 this.paint(this.graphics);
 154  
                                 this.canvas.flushGraphics();
 155  
                                 interval = System.currentTimeMillis() - interval;
 156  
                                 interval = ((1000 / fps) - interval);
 157  
                                 Thread.sleep(interval > 0 ? interval : 0x00);
 158  
                         } catch (InterruptedException e) {
 159  
                                 e.printStackTrace();
 160  
                         }
 161  
                 }
 162  
                 this.stoped = true;
 163  
         }
 164  
         
 165  
         public GameTimer getTimer() {
 166  
                 return timer;
 167  
         }
 168  
         
 169  
         private class GameCanvasProxy extends GameCanvas {
 170  
 
 171  1
                 protected GameCanvasProxy() {
 172  1
                         super(true);
 173  1
                 }
 174  
                 
 175  
                 /* (non-Javadoc)
 176  
                  * @see javax.microedition.lcdui.game.GameCanvas#getGraphics()
 177  
                  */
 178  
                 public Graphics getGraphics() {
 179  1
                         return super.getGraphics();
 180  
                 }
 181  
         }
 182  
         
 183  
 }

Legend:
Instrumented line CCN: Cyclomatic Complexity
Covered line NCSS: Non-Commenting Source Statement
Uncovered line JVDC: JaVaDoc Comment