From ggc
|
001 packagepackage is used to name the directory or folder a class is in Moriah;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * All about my game.
009 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
010 */
011 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 deal extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer numClicks;
014 privateprivate is used to restrict access to the current class only RectangleSprite door;
015 privateprivate is used to restrict access to the current class only RectangleSprite door2;
016 privateprivate is used to restrict access to the current class only RectangleSprite door3;
017 privateprivate is used to restrict access to the current class only StringSprite one;
018 privateprivate is used to restrict access to the current class only StringSprite two;
019 privateprivate is used to restrict access to the current class only StringSprite three;
020 privateprivate is used to restrict access to the current class only ImageSprite gold;
021 privateprivate is used to restrict access to the current class only ImageSprite duck;
022 privateprivate is used to restrict access to the current class only ImageSprite lose;
023 privateprivate is used to restrict access to the current class only StringSprite ulose;
024
025 /**sets up the game*/
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
027 {open braces start code blocks and must be matched with a close brace
028
029
030 StringSprite pick=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Pick a Door");
031 pick.setSize(.3);
032 pick.setLocation(.5,.1);
033 pick.setColor(Palette.getColor("Hot Pink"));
034 addSprite(pick);
035
036
037
038 gold=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Gold.jpg");
039 gold.setSize (.1);
040 gold.setLocation(.2,.5);
041 addSprite(gold);
042
043 door=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(5,7);
044 door.setSize(.25);
045 door.setLocation(.2,.5);
046 door.setColor(Palette.getColor("Lime Green"));
047 addSprite(door);
048
049 one=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("1");
050 one.setSize(.1);
051 one.setLocation(.2,.5);
052 addSprite(one);
053
054
055
056 duck=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Duck.jpg");
057 duck.setSize (.15);
058 duck.setLocation(.5,.5);
059 addSprite(duck);
060
061 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(5,7);
062 door2.setSize(.25);
063 door2.setLocation(.5,.5);
064 door2.setColor(Palette.getColor("Lime Green"));
065 addSprite(door2);
066
067 two=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("2");
068 two.setSize(.1);
069 two.setLocation(.5,.5);
070 addSprite(two);
071
072
073
074 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Lose.jpg");
075 lose.setSize(.15);
076 lose.setLocation(.8,.5);
077 addSprite(lose);
078
079 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(5,7);
080 door3.setSize(.25);
081 door3.setLocation(.8,.5);
082 door3.setColor(Palette.getColor("Lime Green"));
083 addSprite(door3);
084
085 three=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("3");
086 three.setSize(.1);
087 three.setLocation(.8,.5);
088 addSprite(three);
089
090 ulose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Lose!");
091 ulose.setSize(.5);
092 ulose.setLocation(.5,.8);
093 ulose.setColor(Palette.getColor("Purple"));
094 addSprite(ulose);
095
096
097
098 }close braces end code blocks and must match an earlier open brace
099
100 /**handle input and game events*/
101 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
102 {open braces start code blocks and must be matched with a close brace
103 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
104 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)
105
106 {open braces start code blocks and must be matched with a close brace
107 ifif executes the next statement only if the condition in parenthesis evaluates to true ( door.intersects(click))
108 {open braces start code blocks and must be matched with a close brace
109
110 canvas.removeSprite(door3);
111 canvas.removeSprite(three);
112 addSprite(door2);
113 addSprite(two);
114 addSprite(ulose);
115
116
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 (door2.intersects(click))
119 {open braces start code blocks and must be matched with a close brace
120 canvas.removeSprite(ulose);
121 canvas.removeSprite(door);
122 canvas.removeSprite(one);
123 addSprite(door3);
124 addSprite(three);
125
126 }close braces end code blocks and must match an earlier open brace
127 ifif executes the next statement only if the condition in parenthesis evaluates to true (door3.intersects(click))
128 {open braces start code blocks and must be matched with a close brace
129 canvas.removeSprite(ulose);
130 canvas.removeSprite(door2);
131 canvas.removeSprite(two);
132 addSprite(door);
133 addSprite(one);
134
135
136 }close braces end code blocks and must match an earlier open brace
137
138 }close braces end code blocks and must match an earlier open brace
139
140 }close braces end code blocks and must match an earlier open brace
141 }close braces end code blocks and must match an earlier open brace
|
Download/View Moriah/deal.java