From ggc
|
001 packagepackage is used to name the directory or folder a class is in Wilson;
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 importimport means to make the classes and/or packages available in this program java.lang.*;
007
008 /**
009 * All about my game.
010 * @authorthis is the Javadoc tag for documenting who created the source code Wilson Green
011 */
012 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
013 {open braces start code blocks and must be matched with a close brace
014 ImageSprite door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("President_Security_Door.jpg");
015 ImageSprite door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("President_Security_Door.jpg");
016 ImageSprite door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("President_Security_Door.jpg");
017 ImageSprite money=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Moneystackss.jpg");
018 ImageSprite fail=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("FAIL.jpg");
019 StringSprite welcome=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click any Door.");
020 StringSprite again=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click again please.");
021 StringSprite win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You win!");
022 StringSprite lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You lose!");
023 booleanboolean is a type that is either true or false opened=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
024 intint is the type for whole numbers and it is short for integer doorNumber, doorOpened;
025 intint is the type for whole numbers and it is short for integer random=this assignment operator makes the left side equal to the right side((intint is the type for whole numbers and it is short for integer)(Math.random()*3)+adds two numbers together or concatenates Strings together1);
026 /**sets up the game*/
027 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
028 {open braces start code blocks and must be matched with a close brace
029 ifif executes the next statement only if the condition in parenthesis evaluates to true(random==this is the comparison operator which evaluates to true if both sides are the same1)
030 {open braces start code blocks and must be matched with a close brace
031 money.setLocation(.5,.5);
032 money.setSize(.5);
033 addSprite(money);
034 money.setVisible(truetrue is the boolean value that is the opposite of false);
035 doorNumber=this assignment operator makes the left side equal to the right side1;
036 }close braces end code blocks and must match an earlier open brace
037 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(random==this is the comparison operator which evaluates to true if both sides are the same2)
038 {open braces start code blocks and must be matched with a close brace
039 money.setLocation(.15,.5);
040 money.setSize(.5);
041 addSprite(money);
042 money.setVisible(truetrue is the boolean value that is the opposite of false);
043 doorNumber=this assignment operator makes the left side equal to the right side2;
044 }close braces end code blocks and must match an earlier open brace
045
046 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(random==this is the comparison operator which evaluates to true if both sides are the same3)
047 {open braces start code blocks and must be matched with a close brace
048 money.setLocation(.85,.5);
049 money.setSize(.5);
050 addSprite(money);
051 money.setVisible(truetrue is the boolean value that is the opposite of false);
052 doorNumber=this assignment operator makes the left side equal to the right side3;
053 }close braces end code blocks and must match an earlier open brace
054
055 //(for debugging) welcome=new StringSprite("Door: " + doorNumber);
056 welcome.setLocation(.5,.9);
057 welcome.setSize(.5);
058 addSprite(welcome);
059 welcome.setVisible(truetrue is the boolean value that is the opposite of false);
060
061 again.setLocation(.5,.9);
062 again.setSize(.9);
063 addSprite(again);
064 again.setVisible(falsefalse is a value for the boolean type and means not true);
065
066 win.setLocation(.5,.9);
067 win.setSize(.5);
068 addSprite(win);
069 win.setVisible(falsefalse is a value for the boolean type and means not true);
070
071 lose.setLocation(.5,.9);
072 lose.setSize(.5);
073 addSprite(lose);
074 lose.setVisible(falsefalse is a value for the boolean type and means not true);
075
076 door1.setLocation(.5,.5);
077 door1.setSize(.5);
078 addSprite(door1);
079 door1.setVisible(truetrue is the boolean value that is the opposite of false);
080
081 door2.setLocation(.15,.5);
082 door2.setSize(.5);
083 addSprite(door2);
084 door2.setVisible(truetrue is the boolean value that is the opposite of false);
085
086 door3.setLocation(.85,.5);
087 door3.setSize(.5);
088 addSprite(door3);
089 door3.setVisible(truetrue is the boolean value that is the opposite of false);
090 }close braces end code blocks and must match an earlier open brace
091 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value montyHall(intint is the type for whole numbers and it is short for integer doorMania)
092 {open braces start code blocks and must be matched with a close brace
093 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the samedoorNumber)
094 {open braces start code blocks and must be matched with a close brace
095 intint is the type for whole numbers and it is short for integer randomD=this assignment operator makes the left side equal to the right side((intint is the type for whole numbers and it is short for integer)Math.random()*1);
096 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the same1)
097 {open braces start code blocks and must be matched with a close brace
098 ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same0)
099 {open braces start code blocks and must be matched with a close brace
100 door2.setVisible(falsefalse is a value for the boolean type and means not true);
101 doorOpened=this assignment operator makes the left side equal to the right side2;
102 }close braces end code blocks and must match an earlier open brace
103 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same1)
104 {open braces start code blocks and must be matched with a close brace
105 door3.setVisible(falsefalse is a value for the boolean type and means not true);
106 doorOpened=this assignment operator makes the left side equal to the right side3;
107 }close braces end code blocks and must match an earlier open brace
108 }close braces end code blocks and must match an earlier open brace
109 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the same2)
110 {open braces start code blocks and must be matched with a close brace
111 ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same0)
112 {open braces start code blocks and must be matched with a close brace
113 door1.setVisible(falsefalse is a value for the boolean type and means not true);
114 doorOpened=this assignment operator makes the left side equal to the right side1;
115 }close braces end code blocks and must match an earlier open brace
116 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same1)
117 {open braces start code blocks and must be matched with a close brace
118 door3.setVisible(falsefalse is a value for the boolean type and means not true);
119 doorOpened=this assignment operator makes the left side equal to the right side3;
120 }close braces end code blocks and must match an earlier open brace
121 }close braces end code blocks and must match an earlier open brace
122 elseelse is what happens when the if condition is false
123 {open braces start code blocks and must be matched with a close brace
124 ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same0)
125 {open braces start code blocks and must be matched with a close brace
126 door1.setVisible(falsefalse is a value for the boolean type and means not true);
127 doorOpened=this assignment operator makes the left side equal to the right side1;
128 }close braces end code blocks and must match an earlier open brace
129 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(randomD==this is the comparison operator which evaluates to true if both sides are the same1)
130 {open braces start code blocks and must be matched with a close brace
131 door2.setVisible(falsefalse is a value for the boolean type and means not true);
132 doorOpened=this assignment operator makes the left side equal to the right side2;
133 }close braces end code blocks and must match an earlier open brace
134 }close braces end code blocks and must match an earlier open brace
135 }close braces end code blocks and must match an earlier open brace
136 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the same1 &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 &&) doorMania!=this is the not equals operator which evaluates to true if both sides are differentdoorNumber)
137 {open braces start code blocks and must be matched with a close brace
138 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same2)
139 {open braces start code blocks and must be matched with a close brace
140 door3.setVisible(falsefalse is a value for the boolean type and means not true);
141 doorOpened=this assignment operator makes the left side equal to the right side3;
142 }close braces end code blocks and must match an earlier open brace
143 elseelse is what happens when the if condition is false
144 {open braces start code blocks and must be matched with a close brace
145 door2.setVisible(falsefalse is a value for the boolean type and means not true);
146 doorOpened=this assignment operator makes the left side equal to the right side2;
147 }close braces end code blocks and must match an earlier open brace
148 }close braces end code blocks and must match an earlier open brace
149 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the same2 &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 &&) doorMania!=this is the not equals operator which evaluates to true if both sides are differentdoorNumber)
150 {open braces start code blocks and must be matched with a close brace
151 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same3)
152 {open braces start code blocks and must be matched with a close brace
153 door1.setVisible(falsefalse is a value for the boolean type and means not true);
154 doorOpened=this assignment operator makes the left side equal to the right side1;
155 }close braces end code blocks and must match an earlier open brace
156 elseelse is what happens when the if condition is false
157 {open braces start code blocks and must be matched with a close brace
158 door3.setVisible(falsefalse is a value for the boolean type and means not true);
159 doorOpened=this assignment operator makes the left side equal to the right side3;
160 }close braces end code blocks and must match an earlier open brace
161 }close braces end code blocks and must match an earlier open brace
162 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(doorMania==this is the comparison operator which evaluates to true if both sides are the same3 &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 &&) doorMania!=this is the not equals operator which evaluates to true if both sides are differentdoorNumber)
163 {open braces start code blocks and must be matched with a close brace
164 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same2)
165 {open braces start code blocks and must be matched with a close brace
166 door1.setVisible(falsefalse is a value for the boolean type and means not true);
167 doorOpened=this assignment operator makes the left side equal to the right side1;
168 }close braces end code blocks and must match an earlier open brace
169 elseelse is what happens when the if condition is false
170 {open braces start code blocks and must be matched with a close brace
171 door2.setVisible(falsefalse is a value for the boolean type and means not true);
172 doorOpened=this assignment operator makes the left side equal to the right side2;
173 }close braces end code blocks and must match an earlier open brace
174 }close braces end code blocks and must match an earlier open brace
175 welcome.setVisible(falsefalse is a value for the boolean type and means not true);
176 again.setVisible(truetrue is the boolean value that is the opposite of false);
177 }close braces end code blocks and must match an earlier open brace
178
179 /**handle input and game events*/
180 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
181 {open braces start code blocks and must be matched with a close brace
182 ifif executes the next statement only if the condition in parenthesis evaluates to true(!this is the not operator, which changes true to false and false to trueopened)
183 {open braces start code blocks and must be matched with a close brace
184 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()))
185 {open braces start code blocks and must be matched with a close brace
186 montyHall(1);
187 opened=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
188 }close braces end code blocks and must match an earlier open brace
189 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()))
190 {open braces start code blocks and must be matched with a close brace
191 montyHall(2);
192 opened=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
193 }close braces end code blocks and must match an earlier open brace
194 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()))
195 {open braces start code blocks and must be matched with a close brace
196 montyHall(3);
197 opened=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
198 }close braces end code blocks and must match an earlier open brace
199 }close braces end code blocks and must match an earlier open brace
200 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(opened)
201 {open braces start code blocks and must be matched with a close brace
202 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()) &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 &&) doorOpened!=this is the not equals operator which evaluates to true if both sides are different3)
203 {open braces start code blocks and must be matched with a close brace
204 again.setVisible(falsefalse is a value for the boolean type and means not true);
205 door3.setVisible(falsefalse is a value for the boolean type and means not true);
206 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same3)
207 {open braces start code blocks and must be matched with a close brace
208 win.setVisible(truetrue is the boolean value that is the opposite of false);
209 money.setVisible(truetrue is the boolean value that is the opposite of false);
210 }close braces end code blocks and must match an earlier open brace
211 elseelse is what happens when the if condition is false
212 {open braces start code blocks and must be matched with a close brace
213 lose.setVisible(truetrue is the boolean value that is the opposite of false);
214 }close braces end code blocks and must match an earlier open brace
215 }close braces end code blocks and must match an earlier open brace
216 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()) &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 &&) doorOpened!=this is the not equals operator which evaluates to true if both sides are different2)
217 {open braces start code blocks and must be matched with a close brace
218 again.setVisible(falsefalse is a value for the boolean type and means not true);
219 door2.setVisible(falsefalse is a value for the boolean type and means not true);
220 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same2)
221 {open braces start code blocks and must be matched with a close brace
222 win.setVisible(truetrue is the boolean value that is the opposite of false);
223 money.setVisible(truetrue is the boolean value that is the opposite of false);
224 }close braces end code blocks and must match an earlier open brace
225 elseelse is what happens when the if condition is false
226 {open braces start code blocks and must be matched with a close brace
227 lose.setVisible(truetrue is the boolean value that is the opposite of false);
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
230 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()) &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 &&) doorOpened!=this is the not equals operator which evaluates to true if both sides are different1)
231 {open braces start code blocks and must be matched with a close brace
232 again.setVisible(falsefalse is a value for the boolean type and means not true);
233 door1.setVisible(falsefalse is a value for the boolean type and means not true);
234 ifif executes the next statement only if the condition in parenthesis evaluates to true(doorNumber==this is the comparison operator which evaluates to true if both sides are the same1)
235 {open braces start code blocks and must be matched with a close brace
236 win.setVisible(truetrue is the boolean value that is the opposite of false);
237 money.setVisible(truetrue is the boolean value that is the opposite of false);
238 }close braces end code blocks and must match an earlier open brace
239 elseelse is what happens when the if condition is false
240 {open braces start code blocks and must be matched with a close brace
241 lose.setVisible(truetrue is the boolean value that is the opposite of false);
242 }close braces end code blocks and must match an earlier open brace
243 }close braces end code blocks and must match an earlier open brace
244
245
246 }close braces end code blocks and must match an earlier open brace
247 }close braces end code blocks and must match an earlier open brace
248 }close braces end code blocks and must match an earlier open brace
|
Download/View Wilson/MontyHall.java