|
001 packagepackage is used to name the directory or folder a class is in matt_mitrovich_kcie_green;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * This code is from rohrer.
009 * This code is from rohrer.
010 */
011 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Montyhall extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 ImageSprite door1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Kickstop_door_p5.jpg");
014 ImageSprite door2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Kickstop_door_p5.jpg");
015 ImageSprite door3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Kickstop_door_p5.jpg");
016 ImageSprite prize1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Trophy-cup.jpg");
017 ImageSprite prize2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Broken_computer.jpg");
018 ImageSprite prize3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Broken_computer.jpg");
019 StringSprite step1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Click a Door to Begin");
020 StringSprite step2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("choose to stay with your choice or change it");
021 StringSprite step3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Press the (s) key to begin again");
022 StringSprite win =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("YOU WIN!!!");
023 StringSprite lose =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("YOU FAIL");
024 StringSprite numbers =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("1 2 3");
025 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer numClicks, prizePlace, doorRemove;
026
027
028
029 /**sets up the splash screen*/
030 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
031 {open braces start code blocks and must be matched with a close brace
032 StringSprite splash =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Click Start To Begin");
033 splash.setSize(.75);
034 splash.setLocation(.5,.5);
035 addSprite(splash);
036 }close braces end code blocks and must match an earlier open brace
037
038 /** removes all doors and displays a mesage opon correct door choice*/
039 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Winner()
040 {open braces start code blocks and must be matched with a close brace
041 door1.setVisible(falsefalse is a value for the boolean type and means not true);
042 door2.setVisible(falsefalse is a value for the boolean type and means not true);
043 door3.setVisible(falsefalse is a value for the boolean type and means not true);
044 step2.setVisible(falsefalse is a value for the boolean type and means not true);
045 win.setSize(.75);
046 win.setLocation(.5,.2);
047 addSprite(win);
048 win.setVisible(truetrue is the boolean value that is the opposite of false);
049 step3.setVisible(truetrue is the boolean value that is the opposite of false);
050 numbers.setVisible(falsefalse is a value for the boolean type and means not true);
051 }close braces end code blocks and must match an earlier open brace
052
053 /** removes all doors and displays a message apon wrong door choice*/
054 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Loser()
055 {open braces start code blocks and must be matched with a close brace
056 door1.setVisible(falsefalse is a value for the boolean type and means not true);
057 door2.setVisible(falsefalse is a value for the boolean type and means not true);
058 door3.setVisible(falsefalse is a value for the boolean type and means not true);
059 step2.setVisible(falsefalse is a value for the boolean type and means not true);
060 lose.setSize(.75);
061 lose.setLocation(.5,.2);
062 addSprite(lose);
063 lose.setVisible(truetrue is the boolean value that is the opposite of false);
064 step3.setVisible(truetrue is the boolean value that is the opposite of false);
065 numbers.setVisible(falsefalse is a value for the boolean type and means not true);
066 }close braces end code blocks and must match an earlier open brace
067
068 /** createsand adds the winning door and prize*/
069 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value WinningDoor(doubledouble is the type for numbers that can contain decimal fractions p, doubledouble is the type for numbers that can contain decimal fractions d)
070 {open braces start code blocks and must be matched with a close brace
071 prize1.setLocation(p,.5);
072 prize1.setSize(.2);
073 addSprite(prize1);
074 prize1.setVisible(truetrue is the boolean value that is the opposite of false);
075
076 door1.setLocation(d,.5);
077 door1.setSize(.5);
078 addSprite(door1);
079 door1.setVisible(truetrue is the boolean value that is the opposite of false);
080
081 }close braces end code blocks and must match an earlier open brace
082
083 /** createsand adds a losing door and prize*/
084 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value LosingDoor1(doubledouble is the type for numbers that can contain decimal fractions p, doubledouble is the type for numbers that can contain decimal fractions d)
085 {open braces start code blocks and must be matched with a close brace
086 prize2.setLocation(p,.5);
087 prize2.setSize(.2);
088 addSprite(prize2);
089 prize2.setVisible(truetrue is the boolean value that is the opposite of false);
090
091 door2.setLocation(d,.5);
092 door2.setSize(.5);
093 addSprite(door2);
094 door2.setVisible(truetrue is the boolean value that is the opposite of false);
095 }close braces end code blocks and must match an earlier open brace
096
097 /**creates and adds a loosing door and prize*/
098 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value LosingDoor2(doubledouble is the type for numbers that can contain decimal fractions p, doubledouble is the type for numbers that can contain decimal fractions d)
099 {open braces start code blocks and must be matched with a close brace
100 prize3.setLocation(p,.5);
101 prize3.setSize(.2);
102 addSprite(prize3);
103 prize3.setVisible(truetrue is the boolean value that is the opposite of false);
104
105 door3.setLocation(d,.5);
106 door3.setSize(.5);
107 addSprite(door3);
108 door3.setVisible(truetrue is the boolean value that is the opposite of false);
109 }close braces end code blocks and must match an earlier open brace
110
111 /**adds the prizes to random locations in the game window*/
112 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value AddPrizeDoors()
113 {open braces start code blocks and must be matched with a close brace
114
115 ifif executes the next statement only if the condition in parenthesis evaluates to true(prizePlace ==this is the comparison operator which evaluates to true if both sides are the same 1)
116 {open braces start code blocks and must be matched with a close brace
117 WinningDoor(.2, .2);
118 LosingDoor1(.5, .5);
119 LosingDoor2(.8, .8);
120 }close braces end code blocks and must match an earlier open brace
121 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(prizePlace ==this is the comparison operator which evaluates to true if both sides are the same 2)
122 {open braces start code blocks and must be matched with a close brace
123 WinningDoor(.5, .5);
124 LosingDoor1(.8, .8);
125 LosingDoor2(.2, .2);
126 }close braces end code blocks and must match an earlier open brace
127 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (prizePlace ==this is the comparison operator which evaluates to true if both sides are the same 3)
128 {open braces start code blocks and must be matched with a close brace
129 WinningDoor(.8, .8);
130 LosingDoor1(.2, .2);
131 LosingDoor2(.5, .5);
132 }close braces end code blocks and must match an earlier open brace
133 }close braces end code blocks and must match an earlier open brace
134 /**removes door that is not chosen and is not the prize apon first door choice*/
135 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value RemoveDoor()
136 {open braces start code blocks and must be matched with a close brace
137
138 ifif executes the next statement only if the condition in parenthesis evaluates to true (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door1.intersects(getClick2D()))
139 {open braces start code blocks and must be matched with a close brace
140 doorRemove =this assignment operator makes the left side equal to the right side random.nextInt(2)+adds two numbers together or concatenates Strings together1;
141 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorRemove ==this is the comparison operator which evaluates to true if both sides are the same 1)
142 {open braces start code blocks and must be matched with a close brace
143 door2.setVisible(falsefalse is a value for the boolean type and means not true);
144 }close braces end code blocks and must match an earlier open brace
145 elseelse is what happens when the if condition is false
146 {open braces start code blocks and must be matched with a close brace
147 door3.setVisible(falsefalse is a value for the boolean type and means not true);
148 }close braces end code blocks and must match an earlier open brace
149 }close braces end code blocks and must match an earlier open brace
150 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door2.intersects(getClick2D()))
151 {open braces start code blocks and must be matched with a close brace
152 door3.setVisible(falsefalse is a value for the boolean type and means not true);
153 }close braces end code blocks and must match an earlier open brace
154 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door3.intersects(getClick2D()))
155 {open braces start code blocks and must be matched with a close brace
156 door2.setVisible(falsefalse is a value for the boolean type and means not true);
157 }close braces end code blocks and must match an earlier open brace
158 }close braces end code blocks and must match an earlier open brace
159
160 /** makes the games instructions and other text*/
161 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Instructions()
162 {open braces start code blocks and must be matched with a close brace
163 step1.setSize(.75);
164 step1.setLocation(.5,.2);
165 addSprite(step1);
166 step1.setVisible(truetrue is the boolean value that is the opposite of false);
167
168 step2.setSize(.75);
169 step2.setLocation(.5,.2);
170 addSprite(step2);
171 step2.setVisible(falsefalse is a value for the boolean type and means not true);
172
173 step3.setSize(.75);
174 step3.setLocation(.5,.8);
175 addSprite(step3);
176 step3.setVisible(falsefalse is a value for the boolean type and means not true);
177
178 numbers.setSize(.7);
179 numbers.setLocation(.5,.85);
180 addSprite(numbers);
181 numbers.setVisible(falsefalse is a value for the boolean type and means not true);
182 }close braces end code blocks and must match an earlier open brace
183
184 /**changes display depending on the interaction of user*/
185 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
186 {open braces start code blocks and must be matched with a close brace
187 ifif executes the next statement only if the condition in parenthesis evaluates to true( (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door1.intersects(getClick2D()))
188 ||this is boolean or, meaning if either or both are true then the result is true (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door2.intersects(getClick2D()))
189 ||this is boolean or, meaning if either or both are true then the result is true (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door3.intersects(getClick2D())) )
190 {open braces start code blocks and must be matched with a close brace
191 numClicks++this is the increment operator, which increases the variable by 1;
192 }close braces end code blocks and must match an earlier open brace
193
194
195 ifif executes the next statement only if the condition in parenthesis evaluates to true(numClicks==this is the comparison operator which evaluates to true if both sides are the same0)
196 {open braces start code blocks and must be matched with a close brace
197 prizePlace =this assignment operator makes the left side equal to the right side random.nextInt(3)+adds two numbers together or concatenates Strings together1;
198 removeAllSprites();
199 Instructions();
200 AddPrizeDoors();
201 numbers.setVisible(truetrue is the boolean value that is the opposite of false);
202 }close braces end code blocks and must match an earlier open brace
203 ifif executes the next statement only if the condition in parenthesis evaluates to true(numClicks==this is the comparison operator which evaluates to true if both sides are the same1)
204 {open braces start code blocks and must be matched with a close brace
205 step1.setVisible(falsefalse is a value for the boolean type and means not true);
206 step2.setVisible(truetrue is the boolean value that is the opposite of false);
207 RemoveDoor();
208 }close braces end code blocks and must match an earlier open brace
209 ifif executes the next statement only if the condition in parenthesis evaluates to true(numClicks==this is the comparison operator which evaluates to true if both sides are the same2)
210 {open braces start code blocks and must be matched with a close brace
211 step1.setVisible(falsefalse is a value for the boolean type and means not true);
212 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door1.intersects(getClick2D()))
213 {open braces start code blocks and must be matched with a close brace
214 Winner();
215 }close braces end code blocks and must match an earlier open brace
216 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true( (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door2.intersects(getClick2D()))
217 ||this is boolean or, meaning if either or both are true then the result is true (getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) door3.intersects(getClick2D())) )
218 {open braces start code blocks and must be matched with a close brace
219 Loser();
220 }close braces end code blocks and must match an earlier open brace
221 }close braces end code blocks and must match an earlier open brace
222
223
224 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same's' &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) numClicks >=this evaluates to true if the left side is not less than the right side 2)
225 {open braces start code blocks and must be matched with a close brace
226 numClicks =this assignment operator makes the left side equal to the right side 0;
227 }close braces end code blocks and must match an earlier open brace
228
229
230
231 }close braces end code blocks and must match an earlier open brace
232 }close braces end code blocks and must match an earlier open brace
|