File size: 2,784 Bytes
c02f046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
 * App
 * @description
 * CodePirate is a Programming learning Game for Geeks
 */
var App = function(options) {
  var $this = this;
  var _private = {};

  // CodePirate System Variables
  this.options = $.extend({
    game: {},
    states: []
  }, options);

  /**
   * Constructor
   */
  this.init = function() {
    // Create New Game
    _private.createGame();

    // Register States
    _private.registerState('MainMenuState', new MainMenuState($this.options.game, $this));
    _private.registerState('ConfigShipState', new ConfigShipState($this.options.game, $this));
    _private.registerState('MissionSelectState', new MissionSelectState($this.options.game, $this));
    _private.registerState('SinglePlayerState', new SinglePlayerState($this.options.game, $this));
    _private.registerState('MultiPlayerState', new MultiPlayerState($this.options.game, $this));
    _private.registerState('MultiPlayerCreateState', new MultiPlayerCreateState($this.options.game, $this));
    _private.registerState('PlayGameState', new PlayGameState($this.options.game, $this));

    // Run Game
    _private.createStates();
    $this.options.game.states.switchState("MainMenuState");
  };

  /**
   * registerState
   * @description
   * This Method is registering new Kiwi GameEngine States.
   * This are the States wich the CreateGame Method uses to initalize the Game.
   *
   * @param strStateKey   This is the Unique State Key wich is used to get a specific State
   * @param objState      This is the Kiwi State Object
   * @return void
   */
  _private.registerState = function(strStateKey, objState) {
    $this.options.states[strStateKey] = objState;
  }

  /**
   * createGame
   * @description
   * This is the Main Game Object Creation Method. It is creating a new Kiwi
   * GameEngine Object.
   *
   * @param void
   * @return void
   */
  _private.createGame = function() {
    // Create Game
    var objOptions = {
    	renderer: Kiwi.RENDERER_WEBGL,
    	width: 1024,
    	height: 640
    }
    var objGame = new Kiwi.Game('CodePirate', 'CodePirate', null, objOptions);

    // Set Main Game Object
    $this.options.game = objGame;
  };

  /**
   * createStates
   * @description
   * This is adding the GameStates to the Game Object
   *
   * @param void
   * @return void
   */
  _private.createStates = function() {
    for(var strKey in $this.options.states) {
        var objState = $this.options.states[strKey];
        $this.options.game.states.addState(objState.getState());
    }
  };

  /**
   * getState
   * @description
   * This is returning a speciffic State Controller
   *
   * @param void
   * @return void
   */
  this.getState = function(strStateKey) {
    return $this.options.states[strStateKey];
  };

  // Constructor Call
  $this.init();
};