|
001 packagepackage is used to name the directory or folder a class is in alyday;
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 importimport means to make the classes and/or packages available in this program grid.*;
008
009 /**
010 * All about my game here.
011 * @authorthis is the Javadoc tag for documenting who created the source code Alyday
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 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 /**an oval*/
016 privateprivate is used to restrict access to the current class only Sprite space;
017 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 oval=this assignment operator makes the left side equal to the right sidenewnew 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;
018 privateprivate is used to restrict access to the current class only RectangleSprite background;
019 privateprivate is used to restrict access to the current class only LightsOutModel lightsOut;
020 privateprivate is used to restrict access to the current class only StringSprite fin;
021
022 /**sets up the game*/
023 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
024 {open braces start code blocks and must be matched with a close brace
025 lightsOut=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
026 makeSprites();
027 addSprites();
028 }close braces end code blocks and must match an earlier open brace
029
030 /**makes the sprites*/
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 a=this assignment operator makes the left side equal to the right side0; a<5; a++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 b=this assignment operator makes the left side equal to the right side0; b<5; b++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 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side(b+adds two numbers together or concatenates Strings together0.5)/5;
038 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side(a+adds two numbers together or concatenates Strings together0.5)/5;
039 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysa]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) arraysb]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 sidenewnew is used to create objects by calling the constructor ImageSprite ("Hamster.jpg");
040 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysa]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) arraysb]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale((1.0/5)/1.2);
041 oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysa]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) arraysb]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x, y);
042 }close braces end code blocks and must match an earlier open brace
043 }close braces end code blocks and must match an earlier open brace
044 space=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.05);
045 space.setScale(1.0);
046 space.setLocation(0.5, 0.5);
047 space.setColor(Color.YELLOW);
048
049 background=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite (2,1);
050 background.setScale(2.0);
051 background.setLocation(0.5, 0.5);
052
053 fin=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("You Won!");
054 fin.setScale(1.0);
055 fin.setLocation(0.5, 0.5);
056 fin.setColor(newnew is used to create objects by calling the constructor Color(180,0,0));
057 fin.setFontFamilyName("Bauhaus 93");
058
059 }close braces end code blocks and must match an earlier open brace
060
061 /**adds the sprites to the screen*/
062 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
063 {open braces start code blocks and must be matched with a close brace
064 canvas.addSprite(background);
065 canvas.addSprite(space);
066 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 side0; a<5; a++this is the increment operator, which increases the variable by 1)
067 {open braces start code blocks and must be matched with a close brace
068 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 side0; b<5; b++this is the increment operator, which increases the variable by 1)
069 {open braces start code blocks and must be matched with a close brace
070 canvas.addSprite(oval[brackets are typically used to declare, initialize and index (indicate which element of) arraysa]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) arraysb]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
071 }close braces end code blocks and must match an earlier open brace
072 }close braces end code blocks and must match an earlier open brace
073
074 }close braces end code blocks and must match an earlier open brace
075
076 publicpublic is used to indicate unrestricted access (any other class can have access) Point getCell(Point2D.Double point)
077 {open braces start code blocks and must be matched with a close brace
078 intint is the type for whole numbers and it is short for integer x=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.min(4, point.x*5);
079 intint is the type for whole numbers and it is short for integer y=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.min(4, point.y*5);
080 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Point(x, y);
081 }close braces end code blocks and must match an earlier open brace
082
083 /**handle input and game events*/
084 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)
085 {open braces start code blocks and must be matched with a close brace
086 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getMouse().getClickLocation()!=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)
087 {open braces start code blocks and must be matched with a close brace
088 Point cell=this assignment operator makes the left side equal to the right sidegetCell(getPlayer().getMouse().getClickLocation());
089 lightsOut.play(cell.y, cell.x);
090 }close braces end code blocks and must match an earlier open brace
091 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<oval.length; r++this is the increment operator, which increases the variable by 1)
092 {open braces start code blocks and must be matched with a close brace
093 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<oval[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.length; c++this is the increment operator, which increases the variable by 1)
094 {open braces start code blocks and must be matched with a close brace
095 oval[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.setVisible(lightsOut.isOn(r, c));
096 }close braces end code blocks and must match an earlier open brace
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 (lightsOut.won()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
099 {open braces start code blocks and must be matched with a close brace
100 canvas.removeSprite(space);
101 canvas.removeSprite(background);
102 canvas.addSprite(fin);
103 }close braces end code blocks and must match an earlier open brace
104
105 }close braces end code blocks and must match an earlier open brace
106 }close braces end code blocks and must match an earlier open brace
|