scg/ch05/RollDice

From FANG

Jump to: navigation, search

01 package scg.ch05;
02 
03 import fang2.core.Game;
04 
05 /**
06  * Demonstration game using OneDie and EasyButton classes: Roll two big
07  * dice every time the button saying "Roll Dice" is pressed.
08  */
09 public class RollDice
10   extends Game {
11   /** the button at the bottom of the screen */
12   private EasyButton button;
13 
14   /** the left die */
15   private OneDie leftDie;
16 
17   /** the right die */
18   private OneDie rightDie;
19 
20   /**
21    * Advance the game one frame.
22    *
23    @param  secondsSinceLastCall  time since last advance
24    */
25   @Override
26   public void advance(double secondsSinceLastCall{
27     if (button.isPressed()) {
28       leftDie.roll();
29       rightDie.roll();
30     }
31   }
32 
33   /**
34    Set up the game for play. Initializes all of the sprites (either
35    * here or in other setup functions).
36    */
37   @Override
38   public void setup() {
39     button = new EasyButton();
40     button.setScale(0.5);
41     button.setLocation(0.50.85);
42     button.setColor(getColor("yellow"));
43     button.setTextColor(getColor("navy"));
44     addSprite(button);
45 
46     button.setText("Roll Dice");
47 
48     leftDie = new OneDie();
49     leftDie.setScale(0.33);
50     leftDie.setLocation(5.0 18.00.5);
51     addSprite(leftDie);
52 
53     rightDie = new OneDie();
54     rightDie.setScale(0.33);
55     rightDie.setLocation(13.0 18.00.5);
56     addSprite(rightDie);
57   }
58 }
59 
60 //Uploaded on Mon Mar 29 21:41:32 EDT 2010


Download/View scg/ch05/RollDice.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