LuanNguyen/montyhallgame

From ggc

Jump to: navigation, search

001 package LuanNguyen;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * All about my game here.
010  @author Lnguyen1
011  */
012 public class montyhallgame extends GameLoop
013 {
014   /**an oval*/
015 
016   
017   private Sprite door2;
018   private Sprite door1;
019   private Sprite door3;
020   private StringSprite text;
021   private Sprite reddot;
022   private StringSprite text2;
023   private Sprite reddot2;
024   private StringSprite text3;
025   private Sprite greendot;
026   private StringSprite gametitle;
027   private StringSprite instruction;
028   private StringSprite instruction2;
029   private StringSprite instruction3;
030   private int q;
031     
032 
033   /**sets up the game*/
034   public void startGame()
035   {
036     makeSprites();
037     addSprites();
038   }
039   
040   /**makes the sprites*/
041   private void makeSprites()
042   {
043     door2=new RectangleSprite(1,1);
044     door2.setScale(0.25);
045     door2.setLocation(0.50.5);
046     
047     reddot=new OvalSprite(11);
048     reddot.setScale(0.1);
049     reddot.setLocation(0.50.5);
050     reddot.setColor(Color.RED);
051     
052     door1=new RectangleSprite(11);
053     door1.setScale(0.25);
054     door1.setLocation(0.20.5);
055     
056     door3=new RectangleSprite(11);
057     door3.setScale(0.25);
058     door3.setLocation(0.80.5);
059     
060     reddot2=new OvalSprite(11);
061     reddot2.setScale(0.1);
062     reddot2.setLocation(0.80.5);
063     reddot2.setColor(Color.RED);
064     
065     text=new StringSprite("2");
066     text.setScale(0.1);
067     text.setColor(Color.RED);
068     text.setLocation(0.50.5);
069     
070     greendot=new OvalSprite(11);
071     greendot.setScale(0.1);
072     greendot.setColor(Color.GREEN);
073     greendot.setLocation(0.20.5);
074     
075     text2=new StringSprite("1");
076     text2.setScale(0.1);
077     text2.setColor(Color.RED);
078     text2.setLocation(0.20.5);
079     
080     text3=new StringSprite("3");
081     text3.setScale(0.1);
082     text3.setColor(Color.RED);
083     text3.setLocation(0.80.5);
084     
085     gametitle=new StringSprite ("Let's Make A Deal");
086     gametitle.setScale(0.5);
087     gametitle.setColor(Color.BLUE);
088     gametitle.setLocation(0.50.1);
089     
090     instruction=new StringSprite("Inside one of these cases is a $1000 Prize");
091     instruction.setScale(0.8);
092     instruction.setColor(Color.RED);
093     instruction.setLocation(0.50.15);
094     
095     instruction2=new StringSprite("Inside the others case are either $0.1 or $1");
096     instruction2.setScale(0.8);
097     instruction2.setColor(Color.YELLOW);
098     instruction2.setLocation(0.50.2);
099     
100     instruction3=new StringSprite("Click on the case to open the $1000 case");
101     instruction3.setScale(0.8);
102     instruction3.setColor(Color.GREEN);
103     instruction3.setLocation(0.50.25);
104     
105     int q=random.nextInt(2);
106     
107   }
108   
109   /**adds the sprites to the screen*/
110   private void addSprites()
111   {
112     canvas.addSprite(reddot);
113     canvas.addSprite(reddot2);
114     canvas.addSprite(greendot);
115     canvas.addSprite(door2);
116     canvas.addSprite(door1);
117     canvas.addSprite(door3);
118     canvas.addSprite(text);
119     canvas.addSprite(text2);
120     canvas.addSprite(text3);
121     canvas.addSprite(gametitle);
122     canvas.addSprite(instruction);
123     canvas.addSprite(instruction2);
124     canvas.addSprite(instruction3);
125 
126   }
127   
128   /**handle input and game events*/
129   public void advanceFrame(double timePassed)
130   {
131     Point2D.Double click=getPlayer().getMouse().getClickLocation();
132     if(click!=null)
133     {
134       if(door2.intersects(click))
135       {
136         canvas.removeSprite(door3);
137       }
138       if(door1.intersects(click))
139       {
140         int q=random.nextInt(2);
141           if(q==0)
142           {
143             canvas.removeSprite(door2);
144           }
145           else if(q==1)
146           {
147             canvas.removeSprite(door3);
148           }
149       }
150       if(door3.intersects(click))
151       {
152         canvas.removeSprite(door2);
153 
154       }
155 
156     }
157     
158   }
159   
160   
161   
162   
163 }


Download/View LuanNguyen/montyhallgame.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