|
001 packagepackage is used to name the directory or folder a class is in cray;
002
003 importimport means to make the classes and/or packages available in this program cray.LightsModel.*;
004 importimport means to make the classes and/or packages available in this program grid.*;
005 importimport means to make the classes and/or packages available in this program wiki.Wiki;
006 importimport means to make the classes and/or packages available in this program fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009
010 /**
011 * All about my game here.
012 @authorthis is the Javadoc tag for documenting who created the source code Cray
013 */
014 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 LightsGraphic extendsextends means to customize or extend the functionality of a class GameLoop
015 {open braces start code blocks and must be matched with a close brace
016
017 privateprivate is used to restrict access to the current class only Sprite grid;
018 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 dots;
019 privateprivate is used to restrict access to the current class only LightsModel lightsModel;
020 privateprivate is used to restrict access to the current class only StringSprite victory;
021 privateprivate is used to restrict access to the current class only Sound clip=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Pong.wav");
022 privateprivate is used to restrict access to the current class only Sound clip2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Kidscheer.wav");
023 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
024
025
026 /**sets up the game*/
027 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
028 {open braces start code blocks and must be matched with a close brace
029 lightsModel=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsModel();
030 makeSprites();
031 addSprites();
032 makeDots();
033 }close braces end code blocks and must match an earlier open brace
034
035 /**makes the sprites*/
036 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
037 {open braces start code blocks and must be matched with a close brace
038 grid=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);
039 grid.setScale(1);
040 grid.setLocation(0.5, 0.5);
041
042 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(
043 random.nextDouble()-0.5,
044 random.nextDouble()-0.5);
045 tracker.setAngularVelocity(1);
046
047 victory=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Epic \nWin!");
048 victory.setHeight(.25);
049 victory.setColor(Color.RED);
050 victory.setLocation(0.5,0.5);
051 victory.setFontFamilyName("Castellar");
052 }close braces end code blocks and must match an earlier open brace
053
054 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeDots()
055 {open braces start code blocks and must be matched with a close brace
056 dots=this assignment operator makes the left side equal to the right sidenewnew 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;
057 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)
058 {open braces start code blocks and must be matched with a close brace
059 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)
060 {open braces start code blocks and must be matched with a close brace
061 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;
062 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;
063 dots[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 OvalSprite (1,1);
064 dots[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/7)/1.2);
065 dots[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);
066 dots[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.setColor(Color.GREEN);
067 canvas.addSprite(dots[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);
068 }close braces end code blocks and must match an earlier open brace
069
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 publicpublic is used to indicate unrestricted access (any other class can have access) Point getCell(Point2D.Double point)
073 {open braces start code blocks and must be matched with a close brace
074 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);
075 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);
076 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);
077 }close braces end code blocks and must match an earlier open brace
078
079 /**adds the sprites to the screen*/
080 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
081 {open braces start code blocks and must be matched with a close brace
082 canvas.addSprite(grid);
083 }close braces end code blocks and must match an earlier open brace
084
085 /**handle input and game events*/
086 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)
087 {open braces start code blocks and must be matched with a close brace
088 Point2D.Double leftClick=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLeftClickLocation();
089 ifif executes the next statement only if the condition in parenthesis evaluates to true(lightsModel.won()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
090 {open braces start code blocks and must be matched with a close brace
091 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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)
092 {open braces start code blocks and must be matched with a close brace
093 Point cell=this assignment operator makes the left side equal to the right sidegetCell(leftClick);
094 lightsModel.play(cell.y, cell.x);
095 clip.play();
096
097 }close braces end code blocks and must match an earlier open brace
098 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<dots.length; r++this is the increment operator, which increases the variable by 1)
099 {open braces start code blocks and must be matched with a close brace
100 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<dots[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)
101 {open braces start code blocks and must be matched with a close brace
102 dots[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(lightsModel.isOn(r, c));
103 }close braces end code blocks and must match an earlier open brace
104 }close braces end code blocks and must match an earlier open brace
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(lightsModel.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)
107 {open braces start code blocks and must be matched with a close brace
108 canvas.removeSprite(grid);
109 canvas.addSprite(victory);
110 victory.setTracker(tracker);
111 ifif executes the next statement only if the condition in parenthesis evaluates to true(victory.getLocation().y>1 ||this is boolean or, meaning if either or both are true then the result is true victory.getLocation().y<0)
112 {open braces start code blocks and must be matched with a close brace
113 Point2D.Double direction=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
114 direction.y*=this multiplies the variable on the left by the value on the right and stores the result in the variable-1;
115 tracker.setVelocity(direction);
116 tracker.setAngularVelocity(-tracker.getAngularVelocity());
117 }close braces end code blocks and must match an earlier open brace
118 ifif executes the next statement only if the condition in parenthesis evaluates to true(victory.getLocation().x>1 ||this is boolean or, meaning if either or both are true then the result is true victory.getLocation().x<0)
119 {open braces start code blocks and must be matched with a close brace
120 Point2D.Double direction=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
121 direction.x*=this multiplies the variable on the left by the value on the right and stores the result in the variable-1;
122 tracker.setVelocity(direction);
123 tracker.setAngularVelocity(-tracker.getAngularVelocity());
124 }close braces end code blocks and must match an earlier open brace
125
126
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 }close braces end code blocks and must match an earlier open brace
|