scg/ch10/LetterSprite

From FANG

Jump to: navigation, search

001 package scg.ch10;
002 
003 import java.awt.Color;
004 
005 import fang2.core.Game;
006 import fang2.sprites.StringSprite;
007 
008 public class LetterSprite
009   extends StringSprite {
010   /** default color values; can be overridden in constructor */
011   public static Color DEFAULT_READY_COLOR = Game.getColor("SCG Red");
012   public static Color DEFAULT_USED_COLOR = Game.getColor("Gray");
013 
014   /** the letter this sprite displays/represents */
015   private final char letter;
016 
017   /** the colors used by this sprite to indicate its two states */
018   private Color readyColor;
019 
020   /** is the letter in the used (or ready) state */
021   private boolean used;
022 
023   private Color usedColor;
024 
025   /**
026    * Construct a new LetterSprite. Uses the default colors
027    */
028   public LetterSprite(char letter{
029     this(letter, DEFAULT_READY_COLOR, DEFAULT_USED_COLOR);
030   }
031 
032   /**
033    * Construct a new LetterSprite with the given letter and colors.
034    */
035   public LetterSprite(char letter, Color readyColor, Color usedColor{
036     super();
037     setMonospaced(true);
038     this.letter = letter;
039     setReadyColor(readyColor);
040     setUsedColor(usedColor);
041     setText(Character.toString(this.letter));
042     startReady();
043   }
044 
045   /**
046    * Get the letter stored in this letter sprite
047    *
048    @return  the letter shown by this letter sprite
049    */
050   public char getLetter() {
051     return letter;
052   }
053 
054   /**
055    * Return the ready color. Color used when the sprite is in ready
056    * state.
057    *
058    @return  color of sprite in ready state
059    */
060   public Color getReadyColor() {
061     return readyColor;
062   }
063 
064   /**
065    * Return the used color. Color used when the sprite is in used
066    * (selected) state.
067    *
068    @return  color of sprite in used state
069    */
070   public Color getUsedColor() {
071     return usedColor;
072   }
073 
074   /**
075    * Is the sprite in the ready state?
076    *
077    @return  true if ready (to be selected); false otherwise
078    */
079   public boolean isReady() {
080     return !used;
081   }
082 
083   /**
084    * Is the sprite in the used (already selected) state?
085    *
086    @return  true if used (no longer selectable); false otherwise
087    */
088   public boolean isUsed() {
089     return used;
090   }
091 
092   /**
093    Set the color to to use when in the ready state
094    *
095    @param  readyColor  the new ready state display color
096    */
097   public void setReadyColor(Color readyColor{
098     this.readyColor = readyColor;
099   }
100 
101   /**
102    Set the color to use when in the used state.
103    *
104    @param  usedColor  the new used state display color
105    */
106   public void setUsedColor(Color usedColor{
107     this.usedColor = usedColor;
108   }
109 
110   /**
111    * Unconditionally go into the ready state.
112    */
113   public void startReady() {
114     setColor(getReadyColor());
115     used = false;
116   }
117 
118   /**
119    * Unconditionally go into the used state.
120    */
121   public void startUsed() {
122     setColor(getUsedColor());
123     used = true;
124   }
125 }
126 
127 //Uploaded on Mon Mar 29 21:41:57 EDT 2010


Download/View scg/ch10/LetterSprite.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