Curtis/MakeADeal

From ggc

Jump to: navigation, search

001 package Curtis;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * Monty Hall.  
009  @author: Curtis
010  */
011 public class MakeADeal extends Game
012 {
013 
014   //All Images and Texts
015   private int numClicks;
016   private ImageSprite door1, door2, door3, win, lose1, lose2;
017   private StringSprite start, first, second, third, choose, change, uwin, ulose;
018   private int doorpicked;
019   private int noopen;
020   private int open;
021   private int i;
022   private int k;
023   private int j;
024   private int stage;
025 
026 
027   /**sets up the game*/
028   public void setup()
029   {
030     numClicks=0;
031     stage=0;
032 
033     start=new StringSprite("Press Start");
034     start.setScale(.2);
035     start.setLocation(.1.9);
036     start.setVisible(true);
037     addSprite(start);
038 
039     /*Doors*/
040     door1=new ImageSprite("DoorCS.jpg");
041     door1.setScale(.45);
042     door1.setLocation(.2.4);
043     addSprite(door1);
044 
045     door2=new ImageSprite("DoorCS.jpg");
046     door2.setScale(.45);
047     door2.setLocation(.5.4);
048     addSprite(door2);
049 
050     door3=new ImageSprite("DoorCS.jpg");
051     door3.setScale(.45);
052     door3.setLocation(.8.4);
053     addSprite(door3);
054 
055     /*Numbers*/
056     first=new StringSprite("#1");
057     first.setSize(.1);
058     first.setLocation(.2.7);
059     first.setColor(getColor("yellow"));
060     addSprite(first);
061 
062     second=new StringSprite("#2");
063     second.setSize(.1);
064     second.setLocation(.5.7);
065     second.setColor(getColor("yellow"));
066     addSprite(second);
067 
068     third=new StringSprite("#3");
069     third.setSize(.1);
070     third.setLocation(.8.7);
071     third.setColor(getColor("yellow"));
072     addSprite(third);
073 
074     /*Text - Instructions*/
075     choose=new StringSprite("Choose A Door");
076     choose.setSize(.5);
077     choose.setLocation(.5.1);
078     choose.setColor(getColor("yellow"));
079     addSprite(choose);
080 
081     change=new StringSprite("Is That Your Final Answer");
082     change.setSize(.5);
083     change.setLocation(.5.8);
084     change.setColor(getColor("yellow"));
085     change.setVisible(false);
086     addSprite(change);
087 
088     /*Win and Lose Images*/
089     win=new ImageSprite("Win12333333.jpg");
090     win.setScale(.2);
091     win.setVisible(false);
092     addSprite(win);
093 
094     lose1=new ImageSprite("LoseCS.jpg");
095     lose1.setScale(.25);
096     lose1.setVisible(false);
097 
098     lose2=new ImageSprite("LoseCS.jpg");
099     lose2.setScale(.25);
100     lose2.setVisible(false);
101     addSprite(lose2);
102 
103     uwin=new StringSprite("You Are Victorious");
104     uwin.setSize(.8);
105     uwin.setLocation(.5.8);
106     uwin.setColor(getColor("yellow"));
107     uwin.setVisible(false);
108     addSprite(uwin);
109 
110     ulose=new StringSprite("You Fail Epically");
111     ulose.setSize(.8);
112     ulose.setLocation(.5.8);
113     ulose.setColor(getColor("yellow"));
114     ulose.setVisible(false);
115     addSprite(ulose);
116 
117   }
118 
119   /**handle input and game events*/
120   public void advance()
121   {
122     if(stage==0)
123     {
124 
125       Point2D.Double click=getPlayer().getMouse().getClickLocation();
126       if(click!=null && numClicks == 0)
127       {
128         if (door1.intersects(click))
129           //This is the number Randomizer
130         {
131           numClicks=1;
132           i=random.nextInt(2)+1;
133           doorpicked=1;
134           if(i==1)
135           {
136             //if you click door 1
137             lose1.setLocation(door2.getLocation());
138             win.setLocation(door3.getLocation());
139             lose2.setLocation(door1.getLocation());
140             addSprite(lose1);
141             addSprite(win);
142             addSprite(lose2);
143             open=2;
144             noopen=3;
145           }
146           else if(i==2)
147           {
148             lose1.setLocation(door3.getLocation());
149             win.setLocation(door1.getLocation());
150             lose2.setLocation(door2.getLocation());
151             addSprite(lose1);
152             addSprite(win);
153             addSprite(lose2);
154             open=3;
155             noopen=2;
156           }
157           change.setVisible(true);
158           lose1.setVisible(true);
159           start.setVisible(false);
160           choose.setVisible(false);
161           stage=1;
162         }
163 
164         if (door2.intersects(click))
165           //if you click door 2
166         {
167           numClicks=1;
168           j=random.nextInt(2)+1;
169           doorpicked=2;
170           if(j==1)
171           {
172             lose1.setLocation(door1.getLocation());
173             win.setLocation(door2.getLocation());
174             lose2.setLocation(door3.getLocation());
175             addSprite(lose1);
176             addSprite(win);
177             addSprite(lose2);
178             open=1;
179             noopen=3;
180           }
181           else if(j==2)
182           {
183             lose1.setLocation(door3.getLocation());
184             win.setLocation(door2.getLocation());
185             lose2.setLocation(door1.getLocation());
186             addSprite(lose1);
187             addSprite(win);
188             addSprite(lose2);
189             open=3;
190             noopen=1;
191           }
192           change.setVisible(true);
193           lose1.setVisible(true);
194           start.setVisible(false);
195           choose.setVisible(false);
196           stage=1;
197         }
198         if(door3.intersects(click))
199           //if you click door 3
200         {
201           numClicks=1;
202           k=random.nextInt(2)+1;
203           doorpicked=3;
204           if(k==1)
205           {
206             lose1.setLocation(door1.getLocation());
207             win.setLocation(door3.getLocation());
208             lose2.setLocation(door2.getLocation());
209             addSprite(lose1);
210             addSprite(win);
211             addSprite(lose2);
212             open=1;
213             noopen=2;
214           }
215           if(k==2)
216           {
217             lose1.setLocation(door2.getLocation());
218             win.setLocation(door1.getLocation());
219             lose2.setLocation(door3.getLocation());
220             addSprite(lose1);
221             addSprite(win);
222             addSprite(lose2);
223             open=2;
224             noopen=1;
225           }
226           change.setVisible(true);
227           lose1.setVisible(true);
228           start.setVisible(false);
229           choose.setVisible(false);
230           stage=1;
231         }
232       }
233     }
234     //On the second Click
235     else if (stage==1)
236     {
237 
238       Point2D.Double click=getPlayer().getMouse().getClickLocation();
239       if(click!=null && numClicks == 1)
240 
241 
242       {
243         if (door1.intersects(click&& open==2)
244         {
245           numClicks=2;
246           i=random.nextInt(2);
247           doorpicked=1;
248           if(i==1)
249           {
250             lose2.setLocation(door1.getLocation());
251             win.setLocation(door3.getLocation());
252             addSprite(lose2);
253             addSprite(win);
254             ulose.setVisible(true);
255             open=2;
256             noopen=3;
257           }
258           else if(i==2)
259           {
260             lose2.setLocation(door3.getLocation());
261             win.setLocation(door1.getLocation());
262             addSprite(lose2);
263             addSprite(win);
264             uwin.setVisible(true);
265             win.setVisible(true);
266             open=3;
267             noopen=2;
268           }
269           lose2.setVisible(true);
270           change.setVisible(false);
271         }
272         if (door1.intersects(click&& open==3)
273         {
274           numClicks=2;
275           i=random.nextInt(2);
276           doorpicked=1;
277           if(i==1)
278           {
279             lose2.setLocation(door1.getLocation());
280             win.setLocation(door2.getLocation());
281             addSprite(lose2);
282             addSprite(win);
283             ulose.setVisible(true);
284             open=2;
285             noopen=3;
286           }
287           else if(i==2)
288           {
289             lose2.setLocation(door2.getLocation());
290             win.setLocation(door1.getLocation());
291             addSprite(lose2);
292             addSprite(win);
293             uwin.setVisible(true);
294             win.setVisible(true);
295             open=3;
296             noopen=2;
297           }
298           lose2.setVisible(true);
299           change.setVisible(false);
300         }
301 
302         if (door2.intersects(click&& open==3)
303         {
304           numClicks=2;
305           j=random.nextInt(2);
306           doorpicked=2;
307           if(j==1)
308           {
309             lose2.setLocation(door2.getLocation());
310             win.setLocation(door1.getLocation());
311             addSprite(lose2);
312             addSprite(win);
313             ulose.setVisible(true);
314             open=1;
315             noopen=3;
316           }
317           else if(j==2)
318           {
319             lose2.setLocation(door1.getLocation());
320             win.setLocation(door2.getLocation());
321             addSprite(lose2);
322             addSprite(win);
323             uwin.setVisible(true);
324             win.setVisible(true);
325             open=3;
326             noopen=1;
327           }
328           lose2.setVisible(true);
329           change.setVisible(false);
330         }
331         if (door2.intersects(click&& open==1)
332         {
333           numClicks=2;
334           j=random.nextInt(2);
335           doorpicked=2;
336           if(j==1)
337           {
338             lose2.setLocation(door2.getLocation());
339             win.setLocation(door3.getLocation());
340             addSprite(lose2);
341             addSprite(win);
342             ulose.setVisible(true);
343             open=1;
344             noopen=3;
345           }
346           else if(j==2)
347           {
348             lose2.setLocation(door3.getLocation());
349             win.setLocation(door2.getLocation());
350             addSprite(lose2);
351             addSprite(win);
352             uwin.setVisible(true);
353             win.setVisible(true);
354             open=3;
355             noopen=1;
356           }
357           lose2.setVisible(true);
358           change.setVisible(false);
359         }
360         if(door3.intersects(click&& open==1)
361         {
362           numClicks=2;
363           k=random.nextInt(2);
364           doorpicked=3;
365           if(k==1)
366           {
367             lose2.setLocation(door3.getLocation());
368             win.setLocation(door2.getLocation());
369             ulose.setVisible(true);
370             addSprite(lose2);
371             addSprite(win);
372 
373             open=1;
374             noopen=2;
375           }
376           if(k==2)
377           {
378             lose2.setLocation(door2.getLocation());
379             win.setLocation(door3.getLocation());
380             addSprite(lose2);
381             addSprite(win);
382             uwin.setVisible(true);
383             win.setVisible(true);
384 
385             open=2;
386             noopen=1;
387           }
388           lose2.setVisible(true);
389           change.setVisible(false);
390           stage=2;
391         }
392         if(door3.intersects(click&& open==2)
393         {
394           numClicks=2;
395           k=random.nextInt(2);
396           doorpicked=3;
397           if(k==1)
398           {
399             lose2.setLocation(door3.getLocation());
400             win.setLocation(door1.getLocation());
401             ulose.setVisible(true);
402             addSprite(lose2);
403             addSprite(win);
404 
405             open=1;
406             noopen=2;
407           }
408           if(k==2)
409           {
410             lose2.setLocation(door1.getLocation());
411             win.setLocation(door3.getLocation());
412             addSprite(lose2);
413             addSprite(win);
414             uwin.setVisible(true);
415             win.setVisible(true);
416 
417             open=2;
418             noopen=1;
419           }
420           lose2.setVisible(true);
421           change.setVisible(false);
422           stage=2;
423         }
424       }
425     }
426   }
427 }


Download/View Curtis/MakeADeal.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