|
001 packagepackage is used to name the directory or folder a class is in Mkim;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006 /**from summer classclass is a group of fields and methods used for making objects(also in API)*/
007 importimport means to make the classes and/or packages available in this program grid.*;
008 /** implementing the lights out model that Dr.Jenkins created*/
009 importimport means to make the classes and/or packages available in this program Mkim.*;
010
011 /**
012 * lights out. point of the game either turn on all the lights
013 * or turn off aghts to win the game.
014 * got helped from Jason. Jason helped me in implementing the classclass is a group of fields and methods used for making objects and gave me the idea to
015 * use the array of 5X5
016 * @authorthis is the Javadoc tag for documenting who created the source code min.
017 */
018 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 Lightout extendsextends means to customize or extend the functionality of a class Game
019 {open braces start code blocks and must be matched with a close brace
020 /**Field Declaration of Sprite named board*/
021 privateprivate is used to restrict access to the current class only Sprite board;
022 /** OvalSprite Declaration named light*/
023 privateprivate is used to restrict access to the current class only OvalSprite light;
024 /**array declaration newnew is used to create objects by calling the constructor Sprite 5X5*/
025 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 =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;
026 /** intint is the type for whole numbers and it is short for integer of row*/
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;
028 /** intint is the type for whole numbers and it is short for integer of column*/
029 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer col;
030 /** model that Dr. jenkins created*/
031 privateprivate is used to restrict access to the current class only LightsOutModel gameWork;
032 /**make help*/
033 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helps()
034 {open braces start code blocks and must be matched with a close brace
035 String helpText=this assignment operator makes the left side equal to the right side
036 "first click to turn on the random light "+adds two numbers together or concatenates Strings together
037 "if you turn off all the lights than you win";
038 setHelpText(helpText);
039 }close braces end code blocks and must match an earlier open brace
040 /**makes the board 5 by 5 grid Grid(first value goes down, second value goes across,
041 size of the grid)*/
042 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBoard()
043 {open braces start code blocks and must be matched with a close brace
044 board=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Grid(5, 5, 0.06);
045 board.setScale(1);
046 board.setLocation(0.5, 0.5);
047 board.setColor(Palette.getColor("blue"));
048 addSprite(board);
049 }close braces end code blocks and must match an earlier open brace
050 /**Array of Light OvalSprite
051 used the base loop forfor is a looping structure for repeatedly executing a block of code square grid */
052 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeLight()
053 {open braces start code blocks and must be matched with a close brace
054 intint is the type for whole numbers and it is short for integer lightAcross=this assignment operator makes the left side equal to the right side5;
055 intint is the type for whole numbers and it is short for integer lightDown=this assignment operator makes the left side equal to the right side5;
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<lightAcross; 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 side0; j<lightAcross; 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 light.setSize(0.18);
062 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/lightAcross+adds two numbers together or concatenates Strings together1.0/lightAcross*(i);
063 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/lightAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.0)/lightAcross;
064 light.setLocation(x, y);
065 light.setColor(Palette.getColor("green"));
066 light.setVisible(falsefalse is a value for the boolean type and means not true);
067 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 side light;
068 addSprite(light);
069 }close braces end code blocks and must match an earlier open brace
070 }close braces end code blocks and must match an earlier open brace
071 }close braces end code blocks and must match an earlier open brace
072 /** thisthis means the current object (the implicit parameter) will set the light on or off depending on the booleanboolean is a type that is either true or false
073 *since the cells is a booleanboolean is a type that is either true or false it will returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false or falsefalse is a value for the boolean type and means not true
074 *so it will either turn off the light or on (Jason gave me the idea.)*/
075 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateBox()
076 {open braces start code blocks and must be matched with a close brace
077 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)
078 {open braces start code blocks and must be matched with a close brace
079 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)
080 {open braces start code blocks and must be matched with a close brace
081 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.setVisible(gameWork.cells[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);
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 /**sets up the game*/
086 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
087 {open braces start code blocks and must be matched with a close brace
088 /**makes the grid calling it*/
089 makeBoard();
090 /** make the array of a oval 25 lights calling it*/
091 makeLight();
092 /** calling the radom lights to be on*/
093 gameWork =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LightsOutModel();
094 /** getting the random lights to turn on from the lights out model
095 that Dr.J wrote*/
096 gameWork.randomPlay();
097 /** sets up the help method*/
098 helps();
099 }close braces end code blocks and must match an earlier open brace
100 /**handle input and game events*/
101 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
102 {open braces start code blocks and must be matched with a close brace
103 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
104 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)
105 {open braces start code blocks and must be matched with a close brace
106 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)
107 {open braces start code blocks and must be matched with a close brace
108 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)
109 {open braces start code blocks and must be matched with a close brace
110
111 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) 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.intersects(click))
112 {open braces start code blocks and must be matched with a close brace
113 row=this assignment operator makes the left side equal to the right sidei;
114 col=this assignment operator makes the left side equal to the right sidej;
115 gameWork.play(row,col);
116 updateBox();
117 }close braces end code blocks and must match an earlier open brace
118 }close braces end code blocks and must match an earlier open brace
119 }close braces end code blocks and must match an earlier open brace
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 }close braces end code blocks and must match an earlier open brace
|