matt mitrovich kcie green/Montyhall

From ggc

Jump to: navigation, search

001 package matt_mitrovich_kcie_green;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * This code is from rohrer.
009  * This code is from rohrer.
010  */
011 public class Montyhall extends Game
012 {
013   ImageSprite door1 = new ImageSprite("Kickstop_door_p5.jpg");
014   ImageSprite door2 = new ImageSprite("Kickstop_door_p5.jpg");
015   ImageSprite door3 = new ImageSprite("Kickstop_door_p5.jpg");
016   ImageSprite prize1 = new ImageSprite("Trophy-cup.jpg");
017   ImageSprite prize2 = new ImageSprite("Broken_computer.jpg");
018   ImageSprite prize3 = new ImageSprite("Broken_computer.jpg");
019   StringSprite step1 = new StringSprite("Click a Door to Begin");
020   StringSprite step2 = new StringSprite("choose to stay with your choice or change it");
021   StringSprite step3 = new StringSprite("Press the (s) key to begin again");
022   StringSprite win = new StringSprite("YOU WIN!!!");
023   StringSprite lose = new StringSprite("YOU FAIL");
024   StringSprite numbers = new StringSprite("1  2  3");
025   private int numClicks, prizePlace, doorRemove;
026 
027 
028 
029   /**sets up the splash screen*/
030   public void setup()
031   {
032     StringSprite splash = new StringSprite("Click Start To Begin");
033     splash.setSize(.75);
034     splash.setLocation(.5,.5);
035     addSprite(splash);
036   }
037 
038   /** removes all doors and displays a mesage opon correct door choice*/
039   public void Winner()
040   {
041     door1.setVisible(false);
042     door2.setVisible(false);
043     door3.setVisible(false);
044     step2.setVisible(false);
045     win.setSize(.75);
046     win.setLocation(.5,.2);
047     addSprite(win);
048     win.setVisible(true);
049     step3.setVisible(true);
050     numbers.setVisible(false);
051   }
052 
053   /** removes all doors and displays a message apon wrong door choice*/
054   public void Loser()
055   {
056     door1.setVisible(false);
057     door2.setVisible(false);
058     door3.setVisible(false);
059     step2.setVisible(false);
060     lose.setSize(.75);
061     lose.setLocation(.5,.2);
062     addSprite(lose);
063     lose.setVisible(true);
064     step3.setVisible(true);
065     numbers.setVisible(false);
066   }
067 
068   /** createsand adds the winning door and prize*/
069   public void WinningDoor(double p, double d)
070   {
071     prize1.setLocation(p,.5);
072     prize1.setSize(.2);
073     addSprite(prize1);
074     prize1.setVisible(true);
075 
076     door1.setLocation(d,.5);
077     door1.setSize(.5);
078     addSprite(door1);
079     door1.setVisible(true);
080 
081   }
082 
083   /** createsand adds a losing door and prize*/
084   public void LosingDoor1(double p, double d)
085   {
086     prize2.setLocation(p,.5);
087     prize2.setSize(.2);
088     addSprite(prize2);
089     prize2.setVisible(true);
090 
091     door2.setLocation(d,.5);
092     door2.setSize(.5);
093     addSprite(door2);
094     door2.setVisible(true);
095   }
096 
097   /**creates and adds a loosing door and prize*/
098   public void LosingDoor2(double p, double d)
099   {
100     prize3.setLocation(p,.5);
101     prize3.setSize(.2);
102     addSprite(prize3);
103     prize3.setVisible(true);
104 
105     door3.setLocation(d,.5);
106     door3.setSize(.5);
107     addSprite(door3);
108     door3.setVisible(true);
109   }
110 
111   /**adds the prizes to random locations in the game window*/
112   public void AddPrizeDoors()
113   {
114 
115     if(prizePlace == 1)
116     {
117       WinningDoor(.2.2);
118       LosingDoor1(.5.5);
119       LosingDoor2(.8.8);
120     }
121     else if(prizePlace == 2)
122     {
123       WinningDoor(.5.5);
124       LosingDoor1(.8.8);
125       LosingDoor2(.2.2);
126     }
127     else if (prizePlace == 3)
128     {
129       WinningDoor(.8.8);
130       LosingDoor1(.2.2);
131       LosingDoor2(.5.5);
132     }
133   }
134   /**removes door that is not chosen and is not the prize apon first door choice*/
135   public void RemoveDoor()
136   {
137 
138     if (getClick2D()!=null  && door1.intersects(getClick2D()))
139     {
140       doorRemove = random.nextInt(2)+1;
141       if(doorRemove == 1)
142       {
143         door2.setVisible(false);
144       }
145       else
146       {
147         door3.setVisible(false);
148       }
149     }
150     else if (getClick2D()!=null  && door2.intersects(getClick2D()))
151     {
152       door3.setVisible(false);
153     }
154     else if(getClick2D()!=null  && door3.intersects(getClick2D()))
155     {
156       door2.setVisible(false);
157     }
158   }
159 
160   /** makes the games instructions and other text*/
161   public void Instructions()
162   {
163     step1.setSize(.75);
164     step1.setLocation(.5,.2);
165     addSprite(step1);
166     step1.setVisible(true);
167 
168     step2.setSize(.75);
169     step2.setLocation(.5,.2);
170     addSprite(step2);
171     step2.setVisible(false);
172 
173     step3.setSize(.75);
174     step3.setLocation(.5,.8);
175     addSprite(step3);
176     step3.setVisible(false);
177 
178     numbers.setSize(.7);
179     numbers.setLocation(.5,.85);
180     addSprite(numbers);
181     numbers.setVisible(false);
182   }
183 
184   /**changes display depending on the interaction of user*/
185   public void advance()
186   {
187     if(  (getClick2D()!=null  && door1.intersects(getClick2D()))
188             || (getClick2D()!=null  && door2.intersects(getClick2D()))
189             || (getClick2D()!=null  && door3.intersects(getClick2D()))  )
190     {
191       numClicks++;
192     }
193 
194 
195     if(numClicks==0)
196     {
197       prizePlace = random.nextInt(3)+1;
198       removeAllSprites();
199       Instructions();
200       AddPrizeDoors();
201       numbers.setVisible(true);
202     }
203     if(numClicks==1)
204     {
205       step1.setVisible(false);
206       step2.setVisible(true);
207       RemoveDoor();
208     }
209     if(numClicks==2)
210     {
211       step1.setVisible(false);
212       if(getClick2D()!=null  && door1.intersects(getClick2D()))
213       {
214         Winner();
215       }
216       else if(  (getClick2D()!=null  && door2.intersects(getClick2D()))
217                 || (getClick2D()!=null  && door3.intersects(getClick2D()))   )
218       {
219         Loser();
220       }
221     }
222 
223 
224     if(getKeyPressed()=='s' && numClicks >= 2)
225     {
226       numClicks = 0;
227     }
228 
229 
230 
231   }
232 }


Download/View matt_mitrovich_kcie_green/Montyhall.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