|
001 packagepackage is used to name the directory or folder a class is in Argumedo;
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
007 /**
008 * All about my game.
009 * @authorthis is the Javadoc tag for documenting who created the source code Joseph Argumedo
010 * I looked at Frank Andersons and Min Kim's code in order to figure out how
011 * I can make my lights turn on and off simultaneously.
012 */
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 Assignment8 extendsextends means to customize or extend the functionality of a class Game
014 {open braces start code blocks and must be matched with a close brace
015 /**Allows to create the background of where the lightbulbs will be on top of*/
016 privateprivate is used to restrict access to the current class only RectangleSprite board;
017 /**Allows to use an image of a lightbulb. It is in place of the dots*/
018 privateprivate is used to restrict access to the current class only ImageSprite shawneMerriman;
019 /**Allows to create a 2d-array forfor is a looping structure for repeatedly executing a block of code the images of th lightbulbs
020 which will be used to play the game*/
021 privateprivate is used to restrict access to the current class only ImageSprite[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 chargers =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite[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;
022 /**Set the integer row(Across) to zero*/
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 row=this assignment operator makes the left side equal to the right side0;
024 /**Set the integer column(Down) to zero*/
025 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=this assignment operator makes the left side equal to the right side0;
026 /**Imported a sound to the game that will be used in the start of the game*/
027 privateprivate is used to restrict access to the current class only Sound electricCurrent=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sound ("Electric_current.wav");
028
029 /**sets up the game*/
030 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
031 {open braces start code blocks and must be matched with a close brace
032 gameBoard();
033 ShawneMerriman();
034 lightsOnOff();
035 electricCurrent();
036 playSoundImmediately();
037 }close braces end code blocks and must match an earlier open brace
038 /**Plays the sound clip at the start of the game*/
039 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value electricCurrent()
040 {open braces start code blocks and must be matched with a close brace
041 electricCurrent.play(0.0);
042 }close braces end code blocks and must match an earlier open brace
043 /**Creates a forfor is a looping structure for repeatedly executing a block of code loop forfor is a looping structure for repeatedly executing a block of code the silver gameBoard(5 X 5) that
044 is made up of Rectangle Sprites*/
045 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value gameBoard()
046 {open braces start code blocks and must be matched with a close brace
047 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 a=this assignment operator makes the left side equal to the right side1; a<=this evaluates to true if the left side is not more than the right side6;a++this is the increment operator, which increases the variable by 1)
048 {open braces start code blocks and must be matched with a close brace
049 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 b=this assignment operator makes the left side equal to the right side1;b<=this evaluates to true if the left side is not more than the right side6;b++this is the increment operator, which increases the variable by 1)
050 {open braces start code blocks and must be matched with a close brace
051 board=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1,1);
052 board.setSize(0.19);
053 board.setLocation(-0.1+adds two numbers together or concatenates Strings together(a-1)*0.2, -0.1+adds two numbers together or concatenates Strings together(b-1)*0.2);
054 board.setColor(getColor("Silver"));
055 addSprite(board);
056 }close braces end code blocks and must match an earlier open brace
057 }close braces end code blocks and must match an earlier open brace
058 }close braces end code blocks and must match an earlier open brace
059 /**Creates the images of lightbulbs from a forfor is a looping structure for repeatedly executing a block of code loop plus a two d-array
060 that will be used in place of the circles*/
061 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value ShawneMerriman()
062 {open braces start code blocks and must be matched with a close brace
063 intint is the type for whole numbers and it is short for integer shawneMerrimanRow=this assignment operator makes the left side equal to the right side5;
064 intint is the type for whole numbers and it is short for integer shawneMerrimanCol=this assignment operator makes the left side equal to the right side5;
065 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 side0; r<shawneMerrimanRow; r++this is the increment operator, which increases the variable by 1)
066 {open braces start code blocks and must be matched with a close brace
067 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 c=this assignment operator makes the left side equal to the right side0; c<shawneMerrimanRow; c++this is the increment operator, which increases the variable by 1)
068 {open braces start code blocks and must be matched with a close brace
069 shawneMerriman=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("LIGHTBULB.JPG");
070 shawneMerriman.setSize(0.18);
071 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/shawneMerrimanRow+adds two numbers together or concatenates Strings together1.0/shawneMerrimanRow*(r);
072 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/shawneMerrimanRow+adds two numbers together or concatenates Strings together(c+adds two numbers together or concatenates Strings together0.0)/shawneMerrimanRow;
073 shawneMerriman.setLocation(x, y);
074 shawneMerriman.setColor(getColor("Yellow"));
075 shawneMerriman.setVisible(falsefalse is a value for the boolean type and means not true);
076 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysr]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) arraysc]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 shawneMerriman;
077 addSprite(shawneMerriman);
078 }close braces end code blocks and must match an earlier open brace
079 }close braces end code blocks and must match an earlier open brace
080 }close braces end code blocks and must match an earlier open brace
081 /**Creates the randomization of lightbulbs at the start of the game.
082 It also allows the lightbulbs to move a certian pattern which is the result of
083 lights turning on or off horizontal or verticaly when it is clicked on by the user*/
084 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value lightsOnOff()
085 {open braces start code blocks and must be matched with a close brace
086 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)
087 {open braces start code blocks and must be matched with a close brace
088 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)Math.round(4*Math.random());
089 col=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)Math.round(4*Math.random());
090 changeShawneMerriman(row, col);
091 changeShawneMerrimanPlusSign(row, col);
092 }close braces end code blocks and must match an earlier open brace
093 }close braces end code blocks and must match an earlier open brace
094 /**Turns lights on and off only when the user playing clicks on a lightbulb*/
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value changeShawneMerriman(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 col)
096 {open braces start code blocks and must be matched with a close brace
097 ifif executes the next statement only if the condition in parenthesis evaluates to true(chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible())
098 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol]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);
099 elseelse is what happens when the if condition is false
100 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol]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);
101 }close braces end code blocks and must match an earlier open brace
102 /**Allows the lightbulbs to turn off and off horizontally or vertically */
103 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value changeShawneMerrimanPlusSign(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 col)
104 {open braces start code blocks and must be matched with a close brace
105 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)
106 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow+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) arrayscol]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 truechargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow+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) arrayscol]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible());
107 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 different0)
108 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow-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) arrayscol]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 truechargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow-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) arrayscol]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible());
109 ifif executes the next statement only if the condition in parenthesis evaluates to true(col !=this is the not equals operator which evaluates to true if both sides are different 4)
110 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol+adds two numbers together or concatenates Strings together1]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 truechargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol+adds two numbers together or concatenates Strings together1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible());
111 ifif executes the next statement only if the condition in parenthesis evaluates to true(col !=this is the not equals operator which evaluates to true if both sides are different 0)
112 chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol-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 truechargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysrow]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) arrayscol-1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible());
113 }close braces end code blocks and must match an earlier open brace
114 /**Allows to click on the Lights which will turn on and off during the game*/
115 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clickLights()
116 {open braces start code blocks and must be matched with a close brace
117 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
118 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)
119 {open braces start code blocks and must be matched with a close brace
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 r =this assignment operator makes the left side equal to the right side 0; r < chargers.length; r++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 c =this assignment operator makes the left side equal to the right side 0; c<chargers.length; c++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 ifif executes the next statement only if the condition in parenthesis evaluates to true (chargers[brackets are typically used to declare, initialize and index (indicate which element of) arraysr]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) arraysc]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(click))
125 {open braces start code blocks and must be matched with a close brace
126 row=this assignment operator makes the left side equal to the right side(10*r+adds two numbers together or concatenates Strings togetherc)/10;
127 col=this assignment operator makes the left side equal to the right side(10*r+adds two numbers together or concatenates Strings togetherc)%this divides the left side by the right side and evaluates to the remainder10;
128 changeShawneMerriman(row, col);
129 changeShawneMerrimanPlusSign(row, col);
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 }close braces end code blocks and must match an earlier open brace
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
136 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
137 {open braces start code blocks and must be matched with a close brace
138 clickLights();
139 }close braces end code blocks and must match an earlier open brace
140 }close braces end code blocks and must match an earlier open brace
|