From ggc
|
01 importimport means to make the classes and/or packages available in this program fang.*;
02 importimport means to make the classes and/or packages available in this program java.awt.*;
03
04 /**
05 * All about my game here.
06 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
07 */
08 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 SampleSound extendsextends means to customize or extend the functionality of a class GameLoop
09 {open braces start code blocks and must be matched with a close brace
10 /**an oval*/
11 privateprivate is used to restrict access to the current class only Sprite oval;
12 privateprivate is used to restrict access to the current class only Sound sound;
13
14 /**sets up the game*/
15 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
16 {open braces start code blocks and must be matched with a close brace
17 makeSprites();
18 makeSounds();
19 addSprites();
20 }close braces end code blocks and must match an earlier open brace
21
22 /**makes the sprites*/
23 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
24 {open braces start code blocks and must be matched with a close brace
25 oval=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(2, 1);
26 oval.setScale(0.75);
27 oval.setLocation(0.5, 0.5);
28 }close braces end code blocks and must match an earlier open brace/**makes the sprites*/
29 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSounds()
30 {open braces start code blocks and must be matched with a close brace
31 sound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Ding.wav"));
32 }close braces end code blocks and must match an earlier open brace
33
34 /**adds the sprites to the screen*/
35 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
36 {open braces start code blocks and must be matched with a close brace
37 canvas.addSprite(oval);
38 }close braces end code blocks and must match an earlier open brace
39
40 /**handle input and game events*/
41 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advanceFrame(doubledouble is the type for numbers that can contain decimal fractions timePassed)
42 {open braces start code blocks and must be matched with a close brace
43 oval.setLocation(getPlayer().getMouse().getLocation());
44 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getMouse().getClickLocation()!=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)
45 {open braces start code blocks and must be matched with a close brace
46 oval.setScale(random.nextDouble());
47 sound.play();
48 }close braces end code blocks and must match an earlier open brace
49 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'r')
50 {open braces start code blocks and must be matched with a close brace
51 oval.setColor(Color.RED);
52 }close braces end code blocks and must match an earlier open brace
53 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'w')
54 {open braces start code blocks and must be matched with a close brace
55 oval.setColor(Color.WHITE);
56 }close braces end code blocks and must match an earlier open brace
57 }close braces end code blocks and must match an earlier open brace
58 }close braces end code blocks and must match an earlier open brace
|
Download/View SampleSound.java