ChrisHull/MontyhallExperiment

From ggc

Jump to: navigation, search

001 package ChrisHull;
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 Chull
011  */
012 public class MontyhallExperiment extends GameLoop
013 {
014   private int x;
015   private int stage;
016   private StringSprite Instructions;
017   /* got idea from KimMooney */
018   private Sound goodsound;
019   private Sound badsound;
020   private Sprite box1;
021   private Sprite box2;
022   private Sprite box3;
023   private Sprite box1L;
024   private Sprite box2L;
025   private Sprite box3L;
026   private Sprite prize1;
027   private Sprite prize2;
028   private Sprite prize3;
029 
030 
031 
032   public void startGame()
033   {
034     toggleAudible();
035     makeSprites();
036     addSprites();
037 
038   }
039   private void clickFirst()
040   {
041     Point2D.Double click=getPlayer().getMouse().getClickLocation();
042     //did they click at all
043     if(click!=null)
044     {
045       if(box1.intersects(click))
046       {
047 
048 
049         if (x==0)
050         {
051           canvas.removeSprite(box2);
052           canvas.removeSprite(box2L);
053           stage = 1;
054         }
055         else if (x==1)
056         {
057           canvas.removeSprite(box3);
058           canvas.removeSprite(box3L);
059           stage = 1;
060         }
061         else
062         {
063           canvas.removeSprite(box2);
064           canvas.removeSprite(box2L);
065           stage = 1;
066         }
067       }
068       if(box2.intersects(click))
069       {
070 
071         if (x==0)
072         {
073           canvas.removeSprite(box2);
074           canvas.removeSprite(box2L);
075           stage = 1;
076         }
077         else if (x==1)
078         {
079           canvas.removeSprite(box3);
080           canvas.removeSprite(box3L);
081           stage = 1;
082         }
083         else
084         {
085           canvas.removeSprite(box2);
086           canvas.removeSprite(box2L);
087           stage = 1;
088         }
089       }
090       if(box3.intersects(click))
091       {
092 
093         if (x==0)
094         {
095           canvas.removeSprite(box2);
096           canvas.removeSprite(box2L);
097           stage = 1;
098         }
099         else if (x==1)
100         {
101           canvas.removeSprite(box3);
102           canvas.removeSprite(box3L);
103           stage = 1;
104         }
105         else
106         {
107           canvas.removeSprite(box2);
108 http://ggc.javawide.org/index.php?title=ChrisHull/Montyhall&action=edit
109           canvas.removeSprite(box2L);
110           stage = 1;
111         }
112       }
113     }
114   }
115   private void clearDoors(String message, Sound sound)
116   {
117     canvas.removeSprite(box2);
118     canvas.removeSprite(box2L);
119 
120     canvas.removeSprite(box3);
121     canvas.removeSprite(box3L);
122 
123     canvas.removeSprite(box1);
124     canvas.removeSprite(box1L);
125 
126     Instructions.setText(message);
127     sound.play();
128     stage = 2;
129   }
130   private void clickSecond()
131   {
132 
133 
134     Instructions.setText("Stay or Switch?");
135     Point2D.Double click=getPlayer().getMouse().getClickLocation();
136     //did they click at all
137     if(click!=null)
138     {
139       if(box1.intersects(click))
140       {
141 
142 
143         if (x==0)
144         {
145           clearDoors("You Win" , goodsound);
146           stage= 2;
147         }
148         else if (x==1)
149         {
150           clearDoors("You Lose" , badsound);
151           stage = 2;
152         }
153         else
154         {
155           clearDoors("You Lose" , badsound);
156           stage = 2;
157         }
158       }
159       if(box2.intersects(click))
160       {
161 
162         if (x==0)
163         {
164           clearDoors("You Lose" , badsound);
165           stage = 2;
166         }
167         else if (x==1)
168         {
169           clearDoors("You Win" , goodsound);
170           stage = 2;
171         }
172         else
173         {
174           clearDoors("You Lose" , badsound);
175           stage = 2;
176         }
177       }
178       if(box3.intersects(click))
179       {
180 
181         if (x==0)
182         {
183           clearDoors("You Lose" , badsound);
184           stage = 2;
185         }
186         else if (x==1)
187         {
188           clearDoors("You Lose" , badsound);
189 
190           stage = 2;
191         }
192         else
193         {
194           clearDoors("You Win" , goodsound);
195           stage = 2;
196         }
197       }
198     }
199   }
200 
201 
202   private void makeSprites()
203   {
204     goodsound = new Sound(Wiki.getMedia("Clap.wav"));
205     badsound = new Sound(Wiki.getMedia("Boom.wav"));
206     Instructions=new StringSprite("Please choose your door");
207     Instructions.setScale(.5);
208     Instructions.setLocation(.3.3);
209     Instructions.setColor(Color.WHITE);
210 
211     prize1=new ImageSprite(Wiki.getMedia("P1.JPG"));
212     prize1.setScale(0.25);
213     prize1.setLocation(.200.5);
214 
215     prize2=new ImageSprite(Wiki.getMedia("P2.JPG"));
216     prize2.setScale(0.25);
217     prize2.setLocation(.500.5);
218 
219     prize3=new ImageSprite(Wiki.getMedia("P2.JPG"));
220     prize3.setScale(0.25);
221     prize3.setLocation(.800.5);
222 
223 
224     String text="heads";
225     x=random.nextInt(3);
226     if(x==0)
227     {
228       prize1.setLocation(.200.5);
229       prize2.setLocation(.500.5);
230       prize3.setLocation(.800.5);
231 
232     }
233     else if(x==1)
234     {
235       prize2.setLocation(.200.5);
236       prize1.setLocation(.500.5);
237       prize3.setLocation(.800.5);
238 
239     }
240     else
241     {
242       prize3.setLocation(.200.5);
243       prize2.setLocation(.500.5);
244       prize1.setLocation(.800.5);
245     }
246 
247     box1=new ImageSprite(Wiki.getMedia("Doorb.JPG"));
248     box1.setScale(0.25);
249     box1.setLocation(0.200.5);
250     box1L=new StringSprite("1");
251     box1L.setColor(Color.GREEN);
252     box1L.setScale(0.25);
253     box1L.setLocation(0.200.5);
254 
255     box2=new ImageSprite(Wiki.getMedia("Doorb.JPG"));
256     box2.setScale(0.25);
257     box2.setLocation(0.500.5);
258     box2L=new StringSprite("2");
259     box2L.setColor(Color.GREEN);
260     box2L.setScale(0.25);
261     box2L.setLocation(0.500.5);
262 
263     box3=new ImageSprite(Wiki.getMedia("Doorb.JPG"));
264     box3.setScale(0.25);
265     box3.setLocation(0.800.5);
266     box3L=new StringSprite("3");
267     box3L.setColor(Color.GREEN);
268     box3L.setScale(0.25);
269     box3L.setLocation(0.800.5);
270   }
271 
272   private void addSprites()
273   {
274     canvas.addSprite(Instructions);
275     canvas.addSprite(prize1);
276     canvas.addSprite(prize2);
277     canvas.addSprite(prize3);
278     canvas.addSprite(box1);
279     canvas.addSprite(box2);
280     canvas.addSprite(box3);
281     canvas.addSprite(box1L);
282     canvas.addSprite(box2L);
283     canvas.addSprite(box3L);
284 
285 
286   }
287 
288   public void advanceFrame(double timePassed)
289 
290   {
291     if (stage==0)
292     {
293       clickFirst();
294     }
295     else if (stage==1)
296     {
297       clickSecond();
298     }
299   }
300 }

Compiler Errors:
----------
1. ERROR in ChrisHull/MontyhallExperiment.java (at line 211)
	prize1=new ImageSprite(Wiki.getMedia("P1.JPG"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in ChrisHull/MontyhallExperiment.java (at line 215)
	prize2=new ImageSprite(Wiki.getMedia("P2.JPG"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
6 problems (6 errors)

Download/View ChrisHull/MontyhallExperiment.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