-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhumanConsole.js
60 lines (51 loc) · 1.33 KB
/
humanConsole.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
/**
* Renders all options and lets user to select one option
**/
var humanConsoleFactory = {
create: function()
{
return {
getTitle:function()
{
return 'You'
},
render:function($elem)
{
this.$elem = $elem
gameLogic.getAllOptions().forEach(function(option) {
$elem.innerHTML += '<button class="option" id="' + option + '">' + option + '</button>'
})
var $optionNodeList = document.getElementsByClassName('option')
for ( var i = 0; i < $optionNodeList.length; ++i ) {
$optionNodeList[i].onclick = this.getOptionClickHandler()
}
},
getOptionClickHandler : function()
{
var thisConsole = this;
return function() {
thisConsole.humanOption = this.id
thisConsole.playerOptionListener( thisConsole.getOption(), thisConsole.getEndOfGameFunction() )
}
},
getEndOfGameFunction:function()
{
var thisConsole = this
return function() {
thisConsole.$elem.innerText = thisConsole.humanOption
thisConsole.$elem.textContent = thisConsole.humanOption
}
},
getOption:function()
{
return this.humanOption
},
setPlayerOptionListener:function(playerOptionListener)
{
this.playerOptionListener = playerOptionListener
}
}
}
}
if (typeof module != 'undefined')
module.exports = humanConsoleFactory