-
Notifications
You must be signed in to change notification settings - Fork 1
/
constructors.js
71 lines (42 loc) · 1.44 KB
/
constructors.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
function Character(player, isHuman, name) {
this.player = player;
this.isHuman = isHuman;
this.name = name;
this.abilities = {
rock: 1,
paper: 1,
scissors: 1
};
}
Character.prototype.renderPlayer = function(){
var $controlsContainer = $('<div class="player-controls">');
$('.' + this.player).append('<p class="player-name">' + this.name + ' <span class="mood-emoji"></span></p>')
.append($controlsContainer);
if(this.isHuman){
for(var ability in this.abilities) {
var $button = $('<button>');
$button.html(ability);
$button.addClass('btn');
$button.addClass('btn-' + ability);
$controlsContainer.append($button);
$button.on('click', function(event){ play(event.target.innerHTML); });
}
} else {
$controlsContainer.append('<p class="cpu-player">💻</p>');
}
};
Character.prototype.disableControls = function(state) {
if(this.isHuman) {
for(var key in this.abilities) {
var $currentButton = $('.' + this.player + ' .btn-' + key);
$currentButton.prop( "disabled", state );
}
}
};
Character.prototype.react = function(mood) {
var $playerContainer = $('.' + this.player);
$playerContainer.removeClass('mood-neutral mood-round-won mood-round-lost mood-round-tied mood-match-won mood-match-won mood-match-lost')
.addClass(mood);
console.log('react!', $playerContainer, $playerContainer.attr('class'));
};
//