|
001 packagepackage is used to name the directory or folder a class is in Hemendra.lights;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**
009 * All about my game here.
010 * @authorthis is the Javadoc tag for documenting who created the source code Hpullay
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 LightsOut extendsextends means to customize or extend the functionality of a class GameLoop
013 {open braces start code blocks and must be matched with a close brace
014 /**makes block*/
015 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays blocks;
016 /**sets up the game*/
017 privateprivate is used to restrict access to the current class only LightsOutModel model;
018 /**makes ovals*/
019 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays oval;
020 /**the coordinates forfor is a looping structure for repeatedly executing a block of code x and y that the game uses forfor is a looping structure for repeatedly executing a block of code spacing */
021 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions startYCoord, startXCoord;
022
023 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
024 {open braces start code blocks and must be matched with a close brace
025 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
026 makeBlocks();
027 makeOval();
028 addSprites();
029 setHelpText
030 ("Make all the blue lights disappear to win game.");
031
032 }close braces end code blocks and must match an earlier open brace
033
034 /**Makes the blocks*/
035
036 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeOval()
037 {open braces start code blocks and must be matched with a close brace
038 intint is the type for whole numbers and it is short for integer index=this assignment operator makes the left side equal to the right side0;
039 oval=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays5]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arrays5]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
040 intint is the type for whole numbers and it is short for integer numBlocksHigh=this assignment operator makes the left side equal to the right side5;
041 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.17;
042 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side1-startLocationY;
043 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY+adds two numbers together or concatenates Strings togetherstartLocationY;
044 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 side0; j<numBlocksHigh; j++this is the increment operator, which increases the variable by 1)
045 {open braces start code blocks and must be matched with a close brace
046 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidej*distanceHigh/(numBlocksHigh+adds two numbers together or concatenates Strings together1)+adds two numbers together or concatenates Strings togetherstartLocationY;
047
048 intint is the type for whole numbers and it is short for integer numBlocksAcross=this assignment operator makes the left side equal to the right side5;
049 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side0.17;
050 doubledouble is the type for numbers that can contain decimal fractions endLocationX=this assignment operator makes the left side equal to the right side1-startLocationX;
051 doubledouble is the type for numbers that can contain decimal fractions distanceAcross=this assignment operator makes the left side equal to the right sideendLocationX+adds two numbers together or concatenates Strings togetherstartLocationX;
052 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 side0; i<numBlocksAcross; i++this is the increment operator, which increases the variable by 1)
053 {open braces start code blocks and must be matched with a close brace
054 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidei*distanceAcross/(numBlocksAcross+adds two numbers together or concatenates Strings together1)+adds two numbers together or concatenates Strings togetherstartLocationX;
055 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
056 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.15);
057 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y);
058 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.BLUE);
059 index++this is the increment operator, which increases the variable by 1;
060 /*Makes the ovals to add to the game.*/
061 }close braces end code blocks and must match an earlier open brace
062 }close braces end code blocks and must match an earlier open brace
063 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 side0; j<5; j++this is the increment operator, which increases the variable by 1)
064 {open braces start code blocks and must be matched with a close brace
065 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 side0; i<5; i++this is the increment operator, which increases the variable by 1)
066 {open braces start code blocks and must be matched with a close brace
067 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(model.isOn(i, j));
068 }close braces end code blocks and must match an earlier open brace
069 }close braces end code blocks and must match an earlier open brace
070 }close braces end code blocks and must match an earlier open brace
071 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBlocks()
072 {open braces start code blocks and must be matched with a close brace
073 intint is the type for whole numbers and it is short for integer index=this assignment operator makes the left side equal to the right side0;
074 blocks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays5]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arrays5]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
075 intint is the type for whole numbers and it is short for integer numBlocksHigh=this assignment operator makes the left side equal to the right side5;
076 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.17;
077 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side1-startLocationY;
078 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY+adds two numbers together or concatenates Strings togetherstartLocationY;
079 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 side0; j<numBlocksHigh; j++this is the increment operator, which increases the variable by 1)
080 {open braces start code blocks and must be matched with a close brace
081 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidej*distanceHigh/(numBlocksHigh+adds two numbers together or concatenates Strings together1)+adds two numbers together or concatenates Strings togetherstartLocationY;
082
083 intint is the type for whole numbers and it is short for integer numBlocksAcross=this assignment operator makes the left side equal to the right side5;
084 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side0.17;
085 doubledouble is the type for numbers that can contain decimal fractions endLocationX=this assignment operator makes the left side equal to the right side1-startLocationX;
086 doubledouble is the type for numbers that can contain decimal fractions distanceAcross=this assignment operator makes the left side equal to the right sideendLocationX+adds two numbers together or concatenates Strings togetherstartLocationX;
087 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 side0; i<numBlocksAcross; i++this is the increment operator, which increases the variable by 1)
088 {open braces start code blocks and must be matched with a close brace
089 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidei*distanceAcross/(numBlocksAcross+adds two numbers together or concatenates Strings together1)+adds two numbers together or concatenates Strings togetherstartLocationX;
090 blocks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1,1);
091 blocks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.15);
092 blocks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y);
093 blocks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.RED);
094 index++this is the increment operator, which increases the variable by 1;
095 /*Makes the blocks to add to the game.*/
096 }close braces end code blocks and must match an earlier open brace
097 }close braces end code blocks and must match an earlier open brace
098 }close braces end code blocks and must match an earlier open brace
099
100 /**adds the sprites to the screen*/
101 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
102 {open braces start code blocks and must be matched with a close brace
103 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 r=this assignment operator makes the left side equal to the right side0; r<blocks.length; r++this is the increment operator, which increases the variable by 1)
104 {open braces start code blocks and must be matched with a close brace
105 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 c=this assignment operator makes the left side equal to the right side0; c<blocks[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.length; c++this is the increment operator, which increases the variable by 1)
106 {open braces start code blocks and must be matched with a close brace
107 canvas.addSprite(blocks[brackets are typically used to declare, initialize and index (indicate which element of) arraysr]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysc]brackets are typically used to declare, initialize and index (indicate which element of) arrays);;
108 }close braces end code blocks and must match an earlier open brace
109 }close braces end code blocks and must match an earlier open brace
110 /**Adds the blocks to the game.*/
111
112 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 r=this assignment operator makes the left side equal to the right side0; r<oval.length; r++this is the increment operator, which increases the variable by 1)
113 {open braces start code blocks and must be matched with a close brace
114 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 c=this assignment operator makes the left side equal to the right side0; c<oval[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.length; c++this is the increment operator, which increases the variable by 1)
115 {open braces start code blocks and must be matched with a close brace
116 canvas.addSprite(oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysr]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysc]brackets are typically used to declare, initialize and index (indicate which element of) arrays);;
117 }close braces end code blocks and must match an earlier open brace
118 }close braces end code blocks and must match an earlier open brace
119 /**Adds the ovals to the game.*/
120
121 }close braces end code blocks and must match an earlier open brace
122 /**handle input and game events*/
123 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)
124 {open braces start code blocks and must be matched with a close brace
125 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
126 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)
127 {open braces start code blocks and must be matched with a close brace
128 intint is the type for whole numbers and it is short for integer row=this assignment operator makes the left side equal to the right side0;
129 intint is the type for whole numbers and it is short for integer col=this assignment operator makes the left side equal to the right side0;
130 ifif executes the next statement only if the condition in parenthesis evaluates to true(click.x> 0 &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 &&) click.x <=this evaluates to true if the left side is not more than the right side .2)
131 {open braces start code blocks and must be matched with a close brace
132 col=this assignment operator makes the left side equal to the right side0;
133 }close braces end code blocks and must match an earlier open brace
134 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(click.x> .2 &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 &&) click.x <=this evaluates to true if the left side is not more than the right side .4)
135 {open braces start code blocks and must be matched with a close brace
136 col=this assignment operator makes the left side equal to the right side1;
137 }close braces end code blocks and must match an earlier open brace
138 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(click.x> .4 &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 &&) click.x <=this evaluates to true if the left side is not more than the right side .6)
139 {open braces start code blocks and must be matched with a close brace
140 col=this assignment operator makes the left side equal to the right side2;
141 }close braces end code blocks and must match an earlier open brace
142 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (click.x> .6 &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 &&) click.x <=this evaluates to true if the left side is not more than the right side .8)
143 {open braces start code blocks and must be matched with a close brace
144 col=this assignment operator makes the left side equal to the right side3;
145 }close braces end code blocks and must match an earlier open brace
146 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (click.x> .8 &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 &&) click.x <=this evaluates to true if the left side is not more than the right side 1)
147 {open braces start code blocks and must be matched with a close brace
148 col=this assignment operator makes the left side equal to the right side4;
149 }close braces end code blocks and must match an earlier open brace
150 ifif executes the next statement only if the condition in parenthesis evaluates to true(click.y> 0 &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 &&) click.y <=this evaluates to true if the left side is not more than the right side .2)
151 {open braces start code blocks and must be matched with a close brace
152 row=this assignment operator makes the left side equal to the right side0;
153 }close braces end code blocks and must match an earlier open brace
154 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(click.y> .2 &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 &&) click.y <=this evaluates to true if the left side is not more than the right side .4)
155 {open braces start code blocks and must be matched with a close brace
156 row=this assignment operator makes the left side equal to the right side1;
157 }close braces end code blocks and must match an earlier open brace
158 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (click.y> .4 &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 &&) click.y <=this evaluates to true if the left side is not more than the right side .6)
159 {open braces start code blocks and must be matched with a close brace
160 row=this assignment operator makes the left side equal to the right side2;
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(click.y> .6 &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 &&) click.y <=this evaluates to true if the left side is not more than the right side .8)
163 {open braces start code blocks and must be matched with a close brace
164 row=this assignment operator makes the left side equal to the right side3;
165 }close braces end code blocks and must match an earlier open brace
166 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(click.y> .8 &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 &&) click.y <=this evaluates to true if the left side is not more than the right side 1)
167 {open braces start code blocks and must be matched with a close brace
168 row=this assignment operator makes the left side equal to the right side4;
169 }close braces end code blocks and must match an earlier open brace
170
171 model.play(row,col);
172 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 side0; j<5; j++this is the increment operator, which increases the variable by 1)
173 {open braces start code blocks and must be matched with a close brace
174 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 side0; i<5; i++this is the increment operator, which increases the variable by 1)
175 {open braces start code blocks and must be matched with a close brace
176 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(model.isOn(i, j));
177 }close braces end code blocks and must match an earlier open brace
178 }close braces end code blocks and must match an earlier open brace
179
180 }close braces end code blocks and must match an earlier open brace
181 }close braces end code blocks and must match an earlier open brace
182
183 }close braces end code blocks and must match an earlier open brace
|