|
001 packagepackage is used to name the directory or folder a class is in WilliamAnderson;
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 William Anderson
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 LightsGame 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 privateprivate is used to restrict access to the current class only LightsOutModel model;
015
016 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 Light =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) 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;
017 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 tiles =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) 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;
018 privateprivate is used to restrict access to the current class only StringSprite youWin;
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 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
023 makeSprites();
024 addSprites();
025 youWin();
026 setHelpText("Click once to randomize the order of the lights, Any clicks after the first one will alternate a light and its surrounding lights between the off and on states. White squares indicate the light is on. The goal of the game is to turn off all of the lights.");
027
028
029 }close braces end code blocks and must match an earlier open brace
030
031 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
032 {open braces start code blocks and must be matched with a close brace
033 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 < tiles.length; i++this is the increment operator, which increases the variable by 1)
034 {open braces start code blocks and must be matched with a close brace
035 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 o =this assignment operator makes the left side equal to the right side 0; o < tiles.length; o++this is the increment operator, which increases the variable by 1)
036 {open braces start code blocks and must be matched with a close brace
037 tiles[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) arrayso]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 newnew is used to create objects by calling the constructor RectangleSprite(1, 1);
038 tiles[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(.17);
039 tiles[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.1 +adds two numbers together or concatenates Strings together .2 * i, .2 * o +adds two numbers together or concatenates Strings together .1);
040 tiles[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.BLACK);
041 canvas.addSprite(tiles[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
042 Light[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) arrayso]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 newnew is used to create objects by calling the constructor RectangleSprite(1, 1);
043 Light[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(.17);
044 Light[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.1 +adds two numbers together or concatenates Strings together .2 * i, .2 * o +adds two numbers together or concatenates Strings together .1);
045 Light[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.WHITE);
046 canvas.addSprite(Light[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
047 }close braces end code blocks and must match an earlier open brace
048 }close braces end code blocks and must match an earlier open brace
049
050 }close braces end code blocks and must match an earlier open brace
051
052
053
054
055
056
057
058 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
059 {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
060
061 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value youWin()
062 {open braces start code blocks and must be matched with a close brace
063 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");
064 youWin.setHeight(0.1);
065 youWin.setLocation(.5, .5);
066 youWin.setVisible(falsefalse is a value for the boolean type and means not true);
067 }close braces end code blocks and must match an earlier open brace
068
069
070
071 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)
072 {open braces start code blocks and must be matched with a close brace
073 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
074 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)
075 {open braces start code blocks and must be matched with a close brace
076 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;
077 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;
078 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)
079 {open braces start code blocks and must be matched with a close brace
080 col=this assignment operator makes the left side equal to the right side0;
081 }close braces end code blocks and must match an earlier open brace
082 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)
083 {open braces start code blocks and must be matched with a close brace
084 col=this assignment operator makes the left side equal to the right side1;
085 }close braces end code blocks and must match an earlier open brace
086 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)
087 {open braces start code blocks and must be matched with a close brace
088 col=this assignment operator makes the left side equal to the right side2;
089 }close braces end code blocks and must match an earlier open brace
090 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)
091 {open braces start code blocks and must be matched with a close brace
092 col=this assignment operator makes the left side equal to the right side3;
093 }close braces end code blocks and must match an earlier open brace
094 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)
095 {open braces start code blocks and must be matched with a close brace
096 col=this assignment operator makes the left side equal to the right side4;
097 }close braces end code blocks and must match an earlier open brace
098 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)
099 {open braces start code blocks and must be matched with a close brace
100 row=this assignment operator makes the left side equal to the right side0;
101 }close braces end code blocks and must match an earlier open brace
102 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)
103 {open braces start code blocks and must be matched with a close brace
104 row=this assignment operator makes the left side equal to the right side1;
105 }close braces end code blocks and must match an earlier open brace
106 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)
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 side2;
109 }close braces end code blocks and must match an earlier open brace
110 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)
111 {open braces start code blocks and must be matched with a close brace
112 row=this assignment operator makes the left side equal to the right side3;
113 }close braces end code blocks and must match an earlier open brace
114 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)
115 {open braces start code blocks and must be matched with a close brace
116 row=this assignment operator makes the left side equal to the right side4;
117 }close braces end code blocks and must match an earlier open brace
118
119 model.play(row,col);
120 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 o=this assignment operator makes the left side equal to the right side0; o<5; o++this is the increment operator, which increases the variable by 1)
121 {open braces start code blocks and must be matched with a close 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 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)
123 {open braces start code blocks and must be matched with a close brace
124
125 youWin.setVisible(model.won());
126 Light[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) arrayso]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(model.isOn(o, i));
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
132 }close braces end code blocks and must match an earlier open brace
133
134
135 }close braces end code blocks and must match an earlier open brace
136
137
|