mcclarty/Monty Hall

From ggc

Jump to: navigation, search

John,

The problem is that you have code blocks that do not belong to methods. For example the code blocks from lines 126-152 and 153-178 are not part of any method body. It looks like they are part of the advance method body, and therefore need to be enclosed within the methoud body that starts on line 100 and ends on line 125. The big picture is that you are putting in braces where they do not belong. Be sure not to finish the method body until all of the statements you want to execute are enclosed.

-Jam


001 package mcclarty;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author My Name Here
010  */
011 public class Monty_Hall extends Game
012 {
013 
014   private ImageSprite door1;
015   private ImageSprite door2;
016   private ImageSprite door3;
017   private ImageSprite cow;
018   private ImageSprite money;
019   private ImageSprite pig;
020   private StringSprite greeting;
021   private StringSprite pick;
022   private StringSprite choice;
023   private StringSprite lose;
024   private StringSprite winner;
025   private int doorChosen;
026   private int x;
027 
028   /**sets up the game*/
029   public void setup()
030   {
031     doorChosen=0;
032     x=random.nextInt(3)+1;
033 
034     cow=new ImageSprite ("HappyCow.jpg");
035     cow.setSize(0.35);
036     addSprite (cow);
037 
038     money=new ImageSprite ("Moneys.jpg");
039     money.setSize(0.28);
040     addSprite(money);
041 
042     pig=new ImageSprite ("PigArt.jpg");
043     pig.setSize(0.35);
044     addSprite(pig);
045 
046     door1=new ImageSprite ("McClarty_Door1.jpg");
047     door1.setLocation (0.150.5);
048     door1.setSize(0.4);
049     addSprite(door1);
050 
051     door2=new ImageSprite ("McClarty_Door2.jpg");
052     door2.setLocation (0.50.5);
053     door2.setSize(0.4);
054     addSprite(door2);
055 
056     door3=new ImageSprite ("McClarty_Door3.jpg");
057     door3.setLocation (0.850.5);
058     door3.setSize(0.4);
059     addSprite(door3);
060 
061     greeting=new StringSprite("Let's Make a Deal!")
062              ;
063     greeting.setLocation (0.5,0.1);
064     greeting.setSize(0.5);
065     greeting.setColor (Palette.getColor("Yellow"));
066     addSprite(greeting);
067 
068     pick=new StringSprite("Choose a door...");
069     pick.setLocation (0.5,0.9);
070     pick.setSize(0.5);
071     pick.setColor (Palette.getColor("Yellow"));
072     addSprite(pick);
073 
074     choice=new StringSprite("Stay (s) or Switch (w)??");
075     choice.setLocation (0.5,0.9);
076     choice.setSize(0.5);
077     choice.setColor (Palette.getColor("Red"));
078     addSprite(choice);
079     choice.setVisible(false);
080 
081     lose=new StringSprite("You lose! Sorry..");
082     lose.setLocation(0.5,0.9);
083     lose.setSize(0.5);
084     lose.setColor (Palette.getColor("Orange"));
085     addSprite(lose);
086     lose.setVisible(false);
087 
088     winner=new StringSprite("You win! Congratulations!");
089     winner.setLocation(0.5,0.9);
090     winner.setSize(0.5);
091     winner.setColor (Palette.getColor("Green"));
092     addSprite(winner);
093     winner.setVisible(false);
094 
095     generate();
096   }
097 
098   public void advance()
099   {
100     door1();
101     door2();
102     door3();
103   }
104 
105   /**Sets up the prizes behind random doors*/
106   public void generate()
107   {
108 
109     x=random.nextInt(3)+1;
110 
111     if(x==1)
112     {
113       money.setLocation(0.15,0.5);
114       pig.setLocation(0.5,0.5);
115       cow.setLocation(0.85,0.5);
116     }
117     if(x==2)
118     {
119       money.setLocation(0.50.5);
120       pig.setLocation(0.85,0.5);
121       cow.setLocation(0.15,0.5);
122     }
123     if(x==3)
124     {
125       money.setLocation(0.85,0.5);
126       pig.setLocation(0.15,0.5);
127       cow.setLocation(0.5,0.5);
128     }
129   }
130 
131   /**handle input and game events for door1*/
132   public void door1()
133   {
134     if(getClick2D()!=null  && door1.intersects(getClick2D()))
135     {
136       doorChosen++;
137     }
138     if(doorChosen==1)
139     {
140       if(x==1)
141       {
142         door3.setVisible(false);
143         pick.setVisible(false);
144         choice.setVisible(true);
145       }
146       if (getKeyPressed() == 's')
147       {
148         door1.setVisible(false);
149         door2.setVisible(false);
150         choice.setVisible(false);
151         winner.setVisible(true);
152 
153       }
154       if (getKeyPressed() == 'w')
155       {
156         door1.setVisible(false);
157         door2.setVisible(false);
158         lose.setVisible(true);
159         choice.setVisible(false);
160       }
161       else if(x==2)
162       {
163         door3.setVisible(false);
164         pick.setVisible(false);
165         choice.setVisible(true);
166       }
167       if(getKeyPressed() == 's')
168       {
169         door1.setVisible(false);
170         door2.setVisible(false);
171         lose.setVisible(true);
172         choice.setVisible(false);
173       }
174       if (getKeyPressed() == 'w')
175       {
176         door1.setVisible(false);
177         door2.setVisible(false);
178         winner.setVisible(true);
179         choice.setVisible(false);
180       }
181       else if(x==3)
182       {
183         door2.setVisible(false);
184         pick.setVisible(false);
185         choice.setVisible(true);
186       }
187       if(getKeyPressed() == 's')
188       {
189         door1.setVisible(false);
190         door3.setVisible(false);
191         lose.setVisible(true);
192         choice.setVisible(false);
193       }
194       if (getKeyPressed() == 'w')
195       {
196         door1.setVisible(false);
197         door3.setVisible(false);
198         winner.setVisible(true);
199         choice.setVisible(false);
200       }
201     }
202   }
203 
204   /**handle input and game events for door2*/
205   public void door2()
206   {
207     if(getClick2D()!=null  && door2.intersects(getClick2D()))
208     {
209       doorChosen++;
210     }
211     if(doorChosen==2)
212     {
213       if(x==1)
214       {
215         door3.setVisible(false);
216         pick.setVisible(false);
217         choice.setVisible(true);
218       }
219       if (getKeyPressed() == 's')
220       {
221         door1.setVisible(false);
222         door2.setVisible(false);
223         lose.setVisible(true);
224         choice.setVisible(false);
225       }
226       if (getKeyPressed() == 'w')
227       {
228         door1.setVisible(false);
229         door2.setVisible(false);
230         winner.setVisible(true);
231         choice.setVisible(false);
232       }
233       else if(x==2)
234       {
235         door1.setVisible(false);
236         pick.setVisible(false);
237         choice.setVisible(true);
238       }
239       if(getKeyPressed() == 's')
240       {
241         door2.setVisible(false);
242         door3.setVisible(false);
243         winner.setVisible(true);
244         choice.setVisible(false);
245       }
246       if (getKeyPressed() == 'w')
247       {
248         door2.setVisible(false);
249         door3.setVisible(false);
250         lose.setVisible(true);
251         choice.setVisible(false);
252       }
253       else if(x==3)
254       {
255         door1.setVisible(false);
256         pick.setVisible(false);
257         choice.setVisible(true);
258       }
259       if(getKeyPressed() == 's')
260       {
261         door2.setVisible(false);
262         door3.setVisible(false);
263         lose.setVisible(true);
264         choice.setVisible(false);
265       }
266       if (getKeyPressed() == 'w')
267       {
268         door2.setVisible(false);
269         door3.setVisible(false);
270         winner.setVisible(true);
271         choice.setVisible(false);
272       }
273     }
274   }
275 
276 
277   /**handle input and game events for door3*/
278   public void door3()
279   {
280     if(getClick2D()!=null  && door3.intersects(getClick2D()))
281     {
282       doorChosen++;
283     }
284     if(doorChosen==3)
285     {
286       if(x==1)
287       {
288         door2.setVisible(false);
289         pick.setVisible(false);
290         choice.setVisible(true);
291       }
292       if (getKeyPressed() == 's')
293       {
294         door1.setVisible(false);
295         door3.setVisible(false);
296         lose.setVisible(true);
297         choice.setVisible(false);
298       }
299       if (getKeyPressed() == 'w')
300       {
301         door1.setVisible(false);
302         door3.setVisible(false);
303         winner.setVisible(true);
304         choice.setVisible(false);
305       }
306       else if(x==2)
307       {
308         door1.setVisible(false);
309         pick.setVisible(false);
310         choice.setVisible(true);
311       }
312       if(getKeyPressed() == 's')
313       {
314         door2.setVisible(false);
315         door3.setVisible(false);
316         lose.setVisible(true);
317         choice.setVisible(false);
318       }
319       if (getKeyPressed() == 'w')
320       {
321         door2.setVisible(false);
322         door3.setVisible(false);
323         winner.setVisible(true);
324         choice.setVisible(false);
325       }
326       else if(x==3)
327       {
328         door2.setVisible(false);
329         pick.setVisible(false);
330         choice.setVisible(true);
331       }
332       if(getKeyPressed() == 's')
333       {
334         door1.setVisible(false);
335         door3.setVisible(false);
336         winner.setVisible(true);
337         choice.setVisible(false);
338       }
339       if (getKeyPressed() == 'w')
340       {
341         door1.setVisible(false);
342         door3.setVisible(false);
343         lose.setVisible(true);
344         choice.setVisible(false);
345       }
346 
347     }
348   }
349 }


Download/View mcclarty/Monty_Hall.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