-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocumentation.js
134 lines (115 loc) · 3 KB
/
documentation.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* ========================================
* This is a short paragraph on how to implement "Achtung die Kurve" on your own pace.
* ========================================
*
*
* Creates a new game.
*
* Parameter: canvasID : string
* canvasWidth : int
* canvasHeight : int
* useFullscreen : boolean
*/
var game = new Game("myCanvas", 500, 700, false);
/*
* Create a new Player.
*
* Parameter: name : string
*
* Returns: Player id (int)
*/
var myPlayerID = game.addPlayer("Mathias");
/*
* Removes a Player from the current game. The player will be left out, when the next round starts.
*
* Parameter: playerID : int
*/
game.removePlayer(myPlayerID);
/*
* Sets a callback to be triggered everytime a player dies.
*
* Parameter: callback : function
*/
game.setCollisionCallback(function (playerID) {
console.log ("Player with ID %i just died.", playerID);
});
/*
* Starts the game. With this action it immediatly starts drawing the lines.
*/
game.start();
/*
* Restarts the game at any point. This method doesn't drop the score that has been
* set till now.
*/
game.restart();
/*
* Stops the game. Only stops drawing. Doesn't reset scores.
*/
game.stop();
/*
* ========================================
* There is a easy way to keep track of all the scores over several rounds without
* managing ever hit over the collision callback
* ========================================
*/
/*
* Starts a mechanism that tracks the score of each player over multiple games
* until you force the mechanism to stop.
*/
game.startSession();
/*
* Stops the counting of scores for each player. Doesn't reset scores.
*/
game.stopSession();
/*
* Sets a callback after every round containing a few stats. Including the winner
* of the current game and the ranking of the current game.
*/
game.setRoundCallback(function(stats) {
console.log("the winnerID is %i ", stats.winnerID);
// prints an array including the IDs of the player
console.log("Ranks: %o", stats.rank);
});
/*
* ========================================
* There are a few accessors for info on each player. Playerinfo is always accessed over the
* playerID. All players are managed and controlled over the PlayerManager.
* ========================================
*/
/*
* Sets a callback after every round containing a few stats. Including the winner
* of the current game and the ranking of the current game.
*/
/*
* Returns the hex color of a player.
*
* Parameter: playerID : int
*
* Returns: color (string)
*/
game.playerManager.getPlayerColor(myPlayerID);
/*
* Returns the Distance the player has moved since the session started.
*
* Parameter: playerID : int
*
* Returns: distance (int)
*/
game.playerManager.getPlayerDistance(myPlayerID);
/*
* Returns the name of the player.
*
* Parameter: playerID : int
*
* Returns: name (string)
*/
game.playerManager.getPlayerName(myPlayerID);
/*
* Returns the number of the wins during the current session.
*
* Parameter: playerID : int
*
* Returns: wins (int)
*/
game.playerManager.getPlayerWins(myPlayerID);