|
01 packagepackage is used to name the directory or folder a class is in scg.ch01;
02
03 importimport means to make the classes and/or packages available in this program scg.ch01.spacesprites.Meteor;
04 importimport means to make the classes and/or packages available in this program scg.ch01.spacesprites.Ship;
05 importimport means to make the classes and/or packages available in this program fang2.core.Game;
06
07
08 /**
09 * A simple Asteroids-clone game. Construct one ship, set it up so it
10 * can shoot rocks. Set up one rock, moving randomly on the screen. Let
11 * the games begin.
12 */
13 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 CommentedMeteors
14 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
15 /**
16 * the name of the ship; commands are given to the ship as messages of
17 * the form ship.<command>(<stuff>). Different command names appear in
18 * place of <command> and the <stuff> can be nothing, one item, or a
19 * comma-separated list of items.
20 */
21 privateprivate is used to restrict access to the current class only Ship playersShip;
22
23 /**
24 * the name of the meteor. Commands can be given to rock, too, by
25 * placing the name, rock, to the left of a dot.
26 */
27 privateprivate is used to restrict access to the current class only Meteor rock;
28
29 /**
30 * setup is a command defined forfor is a looping structure for repeatedly executing a block of code Games. It is called, automatically,
31 * by FANG, once before the game begins. Here we build a newnew is used to create objects by calling the constructor ship and
32 * a newnew is used to create objects by calling the constructor rock, adding each one to the game. We dodo is part of the do-while looping structure (post condition loop) some customization
33 * on the ship, too.
34 */
35 @Override
36 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
37 playersShip =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Ship(thisthis means the current object (the implicit parameter));
38 /* where should the ship appear on the screen? upper-left corner is
39 * (0.0, 0.0), lower-right corner is (1.0, 1.0) so x-coordinates get
40 * bigger to the right, y-coordinates get bigger going downward.
41 */
42 playersShip.setLocation(0.5, 0.5);
43
44 /* tell the ship what kind of sprites its bullets can hit and what
45 * kinds of sprites can strike it (costing it a life). */
46 playersShip.setTarget(Meteor.classclass is a group of fields and methods used for making objects);
47 playersShip.addCollision(Meteor.classclass is a group of fields and methods used for making objects);
48
49 /* show the score and remaining life counter */
50 playersShip.showLives();
51 playersShip.showScore();
52
53 addSprite(playersShip);
54
55 /* create, position, and add the meteor */
56 rock =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Meteor(thisthis means the current object (the implicit parameter));
57 rock.setLocation(0.8, 0.8);
58 addSprite(rock);
59 }close braces end code blocks and must match an earlier open brace
60 }close braces end code blocks and must match an earlier open brace
61
62 //Uploaded on Mon Mar 29 21:42:10 EDT 2010
|