This repository was archived by the owner on Jul 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht3_components.js
68 lines (62 loc) · 1.95 KB
/
t3_components.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
var component = {
Game: function(ID, Player1, Player2, Turn, Squares, NextSquare, Winner) {
this.id = ID;
this.player1 = Player1;
this.player2 = Player2;
this.turn = Turn;
this.squares = Squares != undefined ? Squares : [];
this.nextSquare = NextSquare;
this.winner = Winner;
this.isOnline = true;
},
/**
* Bind member functions for Game
*/
BindGameFunctions: function() {
/**
* Determine and retrieve the current player based on the turn.
*/
component.Game.prototype.getCurrentPlayer = function() {
return this.turn % 2 == 0 ? this.player1 : this.player2;
};
/**
* Determine and retrieve the player which is not the current user.
*/
component.Game.prototype.getNonuserPlayer = function() {
if(this.player1.id == t3.User.id) {
return this.player2;
}
return this.player1;
};
/**
* Determine and retrieve the current player based on a given ID
*
* @param {int} id The numeric identifier for the desired player.
*/
component.Game.prototype.getPlayerByID = function(id) {
if(this.player1.id == id) {
return this.player1;
}
return this.player2;
}
},
Account: function(ID, Username, Logo) {
this.id = ID;
this.username = Username;
this.logo = Logo;
},
Square: function(ID, GameID, LocalOrder, Owner, Cells) {
this.id = ID;
this.gameID = GameID;
this.order = LocalOrder;
this.owner = Owner;
this.cells = Cells != undefined ? Cells : []
},
Cell: function(ID, SquareID, GameID, LocalOrder, Owner) {
this.id = ID;
this.squareID = SquareID;
this.gameID = GameID;
this.order = LocalOrder;
this.owner = Owner;
},
}