From ggc
|
01 packagepackage is used to name the directory or folder a class is in MNewman;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 //end auto-imports
05
06 importimport means to make the classes and/or packages available in this program fang.*;
07 importimport means to make the classes and/or packages available in this program java.awt.*;
08 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
09
10 /**
11 * All about my game.
12 * @authorthis is the Javadoc tag for documenting who created the source code Moriah
13 */
14
15 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 LightsOutModel extendsextends means to customize or extend the functionality of a class Game
16 {open braces start code blocks and must be matched with a close brace
17
18 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;
19 privateprivate is used to restrict access to the current class only RectangleSprite square;
20 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allSquares;
21 privateprivate is used to restrict access to the current class only OvalSprite light;
22 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allLights;
23
24
25
26 /**sets up the game*/
27 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
28 {open braces start code blocks and must be matched with a close brace
29
30 makeAndAddLights();
31 makeAndAddSquares();
32
33 }close braces end code blocks and must match an earlier open brace
34
35 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddSquares()
36 {open braces start code blocks and must be matched with a close brace
37 allSquares=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
38 intint is the type for whole numbers and it is short for integer squareAcross=this assignment operator makes the left side equal to the right side5;
39 intint is the type for whole numbers and it is short for integer squareDown=this assignment operator makes the left side equal to the right side5;
40 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i<=this evaluates to true if the left side is not more than the right sidesquareAcross; i++this is the increment operator, which increases the variable by 1)
41 {open braces start code blocks and must be matched with a close brace
42 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer j =this assignment operator makes the left side equal to the right side 0; j<=this evaluates to true if the left side is not more than the right sidesquareDown; j++this is the increment operator, which increases the variable by 1)
43 {open braces start code blocks and must be matched with a close brace
44 square=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(4, 4);
45 square.setSize(0.8/squareAcross);
46 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side.70/squareAcross+adds two numbers together or concatenates Strings together0.9/squareAcross*(i-1);
47 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.05/squareAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.5)/squareAcross;
48 square.setLocation(x, y);
49 square.setColor(Palette.getColor("Green"));
50 square.setVisible(truetrue is the boolean value that is the opposite of false);
51 allSquares.add(square);
52 addSprite(square);
53 }close braces end code blocks and must match an earlier open brace
54 }close braces end code blocks and must match an earlier open brace
55 }close braces end code blocks and must match an earlier open brace
56
57 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddLights()
58 {open braces start code blocks and must be matched with a close brace
59 allLights=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
60 intint is the type for whole numbers and it is short for integer lightAcross=this assignment operator makes the left side equal to the right side5;
61 intint is the type for whole numbers and it is short for integer lightDown=this assignment operator makes the left side equal to the right side5;
62 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i<=this evaluates to true if the left side is not more than the right sidelightAcross; i++this is the increment operator, which increases the variable by 1)
63 {open braces start code blocks and must be matched with a close brace
64 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer j =this assignment operator makes the left side equal to the right side 0; j<=this evaluates to true if the left side is not more than the right sidelightDown; j++this is the increment operator, which increases the variable by 1)
65 {open braces start code blocks and must be matched with a close brace
66 light=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(4, 4);
67 light.setSize(0.8/lightAcross);
68 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side.70/lightAcross+adds two numbers together or concatenates Strings together0.9/lightAcross*(i-1);
69 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.05/lightAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.5)/lightAcross;
70 light.setLocation(x, y);
71 light.setColor(Palette.getColor("Purple"));
72 light.setVisible(truetrue is the boolean value that is the opposite of false);
73 allLights.add(light);
74 addSprite(light);
75 }close braces end code blocks and must match an earlier open brace
76 }close braces end code blocks and must match an earlier open brace
77 }close braces end code blocks and must match an earlier open brace
78
79
80 /**handle input and game events*/
81 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
82 {open braces start code blocks and must be matched with a close brace
83 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
84 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=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)
85 {open braces start code blocks and must be matched with a close brace
86
87 ifif executes the next statement only if the condition in parenthesis evaluates to true (square.intersects (click))
88 {open braces start code blocks and must be matched with a close brace
89 canvas.removeSprite(square);
90 }close braces end code blocks and must match an earlier open brace
91 }close braces end code blocks and must match an earlier open brace
92 }close braces end code blocks and must match an earlier open brace
93 }close braces end code blocks and must match an earlier open brace
|
Download/View MNewman/LightsOutModel.java