|
001 packagepackage is used to name the directory or folder a class is in Anam;
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 game allows you to interact with shapes and images.
009 * by Anam Mughal
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 assignment6prac 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 privateprivate is used to restrict access to the current class only StringSprite atitle;
014 privateprivate is used to restrict access to the current class only StringSprite aname;
015 privateprivate is used to restrict access to the current class only PolygonSprite shape1;
016 privateprivate is used to restrict access to the current class only ImageSprite belle1;
017 privateprivate is used to restrict access to the current class only StringSprite clickb;
018 privateprivate is used to restrict access to the current class only StringSprite clicko;
019 privateprivate is used to restrict access to the current class only OvalSprite shape4;
020 privateprivate is used to restrict access to the current class only StringSprite helping;
021 privateprivate is used to restrict access to the current class only Sound ring1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Ring1.mp3");
022
023
024 /**sets up the game*/
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
026 {open braces start code blocks and must be matched with a close brace
027 /* This is the method body that tells the program
028 to dodo is part of the do-while looping structure (post condition loop) whatever is told in the privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value below.
029 This will post the sprites on the screen.*/
030 makeTexts();
031 makeShapes();
032 makeBelle();
033 makeHelpbox();
034 ring1();
035
036 }close braces end code blocks and must match an earlier open brace
037 /*This adds sound to 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 ring1()
039 {open braces start code blocks and must be matched with a close brace
040 playSoundImmediately();
041 ring1.setVolume(0.8);
042 ring1.loop();
043 }close braces end code blocks and must match an earlier open brace
044
045 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeHelpbox()
046 {open braces start code blocks and must be matched with a close brace
047 /* This makes the help box.
048 When the user clicks help, a help box pops up
049 forfor is a looping structure for repeatedly executing a block of code additional help &this performs a bit-wise and (not the same as boolean and which is &&) details about the game.
050 The text in purple is what will appear in
051 the help box*/
052
053 String helpbox=this assignment operator makes the left side equal to the right side
054 "Click on Belle's image and it will start blinking.<br>"+adds two numbers together or concatenates Strings together
055 "Press letter 'a' key and the instructions will disappear.<br>"+adds two numbers together or concatenates Strings together
056 "Then click on the oval twice and it will change color after 10 seconds.<br>"+adds two numbers together or concatenates Strings together
057 "Click Sound for sound effects.<br>";
058 setHelpText(helpbox);
059 }close braces end code blocks and must match an earlier open brace
060 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTexts()
061 {open braces start code blocks and must be matched with a close brace
062 /* This makes all the Sprites that include instructions and texts.
063 However, without the method body above, the sprites will not
064 appear on the screen, regardless of the addSprite in the following
065 code. For example, all of the sprites below are instructed
066 to be added to the screen, but ifif executes the next statement only if the condition in parenthesis evaluates to true it is not told to makeTexts
067 in the method body, sprites will not appear on the screen*/
068
069 /* This makes the title*/
070 atitle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Interactive Shapes");
071 atitle.setSize(0.60);
072 atitle.setColor(Palette.getColor("Peachpuff"));
073 atitle.setLocation(0.5, 0.06);
074 addSprite(atitle);
075
076 /*This makes the instructions forfor is a looping structure for repeatedly executing a block of code help box*/
077 helping=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click Help for additional help");
078 helping.setSize(0.35);
079 helping.setColor(Palette.getColor("Light Green"));
080 helping.setLocation(0.20, 0.98);
081 addSprite(helping);
082
083 /* This makes the author's name*/
084 aname=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Anam Mughal");
085 aname.setSize(0.30);
086 aname.setColor(Palette.getColor("SILVER"));
087 aname.setLocation(0.82, 0.97);
088 addSprite(aname);
089
090 /*This makes the instructions to
091 click on belle and the oval*/
092 clickb=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click on the Image");
093 clickb.setSize(0.20);
094 clickb.setLocation(0.38, 0.42);
095 clickb.setColor(Palette.getColor("Light Blue"));
096 addSprite(clickb);
097 clickb.setVisible(truetrue is the boolean value that is the opposite of false);
098
099 clicko=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("First Press 'a' then Click Me");
100 clicko.setSize(0.35);
101 clicko.setLocation(0.50, 0.60);
102 clicko.setColor(Color.BLACK);
103 clicko.setVisible(truetrue is the boolean value that is the opposite of false);
104 }close braces end code blocks and must match an earlier open brace
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBelle()
106 {open braces start code blocks and must be matched with a close brace
107 /* Makes the image (Belle), but the image will
108 not appear on the screen until instructed as makeBelle
109 in the method body.*/
110
111 belle1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Belle.jpg");
112 belle1.setSize(0.18);
113 belle1.setLocation(0.38, 0.30);
114 addSprite(belle1);
115 }close braces end code blocks and must match an earlier open brace
116 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeShapes()
117 {open braces start code blocks and must be matched with a close brace
118 /* Makes all the shapes, but has to be
119 instructed in the method body as makeShapes
120 forfor is a looping structure for repeatedly executing a block of code it to appear on the screen.*/
121
122 /*Makes the Pentagon*/
123 shape1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(5);
124 shape1.setSize(0.22);
125 shape1.setLocation(0.15, 0.30);
126 shape1.setColor(Palette.getColor("Sandy Brown"));
127 addSprite(shape1);
128
129 /*Makes the Oval*/
130 shape4=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(2, 1);
131 shape4.setSize(0.40);
132 shape4.setLocation(0.50, 0.60);
133 shape4.setColor(Palette.getColor("SILVER"));
134 addSprite(shape4);
135 addSprite(clicko);
136
137 /* This attaches the spinning/rotating
138 to the shape it is assigned to,
139 in thisthis means the current object (the implicit parameter) casecase is used with switch for multiple alternatives (like if/else if...) to shape1(which is a polygon).
140 This does not need to be instructed in the method
141 body since thisthis means the current object (the implicit parameter) is already part of the classclass is a group of fields and methods used for making objects
142 makeShapes*/
143
144 Spinner spins;
145 spins=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
146 spins.setRotationDegrees(175);
147
148 shape1.addTransformer(spins);
149
150 /* thisthis means the current object (the implicit parameter) attaches the translation
151 to shape1.*/
152 OutlineTransformer moving;
153 moving=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.40, 0.15, 0.30, 0.3, 0.9, 0.7, 0.5, 0.8, 0.10, 0.15, 0.30);
154 moving.setLooping(truetrue is the boolean value that is the opposite of false);
155 shape1.addTransformer(moving);
156 shape1.setLocation(moving.getCurrentPoint());
157 }close braces end code blocks and must match an earlier open brace
158
159
160 classclass is a group of fields and methods used for making objects Blinker extendsextends means to customize or extend the functionality of a class TimedAction
161 {open braces start code blocks and must be matched with a close brace
162 /* This makes the image of belle
163 blink when clicked*/
164 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
165 {open braces start code blocks and must be matched with a close brace
166 booleanboolean is a type that is either true or false vis=this assignment operator makes the left side equal to the right sidebelle1.isVisible();
167 belle1.setVisible(!this is the not operator, which changes true to false and false to truevis);
168 schedule(thisthis means the current object (the implicit parameter), .5);
169 }close braces end code blocks and must match an earlier open brace
170 }close braces end code blocks and must match an earlier open brace
171 classclass is a group of fields and methods used for making objects DelayedInter extendsextends means to customize or extend the functionality of a class TimedAction
172 {open braces start code blocks and must be matched with a close brace
173 /*This makes the oval change
174 color*/
175 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
176 {open braces start code blocks and must be matched with a close brace
177 shape4.setColor(getColor("purple"));
178 }close braces end code blocks and must match an earlier open brace
179 }close braces end code blocks and must match an earlier open brace
180
181
182 /**handle input and game events*/
183
184 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value interaction()
185 {open braces start code blocks and must be matched with a close brace
186 /*This makes the "click on the image"
187 disappear and start the image to blink
188 when clicked*/
189 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 &&) belle1.intersects(getClick2D()))
190 {open braces start code blocks and must be matched with a close brace
191 schedule (newnew is used to create objects by calling the constructor Blinker(), 0.2);
192 clickb.setVisible(falsefalse is a value for the boolean type and means not true);
193 }close braces end code blocks and must match an earlier open brace
194
195 }close braces end code blocks and must match an earlier open brace
196 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value changeColor()
197 {open braces start code blocks and must be matched with a close brace
198 /*This makes the oval change color
199 after 10 seconds when it is clicked*/
200 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 &&) shape4.intersects(getClick2D()))
201 {open braces start code blocks and must be matched with a close brace
202 schedule(newnew is used to create objects by calling the constructor DelayedInter(), 10);
203 }close braces end code blocks and must match an earlier open brace
204 }close braces end code blocks and must match an earlier open brace
205 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
206 {open braces start code blocks and must be matched with a close brace
207 /* This makes the instructions
208 "first press 'a' then click me"
209 disappear when 'a' is pressed.*/
210 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 'a')
211 {open braces start code blocks and must be matched with a close brace
212 clicko.setVisible(falsefalse is a value for the boolean type and means not true);
213 }close braces end code blocks and must match an earlier open brace
214 {open braces start code blocks and must be matched with a close brace
215 changeColor();
216 interaction();
217 }close braces end code blocks and must match an earlier open brace
218 }close braces end code blocks and must match an earlier open brace
219 }close braces end code blocks and must match an earlier open brace
|