|
01 packagepackage is used to name the directory or folder a class is in Anam;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 //end auto-imports
05
06 importimport means to make the classes and/or packages available in this program fang.*;
07 importimport means to make the classes and/or packages available in this program java.awt.*;
08 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
09
10 /**
11 * All about my game.
12 * @authornull Anam Mughal with the enormous help from Derrick Dixon
13 and Michael and Frank and using the model provided by Dr. Jenkins.
14 */
15 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 lightsoutgame extendsextends means to customize or extend the functionality of a class Game
16 {open braces start code blocks and must be matched with a close brace
17 //Declares the circles, the strings, and the model.
18 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 circles=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) arrays7]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) arrays7]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
19 privateprivate is used to restrict access to the current class only StringSprite won;
20 privateprivate is used to restrict access to the current class only StringSprite won2;
21 privateprivate is used to restrict access to the current class only LightsOutModel model;
22 //This is Dr. Jenkin's model that I made some changes and used it
23
24 /**sets up the game*/
25 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
26 {open braces start code blocks and must be matched with a close brace
27 allCircles();
28 youWon();
29 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
30 }close braces end code blocks and must match an earlier open brace
31 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value allCircles()
32 {open braces start code blocks and must be matched with a close brace
33 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<circles.length; i++this is the increment operator, which increases the variable by 1)
34 {open braces start code blocks and must be matched with a close brace
35 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<circles.length; j++this is the increment operator, which increases the variable by 1)
36 {open braces start code blocks and must be matched with a close brace
37 circles [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 sidenewnew is used to create objects by calling the constructor OvalSprite(2, 2);
38
39 circles [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.setSize(.15);
40 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side0.5/5+adds two numbers together or concatenates Strings together0.98/5*(i-1);
41 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.5/5+adds two numbers together or concatenates Strings together0.98/5*(j-1);
42 circles [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.setLocation(x, y);
43 circles [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.setColor(Palette.getColor("Blue Violet"));
44 circles [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(falsefalse is a value for the boolean type and means not true);
45 addSprite(circles [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);
46 //the above creates a board of 5 by 5 circles (but does not show yet)
47
48
49 }close braces end code blocks and must match an earlier open brace
50 }close braces end code blocks and must match an earlier open brace
51 }close braces end code blocks and must match an earlier open brace
52 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value youWon()
53 {open braces start code blocks and must be matched with a close brace
54 won=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite ("CONGRATS, You Won!!!");
55 won.setSize(0.85);
56 won.setLocation(0.50, 0.50);
57 won.setColor(Palette.getColor("SILVER"));
58 won.setVisible(falsefalse is a value for the boolean type and means not true);
59 addSprite(won);
60
61 won2=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite ("Click Reload to Play Again!");
62 won2.setSize(0.50);
63 won2.setLocation(0.50, 0.70);
64 won2.setColor(Palette.getColor("SILVER"));
65 won2.setVisible(falsefalse is a value for the boolean type and means not true);
66 addSprite(won2);
67 //the above creates the messages to appear at the end of the game.
68 }close braces end code blocks and must match an earlier open brace
69
70 /**handle input and game events*/
71 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
72 {open braces start code blocks and must be matched with a close brace
73 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 side 0;
74 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 side 0;
75
76 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
77 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)
78 {open braces start code blocks and must be matched with a close brace
79 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)(click.y*5)+adds two numbers together or concatenates Strings together1;
80 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)(click.x*5)+adds two numbers together or concatenates Strings together1;
81 // The two equations above were given by Dr. Jenkins
82 model.play(row,col);
83 }close braces end code blocks and must match an earlier open brace
84 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<circles.length; i++this is the increment operator, which increases the variable by 1)
85 {open braces start code blocks and must be matched with a close brace
86 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<circles.length; j++this is the increment operator, which increases the variable by 1)
87 {open braces start code blocks and must be matched with a close brace
88 circles[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(model.isOn(i, j));
89 //randomly adds circles to the screen
90 won.setVisible(model.won());
91 won2.setVisible(model.won());
92 //goes back to the model; if the person wins the messages appear.
93 //Derrick helped me a lot with this assignment.
94
95 }close braces end code blocks and must match an earlier open brace
96 }close braces end code blocks and must match an earlier open brace
97 }close braces end code blocks and must match an earlier open brace
98 }close braces end code blocks and must match an earlier open brace
|