GBell/DoorGame

From ggc

Jump to: navigation, search

001 package GBell;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * Based on Lets Make a Deal, with assistance from Jacob Olsen and Dr. Jenkins.
010  @author Geremy Bell
011  */
012 public class DoorGame extends GameLoop
013 {
014   private Sprite left, middle, right;
015   private ImageSprite prize, junk1, junk2;
016   private StringSprite instruction, instruction1, title, win, lose;
017   private int location, stage, choice, x, y;
018   /**This audio file listed as freeware at http://www.thepcmanwebsite.com/pcman.shtml*/
019   private Sound sound0=new Sound(Wiki.getMedia("Opening.wav"));
020   private Sound sound1=new Sound(Wiki.getMedia("Beep2.wav"));
021 
022   public void startGame()
023   {
024     stage=0;
025     toggleAudible();
026     sound0.play();
027     pauseToggle();
028     makeSprites();
029     addSprites();
030     {
031       y=random.nextInt(2);
032       x=random.nextInt(3);
033       if(x==0)
034       {
035         location=3;
036         prize.setLocation(0.850.4);
037         junk1.setLocation(0.150.4);
038         junk2.setLocation(0.50.4);
039       }
040       if(x==1)
041       {
042         location=1;
043         prize.setLocation(0.150.4);
044         junk1.setLocation(0.850.4);
045         junk2.setLocation(0.50.4);
046       }
047       if(x==2)
048       {
049         location=2;
050         prize.setLocation(0.50.4);
051         junk1.setLocation(0.150.4);
052         junk2.setLocation(0.850.4);
053       }
054     }
055   }
056   /**Makes sprites*/
057   public void makeSprites()
058   {
059     middle=new RectangleSprite(11);
060     middle.setScale(.25);
061     middle.setLocation(0.50.4);
062     middle.setColor(Color.RED);
063 
064     left=new RectangleSprite(11);
065     left.setScale(.25);
066     left.setLocation(0.150.4);
067     left.setColor(Color.RED);
068 
069     right=new RectangleSprite(11);
070     right.setScale(.25);
071     right.setLocation(0.850.4);
072     right.setColor(Color.RED);
073 
074     prize=new ImageSprite ("Gbellbluesmile.gif");
075     prize.setScale(.2);
076 
077     junk1=new ImageSprite ("Ex.jpg");
078     junk1.setScale(.3);
079 
080     junk2=new ImageSprite ("Ex.jpg");
081     junk2.setScale(.3);
082 
083     title=new StringSprite ("Let's Make A Deal");
084     title.setLocation(.5.1);
085     title.setColor(Color.WHITE);
086     title.setScale(.8);
087 
088     instruction=new StringSprite ("Pick a door to begin.");
089     instruction.setLocation(.5.78);
090     instruction.setColor(Color.GREEN);
091     instruction.setScale(.4);
092 
093     instruction1=new StringSprite ("Either click the same door or choose another.");
094     instruction1.setLocation(.5.78);
095     instruction1.setColor(Color.GREEN);
096     instruction1.setScale(.85);
097 
098     win=new StringSprite ("You win!");
099     win.setLocation(.5.78);
100     win.setColor(Color.GREEN);
101     win.setScale(.85);
102 
103     lose=new StringSprite ("You lose.");
104     lose.setLocation(.5.78);
105     lose.setColor(Color.GREEN);
106     lose.setScale(.85);
107   }
108   /**Adds first sprites*/
109   public void addSprites()
110   {
111     canvas.addSprite(prize);
112     canvas.addSprite(junk1);
113     canvas.addSprite(junk2);
114     canvas.addSprite(middle);
115     canvas.addSprite(left);
116     canvas.addSprite(right);
117     canvas.addSprite(title);
118     canvas.addSprite(instruction);
119   }
120   /**First click is left box*/
121   private void leftClicked()
122   {
123     Point2D.Double click=getPlayer().getMouse().getClickLocation();
124     if(left.intersects(click))
125     {
126       choice=1;
127       sound1.play();
128 
129       if (location==3)
130       {
131         canvas.removeSprite(middle);
132       }
133       if (location==1)
134       {
135         if (y==0)
136           canvas.removeSprite(right);
137         else
138           canvas.removeSprite(middle);
139       }
140       if (location==2)
141       {
142         canvas.removeSprite(right);
143       }
144     }
145   }
146   /**First click is middle box*/
147   private void middleClicked()
148   {
149     Point2D.Double click=getPlayer().getMouse().getClickLocation();
150     if(middle.intersects(click))
151     {
152       choice=2;
153       sound1.play();
154       if (location==3)
155       {
156         canvas.removeSprite(left);
157       }
158       if (location==1)
159       {
160         canvas.removeSprite(right);
161       }
162       if (location==2)
163       {
164         if (y==0)
165           canvas.removeSprite(right);
166         else
167           canvas.removeSprite(left);
168       }
169     }
170   }
171   /**First click is right box*/
172   private void rightClicked()
173   {
174     Point2D.Double click=getPlayer().getMouse().getClickLocation();
175     if(right.intersects(click))
176     {
177       choice=3;
178       sound1.play();
179       if (location==3)
180       {
181         if (y==0)
182           canvas.removeSprite(middle);
183         else
184           canvas.removeSprite(left);
185       }
186       if (location==1)
187       {
188         canvas.removeSprite(middle);
189       }
190       if (location==2)
191       {
192         canvas.removeSprite(left);
193       }
194     }
195   }
196 
197   public void advanceFrame(double timePassed)
198   {
199     Point2D.Double click=getPlayer().getMouse().getClickLocation();
200     if(click!=null)
201     {
202       if (stage==0)
203       {
204         stage=1;
205         canvas.removeSprite(instruction);
206         canvas.addSprite(instruction1);
207         leftClicked();
208         middleClicked();
209         rightClicked();
210       }
211       else if (stage==1)
212       {
213         canvas.removeSprite(instruction1);
214         if(left.intersects(click))
215         {
216           choice=1;
217         }
218         if(middle.intersects(click))
219         {
220           choice=2;
221         }
222         if(right.intersects(click))
223         {
224           choice=3;
225         }
226         if (choice==1)
227         {
228           canvas.removeSprite(left, middle, right);
229           sound1.play();
230           if (location==1)
231           {
232             canvas.addSprite(win);
233           }
234           else
235           {
236             canvas.addSprite(lose);
237           }
238         }
239 
240         if (choice==2)
241         {
242           canvas.removeSprite(left, middle, right);
243           sound1.play();
244           if (location==2)
245           {
246             canvas.addSprite(win);
247           }
248           else
249           {
250             canvas.addSprite(lose);
251           }
252         }
253 
254         if (choice==3)
255         {
256           canvas.removeSprite(left, middle, right);
257           sound1.play();
258           if (location==3)
259           {
260             canvas.addSprite(win);
261           }
262           else
263           {
264             canvas.addSprite(lose);
265           }
266         }
267 
268       }
269     }
270   }
271 }
272 


Download/View GBell/DoorGame.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