intro/DisappearingAct

From ggc

Jump to: navigation, search

001 package intro;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author Dr. Jam Jenkins
010  */
011 public class DisappearingAct extends Game
012 {
013   private int numClicks;
014   private OvalSprite oval;
015   private StringSprite alert;
016 
017   /**sets up the game*/
018   public void setup()
019   {
020     numClicks=0;
021     oval=new OvalSprite(0.250.25);
022     oval.setLocation(0.50.5);
023     addSprite(oval);
024 
025     alert=new StringSprite("Alert");
026     alert.setWidth(0.5);
027     alert.setLocation(0.50.8);
028     addSprite(alert);
029     alert.setVisible(false);
030   }
031 
032   private void makeGreen()
033   {
034     oval.setVisible(true);
035     oval.setLocation(0.50.75);
036     oval.setColor(getColor("green"));
037   }
038   private void makeYellow()
039   {
040     oval.setVisible(true);
041     oval.setLocation(0.50.5);
042     oval.setColor(getColor("yellow"));
043   }
044   private void makeRed()
045   {
046     oval.setVisible(true);
047     oval.setLocation(0.50.25);
048     oval.setColor(getColor("red"));
049   }
050 
051   private void makeInvisible()
052   {
053     oval.setVisible(false);
054     numClicks=-1;
055   }
056 
057   private void placeAndColor(double x, double y, Color color)
058   {
059     oval.setVisible(true);
060     oval.setLocation(x, y);
061     oval.setColor(color);
062   }
063 
064   public boolean isYellow()
065   {
066     if(oval.getColor().equals(getColor("yellow")))
067     {
068       return true;
069     }
070     else
071     {
072       return false;
073     }
074   }
075 
076   /**handle input and game events*/
077   public void advance()
078   {
079     if(isYellow()==true)
080     {
081       alert.setVisible(true);
082     }
083     else
084     {
085       alert.setVisible(false);
086     }
087     if(getClick2D()!=null  && oval.intersects(getClick2D()))
088     {
089       numClicks++;
090     }
091     if(numClicks==0)
092     {
093       //makeGreen();
094       placeAndColor(0.50.75, getColor("green"));
095     }
096     else if(numClicks==1)
097     {
098       //makeYellow();
099       placeAndColor(0.50.5, getColor("yellow"));
100     }
101     else if(numClicks==2)
102     {
103       //makeRed();
104       placeAndColor(0.50.25, getColor("red"));
105       numClicks=-1;
106     }
107     else if(numClicks==3)
108     {
109       makeInvisible();
110     }
111   }
112 }


Download/View intro/DisappearingAct.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