Example/RandomNumber

From ggc

Jump to: navigation, search

01 package Example;
02 
03 import wiki.Wiki;
04 import fang.*;
05 import java.awt.*;
06 import java.awt.geom.*;
07 
08 /**
09  * All about my game here.
10  @author Jam Jenkins
11  */
12 public class RandomNumber extends GameLoop
13 {
14   /**an oval*/
15   private StringSprite oval;
16   
17   /**sets up the game*/
18   public void startGame()
19   {
20     makeSprites();
21     addSprites();
22   }
23   
24   /**makes the sprites*/
25   private void makeSprites()
26   {
27     //String text="x="+random.nextInt(5);
28     String text="heads";
29     int x=random.nextInt(2);
30     if(x==0)
31     {
32       text="tail";
33     }
34     oval=new StringSprite(text);
35     oval.setScale(0.75);
36     oval.setLocation(0.50.5);
37   }
38   
39   /**adds the sprites to the screen*/
40   private void addSprites()
41   {
42     canvas.addSprite(oval);
43   }
44   
45   /**handle input and game events*/
46   public void advanceFrame(double timePassed)
47   {
48     oval.setLocation(getPlayer().getMouse().getLocation());
49     if(getPlayer().getMouse().getClickLocation()!=null)
50     {
51       oval.setScale(random.nextDouble());
52     }
53     if(getPlayer().getKeyboard().getLastKey()=='r')
54     {
55       oval.setColor(Color.RED);
56     }
57     if(getPlayer().getKeyboard().getLastKey()=='w')
58     {
59       oval.setColor(Color.WHITE);
60     }
61   }
62 }


Download/View Example/RandomNumber.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