|
001 packagepackage is used to name the directory or folder a class is in Schwarz;
002 //start auto-imports
003 importimport means to make the classes and/or packages available in this program java.util.*;
004 //end auto-imports
005
006 importimport means to make the classes and/or packages available in this program fang2.core.*;
007 importimport means to make the classes and/or packages available in this program fang2.sprites.*;
008 importimport means to make the classes and/or packages available in this program fang2.transformers.*;
009 importimport means to make the classes and/or packages available in this program fang2.attributes.*;
010 importimport means to make the classes and/or packages available in this program java.awt.*;
011 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
012
013 /**
014 * This is the Lights out game where the objective is to get the lights to all go out.
015 * much of thisthis means the current object (the implicit parameter) code was from help in the help sesions.
016 * @authorthis is the Javadoc tag for documenting who created the source code Drew Schwarz
017 */
018
019 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 Game
020 {open braces start code blocks and must be matched with a close brace
021 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 totalBricks;
022 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 lights;
023 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer numberOfRows =this assignment operator makes the left side equal to the right side 5;
024 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer numberOfColumns =this assignment operator makes the left side equal to the right side 5;
025 privateprivate is used to restrict access to the current class only RectangleSprite brick;
026 privateprivate is used to restrict access to the current class only OvalSprite lightbulb;
027 privateprivate is used to restrict access to the current class only 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 side 0, column =this assignment operator makes the left side equal to the right side 0;
028 privateprivate is used to restrict access to the current class only StringSprite win;
029
030 /**sets up the game*/
031 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
032 {open braces start code blocks and must be matched with a close brace
033 removeAllSprites();
034 createBricks();
035 createLights();
036 randomeClicks();
037
038 String helpText =this assignment operator makes the left side equal to the right side
039 "Hello this page teaches you the rulls of the game.<br>" +adds two numbers together or concatenates Strings together
040 "The objective is get all the lights to turn off.<br>" +adds two numbers together or concatenates Strings together
041 "Each click however changes not only the clicked light but also the ones around it in a + shape.<br>" +adds two numbers together or concatenates Strings together
042 "Select r to restart the game.";
043 setHelpText( helpText );
044
045 }close braces end code blocks and must match an earlier open brace
046
047 /** creates the grid forfor is a looping structure for repeatedly executing a block of code the lights on the game bord space invaders game code*/
048 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value createBricks()
049 {open braces start code blocks and must be matched with a close brace
050 totalBricks =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite [brackets are typically used to declare, initialize and index (indicate which element of) arrays 5 ]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 5 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
051
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 side 0; i < numberOfRows; 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 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 < numberOfColumns; j++this is the increment operator, which increases the variable by 1 )
055 {open braces start code blocks and must be matched with a close brace
056 brick =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite( 1, 1 );
057 totalBricks[brackets are typically used to declare, initialize and index (indicate which element of) arrays i ]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 j ]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 side brick;
058 brick.setColor( getColor( "Blue" ) );
059 brick.setSize( 0.9 / numberOfColumns );
060 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side .5 / numberOfColumns +adds two numbers together or concatenates Strings together ( j +adds two numbers together or concatenates Strings together 0.0 ) / numberOfColumns;
061 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side .5 / numberOfRows +adds two numbers together or concatenates Strings together ( i +adds two numbers together or concatenates Strings together 0.0 ) / numberOfRows;
062 brick.setLocation( x, y );
063 brick.setVisible( truetrue is the boolean value that is the opposite of false );
064 addSprite( brick );
065 }close braces end code blocks and must match an earlier open brace
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
069 /** Creates the lightbulbs in the game space invaders game code*/
070 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value createLights()
071 {open braces start code blocks and must be matched with a close brace
072 lights =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays 5 ]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 5 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
073
074 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 0; i < numberOfRows; i++this is the increment operator, which increases the variable by 1 )
075 {open braces start code blocks and must be matched with a close brace
076 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 < numberOfColumns; j++this is the increment operator, which increases the variable by 1 )
077 {open braces start code blocks and must be matched with a close brace
078 lightbulb =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite( 1, 1 );
079 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays i ]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 j ]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 side lightbulb;
080 lightbulb.setColor( getColor( "white" ) );
081 lightbulb.setSize( 0.9 / numberOfColumns );
082 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side .5 / numberOfColumns +adds two numbers together or concatenates Strings together ( j +adds two numbers together or concatenates Strings together 0.0 ) / numberOfColumns;
083 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side .5 / numberOfRows +adds two numbers together or concatenates Strings together ( i +adds two numbers together or concatenates Strings together 0.0 ) / numberOfRows;
084 lightbulb.setLocation( x, y );
085 lightbulb.setVisible( falsefalse is a value for the boolean type and means not true );
086 addSprite( lightbulb );
087 }close braces end code blocks and must match an earlier open brace
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 /**Roher helped me out by sugesting thisthis means the current object (the implicit parameter); keeps track of wether or not thier is a click
092 *then changes the the lightbulb to truetrue is the boolean value that is the opposite of false or flase depending on its position also combined with Joseph Argumedo
093 *code to help get thisthis means the current object (the implicit parameter) to work*/
094 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value checkClick()
095 {open braces start code blocks and must be matched with a close brace
096 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
097
098 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 different nullnull is the value used to refer to a non-existant object )
099 {open braces start code blocks and must be matched with a close brace
100 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 0; i < lights.length; i++this is the increment operator, which increases the variable by 1 )
101 {open braces start code blocks and must be matched with a close brace
102 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 < lights.length; j++this is the increment operator, which increases the variable by 1 )
103 {open braces start code blocks and must be matched with a close brace
104
105 ifif executes the next statement only if the condition in parenthesis evaluates to true ( lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays i ]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 j ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects( click ) )
106
107 {open braces start code blocks and must be matched with a close brace
108 row =this assignment operator makes the left side equal to the right side ( 10 * i +adds two numbers together or concatenates Strings together j ) / 10;
109 column =this assignment operator makes the left side equal to the right side ( 10 * i +adds two numbers together or concatenates Strings together j ) %this divides the left side by the right side and evaluates to the remainder 10;
110 changeLights( row, column );
111 lightRowChange( row, column );
112 lightColumnChange( row, column );
113 }close braces end code blocks and must match an earlier open brace
114 }close braces end code blocks and must match an earlier open brace
115 }close braces end code blocks and must match an earlier open brace
116 }close braces end code blocks and must match an earlier open brace
117 }close braces end code blocks and must match an earlier open brace
118
119 /**changes the lights when you click from falsefalse is a value for the boolean type and means not true to truetrue is the boolean value that is the opposite of false or visaversa*/
120 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value changeLights( intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column )
121 {open braces start code blocks and must be matched with a close brace
122 ifif executes the next statement only if the condition in parenthesis evaluates to true ( lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() &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 &&) lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects( getClick2D() ) )
123 {open braces start code blocks and must be matched with a close brace
124 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( falsefalse is a value for the boolean type and means not true );
125 }close braces end code blocks and must match an earlier open brace
126
127 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true ( lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() ==this is the comparison operator which evaluates to true if both sides are the same falsefalse is a value for the boolean type and means not true &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 &&) lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects( getClick2D() ) )
128 {open braces start code blocks and must be matched with a close brace
129 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( truetrue is the boolean value that is the opposite of false );
130 }close braces end code blocks and must match an earlier open brace
131 }close braces end code blocks and must match an earlier open brace
132
133 /**changes the light above and below the secelcted lightbulb had help from rohers program to start thisthis means the current object (the implicit parameter) thisthis means the current object (the implicit parameter)
134 * then modified it to make it so that it would not click outside the row's length noticed Joseph Argumedo used
135 * ifif executes the next statement only if the condition in parenthesis evaluates to true statments to dodo is part of the do-while looping structure (post condition loop) his so i borowd thisthis means the current object (the implicit parameter) idea*/
136 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value lightRowChange( intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column )
137 {open braces start code blocks and must be matched with a close brace
138 ifif executes the next statement only if the condition in parenthesis evaluates to true ( row !=this is the not equals operator which evaluates to true if both sides are different 4 )
139 {open braces start code blocks and must be matched with a close brace
140 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row +adds two numbers together or concatenates Strings together 1 ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( !this is the not operator, which changes true to false and false to truelights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row +adds two numbers together or concatenates Strings together 1 ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() );
141 }close braces end code blocks and must match an earlier open brace
142
143 ifif executes the next statement only if the condition in parenthesis evaluates to true ( row !=this is the not equals operator which evaluates to true if both sides are different 0 )
144 {open braces start code blocks and must be matched with a close brace
145 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row - 1 ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( !this is the not operator, which changes true to false and false to truelights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row - 1 ]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 column ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() );
146 }close braces end code blocks and must match an earlier open brace
147 }close braces end code blocks and must match an earlier open brace
148
149 /**changes the lights to the left and right of the selected lightbulb had help from rohers program to start thisthis means the current object (the implicit parameter) thisthis means the current object (the implicit parameter)
150 * then modified it to make it so that it would not click outside the row's lengthnoticed Joseph Argumedo used
151 * ifif executes the next statement only if the condition in parenthesis evaluates to true statments to dodo is part of the do-while looping structure (post condition loop) his so i borowd thisthis means the current object (the implicit parameter) idea*/
152 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value lightColumnChange( intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column )
153 {open braces start code blocks and must be matched with a close brace
154 ifif executes the next statement only if the condition in parenthesis evaluates to true ( column !=this is the not equals operator which evaluates to true if both sides are different 4 )
155 {open braces start code blocks and must be matched with a close brace
156 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column +adds two numbers together or concatenates Strings together 1 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( !this is the not operator, which changes true to false and false to truelights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column +adds two numbers together or concatenates Strings together 1 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() );
157 }close braces end code blocks and must match an earlier open brace
158
159 ifif executes the next statement only if the condition in parenthesis evaluates to true ( column !=this is the not equals operator which evaluates to true if both sides are different 0 )
160 {open braces start code blocks and must be matched with a close brace
161 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column - 1 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible( !this is the not operator, which changes true to false and false to truelights[brackets are typically used to declare, initialize and index (indicate which element of) arrays row ]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 column - 1 ]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() );
162 }close braces end code blocks and must match an earlier open brace
163 }close braces end code blocks and must match an earlier open brace
164
165 /**Randomly clicks to turn on lights within the game*/
166 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomeClicks()
167 {open braces start code blocks and must be matched with a close brace
168 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 side 0; r < 5; r++this is the increment operator, which increases the variable by 1 )
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 side ( intint is the type for whole numbers and it is short for integer ) ( 4 * Math.random() );
171 column =this assignment operator makes the left side equal to the right side ( intint is the type for whole numbers and it is short for integer ) ( 4 * Math.random() );
172 lightColumnChange( row, column );
173 lightRowChange( row, column );
174 }close braces end code blocks and must match an earlier open brace
175 }close braces end code blocks and must match an earlier open brace
176
177 /**handle input and game events*/
178 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
179 {open braces start code blocks and must be matched with a close brace
180 checkClick();
181
182 ifif executes the next statement only if the condition in parenthesis evaluates to true ( getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 'r' )
183 {open braces start code blocks and must be matched with a close brace
184 removeAllSprites();
185 setup();
186 }close braces end code blocks and must match an earlier open brace
187 }close braces end code blocks and must match an earlier open brace
188 }close braces end code blocks and must match an earlier open brace
|