-
Notifications
You must be signed in to change notification settings - Fork 0
/
Team.js
90 lines (69 loc) · 2.06 KB
/
Team.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
/****TEAM OBJECT FILE
*
*
*/
var Player = require('./Player.js'); //Player object import
module.exports = function (name, code, head_coach, asst_coach, stadium, roster){
this.name = name;
this.code = code;
this.head_coach = head_coach;
this.asst_coach = asst_coach;
this.stadium = stadium;
this.active_roster = [];
if (roster != null) this.active_roster = roster;
this.get_name = function(){
return this.name;
}
this.get_code = function(){
return this.code;
}
this.get_head_coach = function(){
return this.head_coach;
}
this.get_asst_coach = function(){
return this.asst_coach;
}
this.get_stadium = function(){
return this.stadium;
}
this.edit_name = function(name) {
this.name = name;
}
this.edit_code = function(code){
this.code = code;
}
this.set_head_coach = function(head_coach){
this.head_coach = head_coach;
}
this.set_asst_coach = function(asst_coach){
this.asst_coach = asst_coach;
}
this.set_stadium = function(stadium){
this.stadium = stadium;
}
this.add_player_to_roster = function(player){
//var p = new Player(name, number, position);
if (player.get_name() == null || player.get_number() == null || player.get_position() == null)
throw "add_player_to_roster Error: object passed is not a player";
this.active_roster.push(player);
}
this.remove_player_from_roster = function(name, number){
if (name == null || number == null)
throw "remove_player_to_roster Error: objects passed are not valid";
for (var i = 0; i < this.active_roster.length; i++){
var p = this.active_roster[i];
if (p.get_name() == name && p.get_number() == number){
this.active_roster.splice(this.active_roster.indexOf(p),1);
//console.log("removed player: " + p.get_name());
return;
}
}
throw "remove_player_from_roster Error: player could not be found: (name: " + name + " number: " + number + ")\n";
}
this.get_active_roster = function(){
return this.active_roster;
}
this.to_array = function(){
return [this.name, this.code, this.head_coach, this.asst_coach, this.stadium, this.active_roster];
}
}