|
001 packagepackage is used to name the directory or folder a class is in Schwarz;
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 * Creates a game where the user selects a door. Used Kevin Rohrer's project to help.
009 * @authorthis is the Javadoc tag for documenting who created the source code Drew Schwarz
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 Monty_Hall 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 prizedoor =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Rohrer-Door.jpg");
014 ImageSprite faildoor =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Rohrer-Door.jpg");
015 ImageSprite faildoor2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Rohrer-Door.jpg");
016 ImageSprite prizeGood =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Stack-o-money.jpg");
017 ImageSprite prizeBad1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("HDD_broken.JPG");
018 ImageSprite prizeBad2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Broken_HDD.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 (B) 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'RE A WINNER!!!");
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("FAILURE (T-T) ");
024 StringSprite num =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, PlacePrize, RemoveDoors;
026
027
028 /**opens the game with instructions*/
029 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
030 {open braces start code blocks and must be matched with a close brace
031 StringSprite begin =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("To Begin Click Start");
032 begin.setLocation(.5,.4);
033 begin.setSize(.75);
034 addSprite(begin);
035 }close braces end code blocks and must match an earlier open brace
036
037 /** places the iformation forfor is a looping structure for repeatedly executing a block of code the player when they win the game*/
038 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Win()
039 {open braces start code blocks and must be matched with a close brace
040 prizedoor.setVisible(falsefalse is a value for the boolean type and means not true);
041 faildoor.setVisible(falsefalse is a value for the boolean type and means not true);
042 faildoor2.setVisible(falsefalse is a value for the boolean type and means not true);
043 step2.setVisible(falsefalse is a value for the boolean type and means not true);
044 win.setSize(.5);
045 win.setLocation(.5, .65);
046 addSprite(win);
047 win.setVisible(truetrue is the boolean value that is the opposite of false);
048 step3.setVisible(truetrue is the boolean value that is the opposite of false);
049 num.setVisible(falsefalse is a value for the boolean type and means not true);
050 }close braces end code blocks and must match an earlier open brace
051
052 /**places the information forfor is a looping structure for repeatedly executing a block of code the player when the loos the game*/
053 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Lose()
054 {open braces start code blocks and must be matched with a close brace
055 prizedoor.setVisible(falsefalse is a value for the boolean type and means not true);
056 faildoor.setVisible(falsefalse is a value for the boolean type and means not true);
057 faildoor2.setVisible(falsefalse is a value for the boolean type and means not true);
058 step2.setVisible(falsefalse is a value for the boolean type and means not true);
059 lose.setLocation(.5, .65);
060 lose.setSize(.5);
061 addSprite(lose);
062 lose.setVisible(truetrue is the boolean value that is the opposite of false);
063 step3.setVisible(truetrue is the boolean value that is the opposite of false);
064 num.setVisible(falsefalse is a value for the boolean type and means not true);
065 }close braces end code blocks and must match an earlier open brace
066
067 /** creates the winning door with the prize behind it*/
068 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value WiningDoor(doubledouble is the type for numbers that can contain decimal fractions x, doubledouble is the type for numbers that can contain decimal fractions y)
069 {open braces start code blocks and must be matched with a close brace
070 prizeGood.setLocation(x, .5);
071 prizeGood.setSize(.2);
072 addSprite(prizeGood);
073 prizeGood.setVisible(truetrue is the boolean value that is the opposite of false);
074
075 prizedoor.setLocation(y,.5);
076 prizedoor.setSize(.5);
077 addSprite(prizedoor);
078 prizedoor.setVisible(truetrue is the boolean value that is the opposite of false);
079 }close braces end code blocks and must match an earlier open brace
080
081 /**creates the first loosing door*/
082 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value LosingDoor(doubledouble is the type for numbers that can contain decimal fractions x, doubledouble is the type for numbers that can contain decimal fractions y)
083 {open braces start code blocks and must be matched with a close brace
084 prizeBad1.setLocation(x, .5);
085 prizeBad1.setSize(.2);
086 addSprite(prizeBad1);
087 prizeBad1.setVisible(truetrue is the boolean value that is the opposite of false);
088
089 faildoor.setLocation(y,.5);
090 faildoor.setSize(.5);
091 addSprite(faildoor);
092 faildoor.setVisible(truetrue is the boolean value that is the opposite of false);
093 }close braces end code blocks and must match an earlier open brace
094
095 /** creates the second loosing door*/
096 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 x, doubledouble is the type for numbers that can contain decimal fractions y)
097 {open braces start code blocks and must be matched with a close brace
098 prizeBad2.setLocation(x,.5);
099 prizeBad2.setSize(.2);
100 addSprite(prizeBad2);
101 prizeBad2.setVisible(truetrue is the boolean value that is the opposite of false);
102
103 faildoor2.setLocation(y,.5);
104 faildoor2.setSize(.5);
105 addSprite(faildoor2);
106 faildoor2.setVisible(truetrue is the boolean value that is the opposite of false);
107 }close braces end code blocks and must match an earlier open brace
108
109 /** Places the doors on the program */
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value AddDoors()
111 {open braces start code blocks and must be matched with a close brace
112 ifif executes the next statement only if the condition in parenthesis evaluates to true (PlacePrize==this is the comparison operator which evaluates to true if both sides are the same1)
113 {open braces start code blocks and must be matched with a close brace
114 WiningDoor(.8,.8);
115 LosingDoor(.5,.5);
116 LosingDoor2(.2,.2);
117 }close braces end code blocks and must match an earlier open brace
118 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (PlacePrize==this is the comparison operator which evaluates to true if both sides are the same2)
119 {open braces start code blocks and must be matched with a close brace
120 WiningDoor(.5,.5);
121 LosingDoor(.2,.2);
122 LosingDoor2(.8,.8);
123 }close braces end code blocks and must match an earlier open brace
124 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (PlacePrize==this is the comparison operator which evaluates to true if both sides are the same3)
125 {open braces start code blocks and must be matched with a close brace
126 WiningDoor(.2,.2);
127 LosingDoor(.8,.8);
128 LosingDoor2(.5,.5);
129 }close braces end code blocks and must match an earlier open brace
130 }close braces end code blocks and must match an earlier open brace
131 /**removes door that is not chosen and is not the prize apon first door choice*/
132 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value RemoveDoor()
133 {open braces start code blocks and must be matched with a close brace
134
135 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 different nullnull 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 &&) prizeGood.intersects(getClick2D()))
136 {open braces start code blocks and must be matched with a close brace
137 RemoveDoors =this assignment operator makes the left side equal to the right side random.nextInt(2)+adds two numbers together or concatenates Strings together1;
138 ifif executes the next statement only if the condition in parenthesis evaluates to true(RemoveDoors ==this is the comparison operator which evaluates to true if both sides are the same 1)
139 {open braces start code blocks and must be matched with a close brace
140 faildoor.setVisible(falsefalse is a value for the boolean type and means not true);
141 }close braces end code blocks and must match an earlier open brace
142 elseelse is what happens when the if condition is false
143 {open braces start code blocks and must be matched with a close brace
144 faildoor2.setVisible(falsefalse is a value for the boolean type and means not true);
145 }close braces end code blocks and must match an earlier open brace
146 }close braces end code blocks and must match an earlier open brace
147 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 different nullnull 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 &&) faildoor.intersects(getClick2D()))
148 {open braces start code blocks and must be matched with a close brace
149 faildoor2.setVisible(falsefalse is a value for the boolean type and means not true);
150 }close braces end code blocks and must match an earlier open brace
151 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 different nullnull 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 &&) faildoor2.intersects(getClick2D()))
152 {open braces start code blocks and must be matched with a close brace
153 faildoor.setVisible(falsefalse is a value for the boolean type and means not true);
154 }close braces end code blocks and must match an earlier open brace
155 }close braces end code blocks and must match an earlier open brace
156
157 /**handle input and game events*/
158 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Intro()
159 {open braces start code blocks and must be matched with a close brace
160 step1.setLocation(.5,.15);
161 step1.setSize(.8);
162 addSprite(step1);
163 step1.setVisible(truetrue is the boolean value that is the opposite of false);
164
165 step2.setLocation(.5,.15);
166 step2.setSize(.8);
167 addSprite(step2);
168 step2.setVisible(falsefalse is a value for the boolean type and means not true);
169
170 step3.setLocation(.5,.15);
171 step3.setSize(.8);
172 addSprite(step3);
173 step3.setVisible(falsefalse is a value for the boolean type and means not true);
174
175 num.setLocation(.5,.8);
176 num.setSize(.7);
177 addSprite(num);
178 num.setVisible(falsefalse is a value for the boolean type and means not true);
179 }close braces end code blocks and must match an earlier open brace
180 /** creates the user interfaceinterface is a named collection of declared methods*/
181 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
182 {open braces start code blocks and must be matched with a close brace
183 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 different nullnull 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 &&) prizeGood.intersects(getClick2D()))
184 ||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 different nullnull 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 &&) faildoor.intersects(getClick2D()))
185 ||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 different nullnull 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 &&) faildoor2.intersects(getClick2D())))
186 {open braces start code blocks and must be matched with a close brace
187 numClicks++this is the increment operator, which increases the variable by 1;
188 }close braces end code blocks and must match an earlier open brace
189
190
191 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)
192 {open braces start code blocks and must be matched with a close brace
193 PlacePrize =this assignment operator makes the left side equal to the right side random.nextInt(3)+adds two numbers together or concatenates Strings together1;
194 removeAllSprites();
195 Intro();
196 AddDoors();
197 num.setVisible(truetrue is the boolean value that is the opposite of false);
198 }close braces end code blocks and must match an earlier open brace
199 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)
200 {open braces start code blocks and must be matched with a close brace
201 step1.setVisible(falsefalse is a value for the boolean type and means not true);
202 step2.setVisible(truetrue is the boolean value that is the opposite of false);
203 RemoveDoor();
204 }close braces end code blocks and must match an earlier open brace
205 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)
206 {open braces start code blocks and must be matched with a close brace
207 step1.setVisible(falsefalse is a value for the boolean type and means not true);
208 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 different nullnull 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 &&) prizeGood.intersects(getClick2D()))
209 {open braces start code blocks and must be matched with a close brace
210 Win();
211 }close braces end code blocks and must match an earlier open brace
212 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 different nullnull 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 &&) faildoor.intersects(getClick2D()))
213 ||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 different nullnull 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 &&) faildoor2.intersects(getClick2D())))
214 {open braces start code blocks and must be matched with a close brace
215 Lose();
216 }close braces end code blocks and must match an earlier open brace
217 }close braces end code blocks and must match an earlier open brace
218
219
220 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'b' &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)
221 {open braces start code blocks and must be matched with a close brace
222 numClicks =this assignment operator makes the left side equal to the right side 0;
223 }close braces end code blocks and must match an earlier open brace
224
225
226
227
228 }close braces end code blocks and must match an earlier open brace
229 }close braces end code blocks and must match an earlier open brace
|