Min/letsdeal

From ggc

Jump to: navigation, search

001 package Min;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 import java.util.Random.*;
007 
008 /**
009  * All about my game.
010  @author My Name Here
011  */
012 public class letsdeal extends Game
013 {
014 
015   private ImageSprite door1, door2, door3;
016   private ImageSprite loser1, loser2;
017   private ImageSprite winner;
018   private StringSprite header;
019   private StringSprite answer;
020   private StringSprite num1, num2, num3;
021   private StringSprite win;
022   private StringSprite fail;
023   private int doorpicked;
024   private int clickcount = 0;
025   private int i;
026   private int x;
027   private int j;
028   private int z;
029   private int open;
030   private int notopen;
031   /**sets up the game*/
032   public void setup()
033   {
034     clickcount=0;
035     makeSprite();
036     addSprite();
037     x=random.nextInt(2)+1;
038   }
039   private void makeSprite()
040   {
041     door1=new ImageSprite("Door123444.jpg");
042     door1.setLocation(.2.5);
043     door1.setScale(.5);
044     door1.setVisible(true);
045 
046     door2=new ImageSprite("Door123444.jpg");
047     door2.setLocation(.5.5);
048     door2.setScale(.5);
049     door2.setVisible(true);
050 
051     door3=new ImageSprite("Door123444.jpg");
052     door3.setLocation(.8.5);
053     door3.setScale(.5);
054     door3.setVisible(true);
055 
056     header=new StringSprite("Choose a door");
057     header.setLocation(.5.2);
058     header.setSize(.3);
059     addSprite(header);
060 
061     num1=new StringSprite("1");
062     num1.setLocation(.2.85);
063     num1.setSize(.15);
064 
065     num2=new StringSprite("2");
066     num2.setLocation(.5.85);
067     num2.setSize(.15);
068 
069     num3=new StringSprite("3");
070     num3.setLocation(.8.85);
071     num3.setSize(.15);
072 
073     answer=new StringSprite("q to stay w to switch!!");
074     answer.setSize(.5);
075     answer.setLocation(.5.1);
076     answer.setVisible(false);
077     addSprite(answer);
078 
079     win=new StringSprite("You Win");
080     win.setLocation(.5.3);
081     win.setSize(.25);
082 
083     fail=new StringSprite("Failed!!");
084     fail.setLocation(.5.3);
085     fail.setSize(.25);
086 
087     loser1=new ImageSprite("Loser0000.JPG");
088     loser1.setScale(.1);
089     loser1.setLocation(.2.5);
090     loser2=new ImageSprite("Loser0000.JPG");
091     loser2.setScale(.1);
092     loser2.setLocation(.5.5);
093     winner=new ImageSprite("Win12333333.jpg");
094     winner.setScale(.1);
095     winner.setLocation(.8.5);
096   }
097   private void addSprite()
098   {
099     canvas.addSprite(door1);
100     canvas.addSprite(door2);
101     canvas.addSprite(door3);
102     canvas.addSprite(num1);
103     canvas.addSprite(num2);
104     canvas.addSprite(num3);
105   }
106   /**handle input and game events*/
107   public void advance()
108   {
109     Point2D.Double click=getPlayer().getMouse().getClickLocation();
110     if(click!=null && clickcount == 0)
111     {
112       if (door1.intersects(click))
113       {
114         clickcount=1;
115         x=random.nextInt(2)+1;
116         doorpicked=1;
117         if(x==1)
118         {
119           loser1.setLocation(door2.getLocation());
120           canvas.removeSprite(door2);
121           addSprite(loser1);
122           open=2;
123           notopen=3;
124         }
125         else if(x==2)
126         {
127           loser1.setLocation(door3.getLocation());
128           canvas.removeSprite(door3);
129           addSprite(loser1);
130           open=3;
131           notopen=2;
132         }
133         answer.setVisible(true);
134         header.setVisible(false);
135       }
136 
137       if (door2.intersects(click))
138       {
139         clickcount=1;
140         j=random.nextInt(2)+1;
141         doorpicked=2;
142         if(j==1)
143         {
144           loser1.setLocation(door1.getLocation());
145           canvas.removeSprite(door1);
146           addSprite(loser1);
147           open=1;
148           notopen=3;
149         }
150         else if(j==2)
151         {
152           loser1.setLocation(door3.getLocation());
153           canvas.removeSprite(door3);
154           addSprite(loser1);
155           open=3;
156           notopen=1;
157         }
158         answer.setVisible(true);
159         header.setVisible(false);
160       }
161       if(door3.intersects(click))
162       {
163         clickcount=1;
164         z=random.nextInt(2)+1;
165         doorpicked=3;
166         if(z==1)
167         {
168           loser1.setLocation(door1.getLocation());
169           canvas.removeSprite(door1);
170           addSprite(loser1);
171           open=1;
172           notopen=2;
173         }
174         if(z==2)
175         {
176           loser1.setLocation(door2.getLocation());
177           canvas.removeSprite(door2);
178           addSprite(loser1);
179           open=2;
180           notopen=1;
181         }
182         answer.setVisible(true);
183         header.setVisible(false);
184       }
185     }
186     if(getPlayer().getKeyboard().getLastKey() == 'q')
187     {
188       if(clickcount==1)
189       {
190         i=random.nextInt(2)+1;
191         if(doorpicked==1  && notopen == 3)
192         {
193           if(== 1)
194           {
195             winner.setLocation(door1.getLocation());
196             loser2.setLocation(door3.getLocation());
197             canvas.addSprite(win);
198           }
199           if(== 2)
200           {
201             loser2.setLocation(door1.getLocation());
202             winner.setLocation(door3.getLocation());
203             canvas.addSprite(fail);
204           }
205         }
206         if(doorpicked==&& notopen == 2)
207         {
208           if(== 1)
209           {
210             winner.setLocation(door1.getLocation());
211             loser2.setLocation(door2.getLocation());
212             canvas.addSprite(win);
213           }
214           if(== 2)
215           {
216             loser2.setLocation(door1.getLocation());
217             winner.setLocation(door2.getLocation());
218             canvas.addSprite(fail);
219           }
220         }
221         if(doorpicked==&& notopen == 1)
222         {
223           if(== 1)
224           {
225             winner.setLocation(door2.getLocation());
226             loser2.setLocation(door1.getLocation());
227             canvas.addSprite(win);
228           }
229           if(== 2)
230           {
231             loser2.setLocation(door2.getLocation());
232             winner.setLocation(door1.getLocation());
233             canvas.addSprite(fail);
234           }
235         }
236         if(doorpicked==&& notopen == 3)
237         {
238           if(== 1)
239           {
240             winner.setLocation(door2.getLocation());
241             loser2.setLocation(door3.getLocation());
242             canvas.addSprite(win);
243           }
244           if(== 2)
245           {
246             loser2.setLocation(door2.getLocation());
247             winner.setLocation(door3.getLocation());
248             canvas.addSprite(fail);
249           }
250         }
251         if(doorpicked==&& notopen == 1)
252         {
253           if(== 1)
254           {
255             winner.setLocation(door3.getLocation());
256             loser2.setLocation(door1.getLocation());
257             canvas.addSprite(win);
258           }
259           if(== 2)
260           {
261             loser2.setLocation(door3.getLocation());
262             winner.setLocation(door1.getLocation());
263             canvas.addSprite(fail);
264           }
265         }
266         if(doorpicked==&& notopen == 2)
267         {
268           if(== 1)
269           {
270             winner.setLocation(door3.getLocation());
271             loser2.setLocation(door2.getLocation());
272             canvas.addSprite(win);
273           }
274           if(== 2)
275           {
276             loser2.setLocation(door3.getLocation());
277             winner.setLocation(door2.getLocation());
278             canvas.addSprite(fail);
279           }
280         }
281         canvas.removeSprite(door1);
282         canvas.removeSprite(door2);
283         canvas.removeSprite(door3);
284         canvas.addSprite(winner);
285         canvas.addSprite(loser2);
286       }
287     }
288     if(getPlayer().getKeyboard().getLastKey() == 'w')
289       if (clickcount==1)
290       {
291         = random.nextInt(2)+1;
292         if (doorpicked==&& notopen == 3)
293         {
294           if(== 1)
295           {
296             winner.setLocation(door1.getLocation());
297             loser2.setLocation(door3.getLocation());
298             canvas.addSprite(fail);
299           }
300           if(== 2)
301           {
302             loser2.setLocation(door1.getLocation());
303             winner.setLocation(door3.getLocation());
304             canvas.addSprite(win);
305           }
306         }
307         if (doorpicked==&& notopen == 2)
308         {
309           if(== 1)
310           {
311             winner.setLocation(door1.getLocation());
312             loser2.setLocation(door2.getLocation());
313             canvas.addSprite(fail);
314           }
315           if(== 2)
316           {
317             loser2.setLocation(door1.getLocation());
318             winner.setLocation(door2.getLocation());
319             canvas.addSprite(win);
320           }
321         }
322         if (doorpicked==&& notopen == 1)
323         {
324           if(== 1)
325           {
326             winner.setLocation(door2.getLocation());
327             loser2.setLocation(door1.getLocation());
328             canvas.addSprite(fail);
329           }
330           if(== 2)
331           {
332             loser2.setLocation(door2.getLocation());
333             winner.setLocation(door1.getLocation());
334             canvas.addSprite(win);
335           }
336         }
337         if (doorpicked==&& notopen == 3)
338         {
339           if(== 1)
340           {
341             winner.setLocation(door2.getLocation());
342             loser2.setLocation(door3.getLocation());
343             canvas.addSprite(fail);
344 
345           }
346           if(== 2)
347           {
348             loser2.setLocation(door2.getLocation());
349             winner.setLocation(door3.getLocation());
350             canvas.addSprite(win);
351           }
352         }
353         if (doorpicked==&& notopen == 1)
354         {
355           if(== 1)
356           {
357             winner.setLocation(door3.getLocation());
358             loser2.setLocation(door1.getLocation());
359             canvas.addSprite(fail);
360           }
361           if(== 2)
362           {
363             loser2.setLocation(door3.getLocation());
364             winner.setLocation(door1.getLocation());
365             canvas.addSprite(win);
366           }
367         }
368         if (doorpicked==&& notopen == 2)
369         {
370           if(== 1)
371           {
372             winner.setLocation(door3.getLocation());
373             loser2.setLocation(door2.getLocation());
374             canvas.addSprite(fail);
375           }
376           if(== 2)
377           {
378             loser2.setLocation(door3.getLocation());
379             winner.setLocation(door2.getLocation());
380             canvas.addSprite(win);
381           }
382         }
383 
384 
385         canvas.removeSprite(door1);
386         canvas.removeSprite(door2);
387         canvas.removeSprite(door3);
388         canvas.addSprite(loser2);
389         canvas.addSprite(winner);
390       }
391   }
392 }


Download/View Min/letsdeal.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