|
01 packagepackage is used to name the directory or folder a class is in Wilson;
02
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 importimport means to make the classes and/or packages available in this program fang.*;
05 importimport means to make the classes and/or packages available in this program java.awt.*;
06
07 /**
08 * All about my game.
09 * @authorthis is the Javadoc tag for documenting who created the source code Wilson Green
10 */
11 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 lightsOutGUI extendsextends means to customize or extend the functionality of a class Game
12 {open braces start code blocks and must be matched with a close brace
13 RectangleSprite singleBox;
14 RectangleSprite[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 box =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays10]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) arrays10]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
15 intint is the type for whole numbers and it is short for integer x;
16 /**This calls the display() method to set up all of the squares*/
17 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
18 {open braces start code blocks and must be matched with a close brace
19 display();
20 }close braces end code blocks and must match an earlier open brace
21 /**
22 *This method sets up all the squares in an array, it has two forfor is a looping structure for repeatedly executing a block of code loops forfor is a looping structure for repeatedly executing a block of code rows and colums
23 *Also randomizes a number between 1 and 2 and ifif executes the next statement only if the condition in parenthesis evaluates to true its 1 then set the block to be blue, otherwise white
24 */
25 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value display()
26 {open braces start code blocks and must be matched with a close brace
27 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<10; i++this is the increment operator, which increases the variable by 1)
28 {open braces start code blocks and must be matched with a close brace
29 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 l=this assignment operator makes the left side equal to the right side0; l<10; l++this is the increment operator, which increases the variable by 1)
30 {open braces start code blocks and must be matched with a close brace
31 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.random()*3);
32 singleBox =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1,1);
33 singleBox.setSize(.098);
34 ifif executes the next statement only if the condition in parenthesis evaluates to true(x==this is the comparison operator which evaluates to true if both sides are the same1)
35 singleBox.setColor(getColor("BLUE"));
36 elseelse is what happens when the if condition is false
37 singleBox.setColor(getColor("WHITE"));
38 singleBox.setLocation((i+adds two numbers together or concatenates Strings together.5)/10,(l+adds two numbers together or concatenates Strings together.5)/10);
39 box[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) arraysl]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 sidesingleBox;
40 addSprite(singleBox);
41 }close braces end code blocks and must match an earlier open brace
42 }close braces end code blocks and must match an earlier open brace
43 }close braces end code blocks and must match an earlier open brace
44 /**
45 *This method makes it so you can click on a box and change its color and the boxes up,down,left, and right of it
46 *When wanting to change the color it calls the invertBlock() method
47 */
48 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clickBox()
49 {open braces start code blocks and must be matched with a close brace
50 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<10; j++this is the increment operator, which increases the variable by 1)
51 {open braces start code blocks and must be matched with a close brace
52 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 k=this assignment operator makes the left side equal to the right side0; k<10; k++this is the increment operator, which increases the variable by 1)
53 {open braces start code blocks and must be matched with a close brace
54 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D() !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) getClick2D().intersects(box[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[brackets are typically used to declare, initialize and index (indicate which element of) arraysk]brackets are typically used to declare, initialize and index (indicate which element of) arrays))
55 {open braces start code blocks and must be matched with a close brace
56 invertBlock(box[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[brackets are typically used to declare, initialize and index (indicate which element of) arraysk]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
57 ifif executes the next statement only if the condition in parenthesis evaluates to true (j-1 >=this evaluates to true if the left side is not less than the right side0)
58 invertBlock(box[brackets are typically used to declare, initialize and index (indicate which element of) arraysj-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) arraysk]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
59 ifif executes the next statement only if the condition in parenthesis evaluates to true (j+adds two numbers together or concatenates Strings together1 <=this evaluates to true if the left side is not more than the right side 9)
60 invertBlock(box[brackets are typically used to declare, initialize and index (indicate which element of) arraysj+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) arraysk]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
61 ifif executes the next statement only if the condition in parenthesis evaluates to true (k-1 >=this evaluates to true if the left side is not less than the right side 0)
62 invertBlock(box[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[brackets are typically used to declare, initialize and index (indicate which element of) arraysk-1]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
63 ifif executes the next statement only if the condition in parenthesis evaluates to true (k+adds two numbers together or concatenates Strings together1 <=this evaluates to true if the left side is not more than the right side 9)
64 invertBlock(box[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[brackets are typically used to declare, initialize and index (indicate which element of) arraysk+adds two numbers together or concatenates Strings together1]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
65 }close braces end code blocks and must match an earlier open brace
66 }close braces end code blocks and must match an earlier open brace
67 }close braces end code blocks and must match an earlier open brace
68 }close braces end code blocks and must match an earlier open brace
69 /**
70 *This method inverts the RectangleSprite that you tell it to
71 *@paramthis is the Javadoc tag for documenting the purpose of parameters block - thisthis means the current object (the implicit parameter) is the rectangle sprite that you want to invert
72 */
73 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value invertBlock(RectangleSprite block)
74 {open braces start code blocks and must be matched with a close brace
75 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(block.getColor()) ==this is the comparison operator which evaluates to true if both sides are the same getColorName(getColor("BLUE")))
76 block.setColor(getColor("WHITE"));
77 elseelse is what happens when the if condition is false
78 block.setColor(getColor("BLUE"));
79
80 }close braces end code blocks and must match an earlier open brace
81
82 /**handle input and game events
83 *Calls the clickBox() method to change the color of the blocks.
84 */
85 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
86 {open braces start code blocks and must be matched with a close brace
87 clickBox();
88 }close braces end code blocks and must match an earlier open brace
89 }close braces end code blocks and must match an earlier open brace
|