|
001 packagepackage is used to name the directory or folder a class is in Charles;
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 fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009
010 /**
011 * All about my game.
012 * @authorthis is the Javadoc tag for documenting who created the source code Charles
013 */
014 /**Used Frank Anderson's LightsOut to get an idea forfor is a looping structure for repeatedly executing a block of code the game structure*/
015 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
016 {open braces start code blocks and must be matched with a close brace
017 /**Creates the grid of boxes displayed as the playing board*/
018 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allBoxes;
019 /**the image used to display the lights on the board*/
020 privateprivate is used to restrict access to the current class only OvalSprite light;
021 /**array list of the lights to be displayed*/
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) arrayslights =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays7]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) arrays7]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
023 /**used to identify the horizantal position of an individual light*/
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 hor=this assignment operator makes the left side equal to the right side0;
025 /**used to identify the vertical position of an individual light*/
026 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer vert=this assignment operator makes the left side equal to the right side0;
027 /**sets up the game*/
028 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
029 {open braces start code blocks and must be matched with a close brace
030 makeBoxes();
031 makeLights();
032 }close braces end code blocks and must match an earlier open brace
033 /** Creates the boxes that hold the light*/
034 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBoxes()
035 {open braces start code blocks and must be matched with a close brace
036 allBoxes=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
037 intint is the type for whole numbers and it is short for integer boxesAcross=this assignment operator makes the left side equal to the right side5;
038 intint is the type for whole numbers and it is short for integer boxesDown=this assignment operator makes the left side equal to the right side5;
039 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<boxesDown; j++this is the increment operator, which increases the variable by 1)
040 {open braces start code blocks and must be matched with a close brace
041 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 side1; i<=this evaluates to true if the left side is not more than the right sideboxesAcross; i++this is the increment operator, which increases the variable by 1)
042 {open braces start code blocks and must be matched with a close brace
043 RectangleSprite box=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1,1);
044 box.setSize(0.9/boxesAcross);
045 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side0.5/boxesAcross+adds two numbers together or concatenates Strings together1.0/boxesAcross*(i-1);
046 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.5/boxesAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.0)/boxesAcross;
047 box.setLocation(x,y);
048 box.setColor(getColor("gray"));
049 addSprite(box);
050 }close braces end code blocks and must match an earlier open brace
051 }close braces end code blocks and must match an earlier open brace
052 }close braces end code blocks and must match an earlier open brace
053 /**creates and adds the lights that are displayed on the grid already turned off*/
054 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeLights()
055 {open braces start code blocks and must be matched with a close brace
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<=this evaluates to true if the left side is not more than the right side6;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 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer j =this assignment operator makes the left side equal to the right side 0;j<=this evaluates to true if the left side is not more than the right side6;j++this is the increment operator, which increases the variable by 1)
059 {open braces start code blocks and must be matched with a close brace
060 light =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
061 lights[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 sidelight;
062 light.setSize(.18);
063 light.setLocation(-.1+adds two numbers together or concatenates Strings together (i)*.2, -.1+adds two numbers together or concatenates Strings together(j)*.2);
064 light.setColor(getColor("red"));
065 light.setVisible(falsefalse is a value for the boolean type and means not true);
066 addSprite(light);
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 }close braces end code blocks and must match an earlier open brace
070 /**returns the a value of i&this performs a bit-wise and (not the same as boolean and which is &&)j to determine which light was selected*/
071 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer getSelectedLight()
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 loc=this assignment operator makes the left side equal to the right side0;
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 side1; i<=this evaluates to true if the left side is not more than the right side5; 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 side1; j<=this evaluates to true if the left side is not more than the right side5; 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 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=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 &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 &&) getClick2D().intersects(lights[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))
079 {open braces start code blocks and must be matched with a close brace
080 loc =this assignment operator makes the left side equal to the right side 10*i+adds two numbers together or concatenates Strings togetherj;
081 returnreturn means to provide the result of the method and/or cease execution of the method immediately loc;
082 }close braces end code blocks and must match an earlier open brace
083 }close braces end code blocks and must match an earlier open brace
084 }close braces end code blocks and must match an earlier open brace
085 returnreturn means to provide the result of the method and/or cease execution of the method immediately 0;
086 }close braces end code blocks and must match an earlier open brace
087 /**turns on and off the selected light*/
088 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value lightSwitch(intint is the type for whole numbers and it is short for integer hor, intint is the type for whole numbers and it is short for integer vert)
089 {open braces start code blocks and must be matched with a close brace
090 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) arrayshor]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) arraysvert]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
091 {open braces start code blocks and must be matched with a close brace
092 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor]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) arraysvert]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);
093 }close braces end code blocks and must match an earlier open brace
094 elseelse is what happens when the if condition is false
095 {open braces start code blocks and must be matched with a close brace
096 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor]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) arraysvert]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);
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 /**switches the lights to the left, right top and bottom of the selected light*/
100 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value switchLightsInGroups(intint is the type for whole numbers and it is short for integer hor, intint is the type for whole numbers and it is short for integer vert)
101 {open braces start code blocks and must be matched with a close brace
102 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) arrayshor+adds two numbers together or concatenates Strings together1]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) arraysvert]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
103 {open braces start code blocks and must be matched with a close brace
104 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor+adds two numbers together or concatenates Strings together1]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) arraysvert]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);
105 }close braces end code blocks and must match an earlier open brace
106 elseelse is what happens when the if condition is false
107 {open braces start code blocks and must be matched with a close brace
108 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor+adds two numbers together or concatenates Strings together1]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) arraysvert]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);
109 }close braces end code blocks and must match an earlier open brace
110 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) arrayshor-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) arraysvert]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
111 {open braces start code blocks and must be matched with a close brace
112 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor-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) arraysvert]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);
113 }close braces end code blocks and must match an earlier open brace
114 elseelse is what happens when the if condition is false
115 {open braces start code blocks and must be matched with a close brace
116 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor-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) arraysvert]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);
117 }close braces end code blocks and must match an earlier open brace
118 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) arrayshor]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) arraysvert+adds two numbers together or concatenates Strings together1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
119 {open braces start code blocks and must be matched with a close brace
120 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor]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) arraysvert+adds two numbers together or concatenates Strings together1]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);
121 }close braces end code blocks and must match an earlier open brace
122 elseelse is what happens when the if condition is false
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) arrayshor]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) arraysvert+adds two numbers together or concatenates Strings together1]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);
125 }close braces end code blocks and must match an earlier open brace
126 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) arrayshor]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) arraysvert-1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
127 {open braces start code blocks and must be matched with a close brace
128 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor]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) arraysvert-1]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);
129 }close braces end code blocks and must match an earlier open brace
130 elseelse is what happens when the if condition is false
131 {open braces start code blocks and must be matched with a close brace
132 lights[brackets are typically used to declare, initialize and index (indicate which element of) arrayshor]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) arraysvert-1]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);
133 }close braces end code blocks and must match an earlier open brace
134 }close braces end code blocks and must match an earlier open brace
135 //generatePatterns();
136 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
137 /**handle input and game events*/
138 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
139 {open braces start code blocks and must be matched with a close brace
140 /**gets the previously determined location of the selected light and convertes the values so that it appropriately matches the grid*/
141 intint is the type for whole numbers and it is short for integer locationOfLight=this assignment operator makes the left side equal to the right sidegetSelectedLight();
142 ifif executes the next statement only if the condition in parenthesis evaluates to true(locationOfLight!=this is the not equals operator which evaluates to true if both sides are different0)
143 {open braces start code blocks and must be matched with a close brace
144 intint is the type for whole numbers and it is short for integer xOfLight=this assignment operator makes the left side equal to the right sidelocationOfLight/10;
145 intint is the type for whole numbers and it is short for integer yOfLight=this assignment operator makes the left side equal to the right sidelocationOfLight%this divides the left side by the right side and evaluates to the remainder10;
146 lightSwitch(xOfLight, yOfLight);
147 switchLightsInGroups(xOfLight, yOfLight);
148 }close braces end code blocks and must match an earlier open brace
149 }close braces end code blocks and must match an earlier open brace
150 }close braces end code blocks and must match an earlier open brace
|