-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayerlist.js
56 lines (50 loc) · 1.36 KB
/
playerlist.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
function PlayerList() {
// Data structure
this.players = new Array();
// Add a player
this.addPlayer = function(obj) {
var isNew = true;
for (i in this.players) {
if (this.players[i].name == obj.name) {
isNew = false;
break;
}
}
if (isNew) {
this.players.push(obj);
}
}
// Get main player
this.getMainPlayer = function() {
return this.players[0];
}
// Get player by name
this.getPlayer = function(name) {
for (i in this.players) {
if (this.players[i].name == name) {
return this.players[i];
}
}
}
// Remove player
this.removePlayer = function(name) {
for (i in this.players) {
if (this.players[i].name == name) {
this.players = this.players.slice(0, i).concat(this.players.slice(parseInt(i)+1, this.players.length));
break;
}
}
}
// Update player
this.updatePlayer = function(player) {
for (i in this.players) {
if (this.players[i].name == player.name) {
for (j in player) {
this.players[i][j] = player[j];
}
break;
}
}
}
}
module.exports.PlayerList = PlayerList;