scg/ch13/core/ScoreSprite

From FANG

Jump to: navigation, search

01 package scg.ch13.core;
02 
03 import fang2.sprites.StringSprite;
04 
05 /**
06  * Keep and display score. The {@link ScoreSprite} is based on the
07  * version presented in Chapter09. The score in this version is an
08  * integer (the number of rows removed in the game).
09  */
10 public class ScoreSprite
11   extends StringSprite {
12   /** current score */
13   private int score;
14 
15   /**
16    * Default constructor: 0/0 is initial score.
17    */
18   public ScoreSprite() {
19     this(0);
20   }
21 
22   /**
23    * Create new ScoreSprite with the given score.
24    *
25    @param  score  initial score
26    */
27   public ScoreSprite(int score{
28     this.score = score;
29     fixTextDisplay();
30   }
31 
32   /**
33    * Get the current score.
34    *
35    @return  the current score
36    */
37   public int getScore() {
38     return score;
39   }
40 
41   /**
42    * Increment the score by 1.
43    */
44   public void increment() {
45     increment(1);
46   }
47 
48   /**
49    * Increment the score by the given value.
50    *
51    @param  n  number to add to the current score
52    */
53   public void increment(int n{
54     score += n;
55     fixTextDisplay();
56   }
57 
58   /**
59    * Implementation method: display the currently recorded score.
60    */
61   private void fixTextDisplay() {
62     setText(Integer.toString(score));
63   }
64 }
65 
66 //Uploaded on Mon Mar 29 21:41:07 EDT 2010


Download/View scg/ch13/core/ScoreSprite.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games