forked from mdashx/pangea-poker-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboardcards.js
92 lines (84 loc) · 2.71 KB
/
boardcards.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
81
82
83
84
85
86
87
88
89
90
91
92
/*global thiscard */
var $ = window.$
var console = window.console
var pangea = window.pangea
var WebSocket = window.WebSocket
// I should definitely use inheritance to create the board card
// and player card object prototypes, but since there's only these
// two types of cards, I'm just duplicating some code for simplicity.
// If there was a need for a third card, I'd have a base Card prototype
// to inherit from.
pangea.BoardCard = function(selector){
this.card = null
this.image = null
this.selector = selector
this.dealimg = pangea.constants.facedown
this.origin = [110, 365] // top, left
}
pangea.BoardCard.prototype.getCard = function(){
if (pangea.cards.indexOf(this.card) > -1){
this.image = pangea.deck[this.card]
return true
} else {this.image = null; return false}
}
pangea.BoardCard.prototype.show = function(){
this.getCard()
if (this.image != null){
var cardElement = $('<img>')
cardElement.attr('src', this.image)
$(this.selector).append(cardElement)
}
}
pangea.BoardCard.prototype.clearCard = function(){
$(this.selector).empty()
this.card = null
this.image = null
}
pangea.BoardCard.prototype.showing = function(){
if ($(this.selector).has('img').length > 0){
return true
}
return false
}
pangea.BoardCard.prototype.deal = function(){
if (this.showing() == false && this.getCard()){
var dealspeed = 250
var dealElement = $('<img>')
dealElement.attr('src', this.dealimg)
var left = (pangea.constants.root.width()/2) - pangea.constants.dealwidth/2
dealElement.css({'position':'absolute', 'top':this.origin[0],
'left':left, 'width':pangea.constants.dealwidth})
pangea.constants.root.append(dealElement)
var thiscard = this
dealElement.animate(
{'left':$(this.selector).css('left'), 'top':$(this.selector).css('top'),
'width':$(this.selector).width()}, dealspeed, "linear",
function(){
dealElement.remove()
thiscard.show()
}
)
}
}
pangea.BoardCard.prototype.returnCard = function(){
if (this.showing()){
var dealspeed = 250
var dealElement = $('<img>')
dealElement.attr('src', this.dealimg)
var left = (pangea.constants.root.width()/2) - pangea.constants.dealwidth/2
this.clearCard()
dealElement.css({'position':'absolute',
'top':$(this.selector).css('top'),
'left':$(this.selector).css('left'),
'width':$(this.selector).width()})
pangea.constants.root.append(dealElement)
var thiscard = this
dealElement.animate(
{'left':left, 'top':thiscard.origin[0],
'width':pangea.constants.dealwidth}, dealspeed, "linear",
function(){
dealElement.remove()
}
)
}
}