-
Notifications
You must be signed in to change notification settings - Fork 1
/
Users.js
69 lines (57 loc) · 1.25 KB
/
Users.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
class Users {
constructor() {
this.users = [];
this.room = [];
}
addUsers(id, name, room) {
var user = { id, name, room, score: 0 };
this.users.push(user);
return user;
}
removeUser(id) {
var user = this.getUser(id);
if (user) {
this.users = this.users.filter(user => user.id !== id);
}
return user;
}
getUser(id) {
return this.users.filter(user => user.id === id)[0];
}
getUserList(room) {
var users = this.users.filter(user => user.room === room);
var namesArray = users.map(user => user);
return namesArray;
}
addRoom(room) {
if (this.room.indexOf(room) === -1) {
this.room.push(room);
}
}
getListRoom() {
return this.room;
}
removeRoom(room) {
this.room.splice(this.room.indexOf(room), 1);
return room;
}
setScore(id, score) {
for (let i = 0; i < this.users.length; i++) {
if (this.users[i].id === id) {
this.users[i].score = score;
}
}
}
winner() {
let winners = [];
for (let i = 0; i < this.users.length; i++) {
if (this.users[i].id === id) {
if (this.users[i].score > 5) {
winners.push(this.users[i]);
}
}
}
return winners;
}
}
module.exports = { Users };