-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmemory-gui.js
80 lines (62 loc) · 1.98 KB
/
memory-gui.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
/// Module 3
var MemoryGUI = (function () {
function GuiCtor(container,game) {
game.gui(this);
this.reset = function() {
var images = document.getElementsByTagName('img')
for (i=0; i<images.length; ++i) {
images[i].setAttribute('src', '../images/bgpic2.jpg');
}
game.reset();
}
// if all card slots are ' ' then render?
// 3 rending methods for the GUI instance, one for each of the 3 states
//
this.hideSoon = function(whereArr) {
window.setTimeout(function () {
$( '#' + whereArr[0] + ' img').attr('src', '../images/bgpic2.jpg')
$( '#' + whereArr[1] + ' img').attr('src', '../images/bgpic2.jpg')
}, 750);
}
//
this.show = function(where,displayString) {
document.getElementById(where).getElementsByTagName('img')[0].setAttribute('src', displayString);
}
//
this.removeSoon = function(whereArr) {
window.setTimeout(function () {
$( '#' + whereArr[0] + ' img').fadeOut(200)
$( '#' + whereArr[1] + ' img').fadeOut(200)
}, 500);
}
this.render = function() {
var tab = document.createElement('table');
var cellNum = 0;
for (var r=0, id=0; r<game.size()/6; ++r) {
var tr = document.createElement('tr');
tab.appendChild(tr); //
for (var c=0; c<6; ++c, ++id) {
var td = document.createElement('td');
var faceImg = document.createElement('img');
faceImg.setAttribute('src', '../images/bgpic2.jpg')
td.setAttribute('id', cellNum);
td.classList.add('facedown');
td.addEventListener("click", function() {
var id = this.getAttribute('id')
game.lift(parseInt(id))
console.log(this.id + ' selected');
});
td.appendChild(faceImg);
tr.appendChild(td);
cellNum++;
}
}
console.log('cards rendered');
var board = document.getElementById(container)
board.appendChild(tab);
document.getElementById("myBtn").addEventListener("click", this.reset);
}
this.render();
};
return GuiCtor;
})();