|
001 packagepackage is used to name the directory or folder a class is in Merima;
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 Merima Omanovic
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 LightsOutProject 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
015 privateprivate is used to restrict access to the current class only OvalSprite[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 circles;
016 privateprivate is used to restrict access to the current class only StringSprite youWin;
017 privateprivate is used to restrict access to the current class only LightsOutModel model;
018 privateprivate is used to restrict access to the current class only RectangleSprite[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 squares;
019
020 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
021 {open braces start code blocks and must be matched with a close brace
022
023 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
024 makeCircles();
025 makeSquares();
026 addSprites();
027 youWin();
028 canvas.addSprite(youWin);
029
030 }close braces end code blocks and must match an earlier open brace
031 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value youWin()
032 {open braces start code blocks and must be matched with a close brace
033 youWin=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Win");
034 youWin.setHeight(0.1);
035 youWin.setLocation(.5, .5);
036 youWin.setVisible(falsefalse is a value for the boolean type and means not true);
037 }close braces end code blocks and must match an earlier open brace
038
039 /**Makes the circles*/
040 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeCircles()
041 {open braces start code blocks and must be matched with a close brace
042 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;
043 circles=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite[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;
044 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;
045 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;
046 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;
047 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;
048 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)
049 {open braces start code blocks and must be matched with a close brace
050 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;
051
052 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;
053 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;
054 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;
055 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;
056 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)
057 {open braces start code blocks and must be matched with a close brace
058 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;
059 circles[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(2,2);
060 circles[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.18);
061 circles[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((0.2 * (i +adds two numbers together or concatenates Strings together 1)) - 0.1, (0.2 * (j +adds two numbers together or concatenates Strings together 1)) - 0.1);
062
063 circles[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.GREEN);
064 //canvas.addSprite(circles[index]);
065 index++this is the increment operator, which increases the variable by 1;
066 /*Add the circles to the game.*/
067 }close braces end code blocks and must match an earlier open brace
068 }close braces end code blocks and must match an earlier open brace
069
070 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)
071 {open braces start code blocks and must be matched with a close brace
072 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)
073 {open braces start code blocks and must be matched with a close brace
074
075
076 circles[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));
077 }close braces end code blocks and must match an earlier open brace
078 }close braces end code blocks and must match an earlier open brace
079 }close braces end code blocks and must match an earlier open brace
080 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSquares()
081 {open braces start code blocks and must be matched with a close brace
082 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;
083 squares=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite[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;
084 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;
085 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;
086 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;
087 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;
088 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)
089 {open braces start code blocks and must be matched with a close brace
090 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;
091
092 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;
093 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;
094 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;
095 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;
096 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)
097 {open braces start code blocks and must be matched with a close brace
098 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;
099 squares[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(2,2);
100 squares[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.18);
101 squares[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((0.2 * (i +adds two numbers together or concatenates Strings together 1)) - 0.1, (0.2 * (j +adds two numbers together or concatenates Strings together 1)) - 0.1);
102
103 squares[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.WHITE);
104 index++this is the increment operator, which increases the variable by 1;
105 /*Make the squares.*/
106 }close braces end code blocks and must match an earlier open brace
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
110
111 /**adds the sprites to the screen*/
112 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
113
114 {open braces start code blocks and must be matched with a close brace
115 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<squares.length; r++this is the increment operator, which increases the variable by 1)
116 {open braces start code blocks and must be matched with a close brace
117 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<squares[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)
118 {open braces start code blocks and must be matched with a close brace
119 canvas.addSprite(squares[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);;
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 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<circles.length; r++this is the increment operator, which increases the variable by 1)
123 {open braces start code blocks and must be matched with a close brace
124 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<circles[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)
125 {open braces start code blocks and must be matched with a close brace
126 canvas.addSprite(circles[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);;
127 }close braces end code blocks and must match an earlier open brace
128 }close braces end code blocks and must match an earlier open brace
129
130 }close braces end code blocks and must match an earlier open brace
131 /**handle input and game events*/
132 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)
133 {open braces start code blocks and must be matched with a close brace
134
135 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
136 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)
137 {open braces start code blocks and must be matched with a close brace
138 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;
139 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;
140 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)
141 {open braces start code blocks and must be matched with a close brace
142 col=this assignment operator makes the left side equal to the right side0;
143 }close braces end code blocks and must match an earlier open brace
144 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)
145 {open braces start code blocks and must be matched with a close brace
146 col=this assignment operator makes the left side equal to the right side1;
147 }close braces end code blocks and must match an earlier open brace
148 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)
149 {open braces start code blocks and must be matched with a close brace
150 col=this assignment operator makes the left side equal to the right side2;
151 }close braces end code blocks and must match an earlier open brace
152 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)
153 {open braces start code blocks and must be matched with a close brace
154 col=this assignment operator makes the left side equal to the right side3;
155 }close braces end code blocks and must match an earlier open brace
156 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)
157 {open braces start code blocks and must be matched with a close brace
158 col=this assignment operator makes the left side equal to the right side4;
159 }close braces end code blocks and must match an earlier open brace
160 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)
161 {open braces start code blocks and must be matched with a close brace
162 row=this assignment operator makes the left side equal to the right side0;
163 }close braces end code blocks and must match an earlier open brace
164 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)
165 {open braces start code blocks and must be matched with a close brace
166 row=this assignment operator makes the left side equal to the right side1;
167 }close braces end code blocks and must match an earlier open brace
168 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)
169 {open braces start code blocks and must be matched with a close brace
170 row=this assignment operator makes the left side equal to the right side2;
171 }close braces end code blocks and must match an earlier open brace
172 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)
173 {open braces start code blocks and must be matched with a close brace
174 row=this assignment operator makes the left side equal to the right side3;
175 }close braces end code blocks and must match an earlier open brace
176 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)
177 {open braces start code blocks and must be matched with a close brace
178 row=this assignment operator makes the left side equal to the right side4;
179 }close braces end code blocks and must match an earlier open brace
180
181 model.play(row,col);
182 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)
183 {open braces start code blocks and must be matched with a close brace
184 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)
185 {open braces start code blocks and must be matched with a close brace
186
187 youWin.setVisible(model.won());
188 circles[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));
189 }close braces end code blocks and must match an earlier open brace
190 }close braces end code blocks and must match an earlier open brace
191
192 }close braces end code blocks and must match an earlier open brace
193
194 }close braces end code blocks and must match an earlier open brace
195
196 }close braces end code blocks and must match an earlier open brace
|