-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 1.45 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 1.45 KB
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 CardGame;
(function() {
var instance;
CardGame = function(){
if(instance){
return instance;
}
instance = this;
}
})();
CardGame.prototype.getCard = function() {
$.ajax({
url:'drawCard.php?do=getJsonCard',
complete: function(response) {
console.log(response.responseJSON);
var imageSrc = response.responseJSON.image_src;
$('#playersHand').append("<img src = '" + imageSrc + "' data = '" + imageSrc + "'>");
game.playerHit();
},
error: function() {
console.log("Did not get valid response");
}
});
}
CardGame.prototype.playerHit = function(){
$.ajax({
url:'drawCard.php?do=hit',
complete: function(response) {
console.log(response);
},
error: function(){
console.log("Did not get valid on hit");
}
});
}
CardGame.prototype._bindButtons = function(){
this.$hitButton.on('click', this.getCard);
}
CardGame.prototype._makeSelectors = function(){
this.$hitButton = $('#hit');
this.$dealerCardUp = $('#dealerCardUp');
this.$dealerCardDown = $('#dealerCardDown');
this.$playerCard1 = $('#playerCard1');
this.$playerCard2 = $('#playerCard2');
//this.$playersHand = $('#playersHand');
}
CardGame.prototype._init = function(){
this._makeSelectors();
this._bindButtons();
}
$(function(){
window.game = new CardGame();
window.game._init();
})