|
001 packagepackage is used to name the directory or folder a class is in ChrisHull;
002 importimport means to make the classes and/or packages available in this program fang.*;
003 importimport means to make the classes and/or packages available in this program java.awt.*;
004 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
005
006 /**
007 * LightsOut.
008 * @authorthis is the Javadoc tag for documenting who created the source code Chull
009
010
011 */
012
013 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 LightOutGame extendsextends means to customize or extend the functionality of a class GameLoop
014 {open braces start code blocks and must be matched with a close brace
015 /**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 */
016 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions startYCoord, startXCoord;
017 /**an block*/
018 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 block;
019 /**sets up the game*/
020 privateprivate is used to restrict access to the current class only StringSprite youWin;
021 privateprivate is used to restrict access to the current class only LightsOutModel model;
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
023 {open braces start code blocks and must be matched with a close brace
024
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 makeBricks();
027 addSprites();
028 youWin();
029 canvas.addSprite(youWin);
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 bricks*/
040 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
041 {open braces start code blocks and must be matched with a close brace
042
043 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;
044 block=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 ;
045 intint is the type for whole numbers and it is short for integer numBricksHigh=this assignment operator makes the left side equal to the right side5;
046 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side0.25;
047 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side3.25-startLocationY;
048 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY-startLocationY;
049 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<numBricksHigh; j++this is the increment operator, which increases the variable by 1)
050 {open braces start code blocks and must be matched with a close brace
051 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/(numBricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
052 intint is the type for whole numbers and it is short for integer numBricksAcross=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.1;
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-startLocationX;
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<numBricksAcross; i++this is the increment operator, which increases the variable by 1)
057
058 {open braces start code blocks and must be matched with a close brace
059 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/(numBricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
060 block[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, 1);
061 block[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);
062 block[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/3.5);
063 block[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);
064
065 index++this is the increment operator, which increases the variable by 1;
066 }close braces end code blocks and must match an earlier open brace
067 }close braces end code blocks and must match an earlier open brace
068 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)
069 {open braces start code blocks and must be matched with a close brace
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 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)
071 {open braces start code blocks and must be matched with a close brace
072
073
074 block[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));
075 }close braces end code blocks and must match an earlier open brace
076 }close braces end code blocks and must match an earlier open brace
077 }close braces end code blocks and must match an earlier open brace
078
079
080 /**adds the sprites to the screen*/
081 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
082 {open braces start code blocks and must be matched with a close brace
083 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<block.length; r++this is the increment operator, which increases the variable by 1)
084 {open braces start code blocks and must be matched with a close brace
085 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<block[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)
086 {open braces start code blocks and must be matched with a close brace
087 canvas.addSprite(block[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);;
088 }close braces end code blocks and must match an earlier open brace
089 }close braces end code blocks and must match an earlier open brace
090
091 }close braces end code blocks and must match an earlier open brace
092 /**handle input and game events*/
093 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)
094 {open braces start code blocks and must be matched with a close brace
095
096 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
097 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)
098 {open braces start code blocks and must be matched with a close brace
099 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;
100 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;
101 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)
102 {open braces start code blocks and must be matched with a close brace
103 col=this assignment operator makes the left side equal to the right side0;
104 }close braces end code blocks and must match an earlier open brace
105 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)
106 {open braces start code blocks and must be matched with a close brace
107 col=this assignment operator makes the left side equal to the right side1;
108 }close braces end code blocks and must match an earlier open brace
109 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)
110 {open braces start code blocks and must be matched with a close brace
111 col=this assignment operator makes the left side equal to the right side2;
112 }close braces end code blocks and must match an earlier open brace
113 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)
114 {open braces start code blocks and must be matched with a close brace
115 col=this assignment operator makes the left side equal to the right side3;
116 }close braces end code blocks and must match an earlier open brace
117 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)
118 {open braces start code blocks and must be matched with a close brace
119 col=this assignment operator makes the left side equal to the right side4;
120 }close braces end code blocks and must match an earlier open brace
121 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)
122 {open braces start code blocks and must be matched with a close brace
123 row=this assignment operator makes the left side equal to the right side0;
124 }close braces end code blocks and must match an earlier open brace
125 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)
126 {open braces start code blocks and must be matched with a close brace
127 row=this assignment operator makes the left side equal to the right side1;
128 }close braces end code blocks and must match an earlier open brace
129 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)
130 {open braces start code blocks and must be matched with a close brace
131 row=this assignment operator makes the left side equal to the right side2;
132 }close braces end code blocks and must match an earlier open brace
133 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)
134 {open braces start code blocks and must be matched with a close brace
135 row=this assignment operator makes the left side equal to the right side3;
136 }close braces end code blocks and must match an earlier open brace
137 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)
138 {open braces start code blocks and must be matched with a close brace
139 row=this assignment operator makes the left side equal to the right side4;
140 }close braces end code blocks and must match an earlier open brace
141
142 model.play(row,col);
143 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)
144 {open braces start code blocks and must be matched with a close brace
145 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)
146 {open braces start code blocks and must be matched with a close brace
147
148 youWin.setVisible(model.won());
149 block[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));
150 }close braces end code blocks and must match an earlier open brace
151 }close braces end code blocks and must match an earlier open brace
152
153 }close braces end code blocks and must match an earlier open brace
154
155 }close braces end code blocks and must match an earlier open brace
156
157 }close braces end code blocks and must match an earlier open brace
|