arcade/SampleLevel

From ggc

Jump to: navigation, search
Compiled in 0.091 seconds.

01 package arcade;
02 import fang.*;
03 
04 /**
05  * This is a simple example game that extends
06  * ArcadeLevel.  It simply displays the name
07  * of the game and asks the user to press a
08  * key to finish the game.
09  @author Jam Jenkins
10  *
11  */
12 public class SampleLevel
13          extends ArcadeLevel
14 {
15    /**the name of the game*/
16    private String name;
17 
18    /**
19     * makes the game
20     @param name the name of the game to be
21     * displayed in the arcade
22     */
23    public SampleLevel(String name)
24    {
25       this.name=name;
26    }
27 
28    @Override
29    /**
30     * makes the level finish when 'd' is pressed
31     */
32    public void advanceFrame(double timePassed)
33    {
34       if(getPlayer().getKeyboard().getLastKey()=='d')
35          finishLevel();
36    }
37 
38    @Override
39    /**
40     * displays the name of the game and instructions
41     * for finishing the game
42     */
43    public void startLevel()
44    {
45       StringSprite gameName=new StringSprite(name);
46       gameName.setWidth(0.8);
47       gameName.topJustify();
48       gameName.setLocation(0.50.1);
49       canvas.addSprite(gameName);
50 
51       StringSprite instructions=new StringSprite(
52                                     "Press d\nto continue.");
53       instructions.setWidth(0.8);
54       instructions.bottomJustify();
55       instructions.setLocation(0.50.9);
56       canvas.addSprite(instructions);
57    }
58 
59    /**
60     * this method is overridden to make it
61     * display properly in the arcade
62     */
63    public String toString()
64    {
65       return name;
66    }
67 
68 }
69 


Download/View arcade/SampleLevel.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter