From ggc
|
01 packagepackage is used to name the directory or folder a class is in jam;
02
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
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 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
07
08 /**
09 * All about my game here.
10 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
11 */
12 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 HangmanGame extendsextends means to customize or extend the functionality of a class GameLoop
13 {open braces start code blocks and must be matched with a close brace
14 /**an oval*/
15 privateprivate is used to restrict access to the current class only Sprite oval;
16 privateprivate is used to restrict access to the current class only StringSprite phrase;
17 privateprivate is used to restrict access to the current class only StringSprite wrong;
18 privateprivate is used to restrict access to the current class only HangmanModel model;
19 /**sets up the game*/
20 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
21 {open braces start code blocks and must be matched with a close brace
22 RandomPhraseGenerator generator=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RandomPhraseGenerator("Hangman.txt");
23 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor HangmanModel(generator.getRandomPhrase());
24 makeSprites();
25 addSprites();
26 }close braces end code blocks and must match an earlier open brace
27
28 /**makes the sprites*/
29 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
30 {open braces start code blocks and must be matched with a close brace
31 phrase=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite(model.getRemaining());
32 phrase.setHeight(0.1);
33 ifif executes the next statement only if the condition in parenthesis evaluates to true(phrase.getWidth()>0.9)
34 phrase.setWidth(0.9);
35 phrase.bottomJustify();
36 phrase.setLocation(0.5, 0.95);
37
38 wrong=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Wrong guesses: 0");
39 wrong.setHeight(0.1);
40 ifif executes the next statement only if the condition in parenthesis evaluates to true(wrong.getWidth()>0.9)
41 wrong.setWidth(0.9);
42 wrong.topJustify();
43 wrong.setLocation(0.5, 0.05);
44
45 oval=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(2, 1);
46 oval.setScale(0.75);
47 oval.setLocation(0.5, 0.5);
48 }close braces end code blocks and must match an earlier open brace
49
50 /**adds the sprites to the screen*/
51 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
52 {open braces start code blocks and must be matched with a close brace
53 canvas.addSprite(oval, phrase, wrong);
54 }close braces end code blocks and must match an earlier open brace
55
56 /**handle input and game events*/
57 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)
58 {open braces start code blocks and must be matched with a close brace
59 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().keyPressed())
60 {open braces start code blocks and must be matched with a close brace
61 charchar is the type for a single letter or symbol and it is short for character letter=this assignment operator makes the left side equal to the right sidegetPlayer().getKeyboard().getLastKey();
62 model.guess(letter);
63 phrase.setText(model.getRemaining());
64 wrong.setText("Wrong guesses: "+adds two numbers together or concatenates Strings togethermodel.getNumberOfWrongGuesses());
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
|
Download/View jam/HangmanGame.java