|
001 packagepackage is used to name the directory or folder a class is in NickandChris.lights;
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 Nmckee
011 */
012 //Graphical interface class
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 LightsOut 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 //Sets up the squares and declares how many elements are in the array
016 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 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) 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 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 =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) 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 LightsOutModel model;
019 privateprivate is used to restrict access to the current class only StringSprite youWin;
020
021 //Declares the LightsOutModel class to model and creates the sprites
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 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
025 makeSprites();
026 youWin();
027
028 }close braces end code blocks and must match an earlier open brace
029
030 //Sets up the for loops on how wide and high the board will be while giving declaring their colors and size
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 < 5; 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 u =this assignment operator makes the left side equal to the right side 0; u < 5; u++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 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) arraysu]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 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.18);
039 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.WHITE);
040 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) arraysu]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 * u +adds two numbers together or concatenates Strings together .1);
041
042 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) arraysu]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 OvalSprite(1, 1);
043 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.17);
044 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.RED);
045 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) arraysu]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 * u +adds two numbers together or concatenates Strings together .1);
046
047 canvas.addSprite(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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays, 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
048 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(model.isOn(u, i));
049 }close braces end code blocks and must match an earlier open brace
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 //Defines what happens when all lights are cleared
053 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value youWin()
054 {open braces start code blocks and must be matched with a close brace
055 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");
056 youWin.setHeight(0.1);
057 youWin.setLocation(.5, .5);
058 youWin.setVisible(falsefalse is a value for the boolean type and means not true);
059 }close braces end code blocks and must match an earlier open brace
060
061
062 //Sets up the boundaries between each light(column & row) if clicked on
063 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)
064 {open braces start code blocks and must be matched with a close brace
065 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
066 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)
067 {open braces start code blocks and must be matched with a close brace
068 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;
069 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;
070 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)
071 {open braces start code blocks and must be matched with a close brace
072 col=this assignment operator makes the left side equal to the right side0;
073 }close braces end code blocks and must match an earlier open brace
074 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)
075 {open braces start code blocks and must be matched with a close brace
076 col=this assignment operator makes the left side equal to the right side1;
077 }close braces end code blocks and must match an earlier open brace
078 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)
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 side2;
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> .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)
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 side3;
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> .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)
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 side4;
089 }close braces end code blocks and must match an earlier open brace
090 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)
091 {open braces start code blocks and must be matched with a close brace
092 row=this assignment operator makes the left side equal to the right side0;
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.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)
095 {open braces start code blocks and must be matched with a close brace
096 row=this assignment operator makes the left side equal to the right side1;
097 }close braces end code blocks and must match an earlier open brace
098 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)
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 side2;
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> .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)
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 side3;
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> .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)
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 side4;
109 }close braces end code blocks and must match an earlier open brace
110 //Goes to LightsOutModel to find which row and column is in use
111 model.play(row,col);
112 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)
113 {open braces start code blocks and must be matched with a close brace
114 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 u=this assignment operator makes the left side equal to the right side0; u<5; u++this is the increment operator, which increases the variable by 1)
115 {open braces start code blocks and must be matched with a close brace
116 //Goes to LightsOutModel won and turns off visibility for lights
117
118 youWin.setVisible(model.won());
119 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) arraysu]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(model.isOn(u, i));
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
123 }close braces end code blocks and must match an earlier open brace
124
125
126 }close braces end code blocks and must match an earlier open brace
127 }close braces end code blocks and must match an earlier open brace
|