-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerInfo.js
63 lines (54 loc) · 1.83 KB
/
playerInfo.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
var _ = require('lodash');
var playerList = {
'dealer': {
balance: 10000,
cards:[]
}
};
module.exports.createPlayer = function createPlayer(playerName) {
if(playerList[playerName]){
console.log('A player by that name already exists, please'+
' choose another name!');
} else if(_.keys(playerList).length === 5){
console.log('The game is currently full');
} else {
var newPlayer = {
balance: 1000,
cards: []
};
playerList[playerName] = newPlayer;
console.log('New Player created! Welcome ' + playerName +
', your balance is ' + newPlayer.balance);
}
};
module.exports.getPlayer = function getPlayer(playerName) {
console.log(playerList[playerName]);
return playerList[playerName];
};
module.exports.getPlayerList = function getPlayerList() {
return playerList;
};
module.exports.deletePlayer = function deletePlayer(playerName) {
delete playerList[playerName];
console.log(playerName + ' has been removed from the game');
return playerList;
};
module.exports.updatePlayerBalance = function updatePlayerBalance(playerName, value) {
playerList[playerName].balance += value;
console.log(playerName + "'s new balance is " + playerList[playerName].balance);
return playerList[playerName];
};
module.exports.getPlayerCards = function getPlayerCards(playerName) {
console.log(playerList[playerName].cards);
return playerList[playerName].cards;
};
module.exports.updatePlayerCards = function updatePlayerCards(playerName, card) {
playerList[playerName].cards.push(card);
var cardsLength = playerList[playerName].cards.length - 1;
console.log(playerName + ' drew ' + playerList[playerName].cards[cardsLength].card +
' of ' + playerList[playerName].cards[cardsLength].suit);
console.log(playerList[playerName]);
};
module.exports.resetPlayerCards = function resetPlayerCards(playerName) {
playerList[playerName].cards = [];
};