|
001 importimport means to make the classes and/or packages available in this program fang.*;
002 importimport means to make the classes and/or packages available in this program java.awt.*;
003 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
004 importimport means to make the classes and/or packages available in this program Derrick.*;
005 /**
006 * All about my game.
007 * @ Recipe provided by Jam Jekins
008 * game Cook Derrick Dixon I must give credit to Frank I thought of the idea of going off the
009 *board however Frank succesfully used the idea first. Once Frank successfully implemented
010 *the idea I then was able to see how the idea looked in a program. I then changed the model
011 *using thisthis means the current object (the implicit parameter) idea. Also the casting idea came from Anam &this performs a bit-wise and (not the same as boolean and which is &&) Frank we sat together after classclass is a group of fields and methods used for making objects
012 *last week. I used it in my program but couldn't gtet it to work so I took it out. After
013 *sitting with Dr. J the equation used forfor is a looping structure for repeatedly executing a block of code finding the location was talked about once again
014 *so I reused the code Anam Frank and I wrote.
015 * Frank Dr. Jenkins and Anamn helped me with thisthis means the current object (the implicit parameter) Assignment.
016 */
017 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 AssignmentEightLightsOutGame extendsextends means to customize or extend the functionality of a class Game
018 {open braces start code blocks and must be matched with a close brace /** col and row is the initial value of the
019 * number of columns and rows */
020 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, row;
021 /** thisthis means the current object (the implicit parameter) sprite is used to display a winning message and help box*/
022 privateprivate is used to restrict access to the current class only StringSprite winner, helpBox;
023 /** Is Dr. Jenkins with my enhancements Lights Model*/
024 privateprivate is used to restrict access to the current class only Derrick.LightsOutModel workingGame;
025 /** used recatangle forfor is a looping structure for repeatedly executing a block of code the games board*/
026 privateprivate is used to restrict access to the current class only RectangleSprite gameBoard;
027 /** is an Array that stores the lights in the game. */
028
029 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 lights =this assignment operator makes the left side equal to the right side newnew 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;
030
031 /**makes and creates help box.*/
032
033 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddGetHelp()
034 {open braces start code blocks and must be matched with a close brace
035 String helpBox=this assignment operator makes the left side equal to the right side
036 "Press start to begin.<br>"+adds two numbers together or concatenates Strings together
037 "Once You Win is displayed<br>"+adds two numbers together or concatenates Strings together
038 "Click Reload to start again!";
039
040 setHelpText(helpBox);
041 }close braces end code blocks and must match an earlier open brace
042 /**Creates a winning message.*/
043 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value createWinningMessage()
044 {open braces start code blocks and must be matched with a close brace
045 winner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Win");
046 winner.setColor(getColor("White"));
047 winner.setSize(0.40);
048 winner.setLocation(0.5,0.5);
049 addSprite(winner);
050 winner.setVisible(falsefalse is a value for the boolean type and means not true);
051 }close braces end code blocks and must match an earlier open brace
052 /**Creates a game board using a forfor is a looping structure for repeatedly executing a block of code loop*/
053 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value createGameBoard()
054 {open braces start code blocks and must be matched with a close brace
055 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 side1;i<=this evaluates to true if the left side is not more than the right side6;i++this is the increment operator, which increases the variable by 1)
056 {open braces start code blocks and must be matched with a close brace
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 j=this assignment operator makes the left side equal to the right side1;j<=this evaluates to true if the left side is not more than the right side6;j++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 gameBoard =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);
060 gameBoard.setSize(0.19);
061
062 gameBoard.setLocation(((i-1)/10.0)+adds two numbers together or concatenates Strings together(.10 * i), ((j-1)/10.0)+adds two numbers together or concatenates Strings together(.10 * j));
063 addSprite(gameBoard);
064 }close braces end code blocks and must match an earlier open brace
065 }close braces end code blocks and must match an earlier open brace
066 }close braces end code blocks and must match an earlier open brace
067 /**Creates a lights using a forfor is a looping structure for repeatedly executing a block of code loop in a 2d array*/
068 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value createLights()
069 {open braces start code blocks and must be matched with a close brace
070 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 side 0;i<=this evaluates to true if the left side is not more than the right side6;i++this is the increment operator, which increases the variable by 1)
071 {open braces start code blocks and must be matched with a close brace
072 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 side 0;j<=this evaluates to true if the left side is not more than the right side6;j++this is the increment operator, which increases the variable by 1)
073 {open braces start code blocks and must be matched with a close brace
074 lights[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 side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
075 lights[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(0.19);
076 lights[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(getColor("white"));
077 lights[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(((i-1)/10.0)+adds two numbers together or concatenates Strings together(.10 * i), ((j-1)/10.0)+adds two numbers together or concatenates Strings together(.10 * j));
078 addSprite( lights[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);
079 lights[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);
080 }close braces end code blocks and must match an earlier open brace
081 }close braces end code blocks and must match an earlier open brace
082 }close braces end code blocks and must match an earlier open brace
083
084
085 /**sets up the game*/
086 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
087 {open braces start code blocks and must be matched with a close brace
088 makeAndAddGetHelp();
089 workingGame =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Derrick.LightsOutModel();
090 createGameBoard();
091 createLights();
092 createWinningMessage();
093 }close braces end code blocks and must match an earlier open brace
094
095 /**handle input and game events*/
096 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance ()
097 {open braces start code blocks and must be matched with a close brace
098
099 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;
100 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;
101 /** I used William Anderson from last semester classclass is a group of fields and methods used for making objects as a reference forfor is a looping structure for repeatedly executing a block of code the player to game */
102 /**interaction, I used his code (Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse
103 /**().getClickLocation()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)
104 /**..
105 /**error*/
106 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
107 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)
108
109 {open braces start code blocks and must be matched with a close brace
110 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;
111 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;
112 //** used the play method of the model to get my lights to light up in a cross pattern*/
113 workingGame.play(row,col);
114 }close braces end code blocks and must match an earlier open brace
115 //** another for loop gives the boundaries of lights to light during play*/
116 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 side1;i<=this evaluates to true if the left side is not more than the right side6;i++this is the increment operator, which increases the variable by 1)
117 {open braces start code blocks and must be matched with a close brace
118 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 side1;j<=this evaluates to true if the left side is not more than the right side6;j++this is the increment operator, which increases the variable by 1)
119 {open braces start code blocks and must be matched with a close brace
120
121 lights[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(workingGame.isOn(i, j));
122 winner.setVisible(workingGame.won());
123
124
125
126 }close braces end code blocks and must match an earlier open brace
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
|