-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
123 lines (111 loc) · 3.38 KB
/
code.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
$(document).ready(function() {
Crafty.init(2000,2000, document.getElementById('game'));
var WIDTH = 80;
var HEIGHT = 90;
var INIT_TOP = 15;
var INIT_LEFT = 15;
OTHER_LEFT = WIDTH * 9.5;
var yourOpponentDeck = Crafty.e("Deck")
.putDeck([])
.size(WIDTH, HEIGHT)
.place(INIT_LEFT, INIT_TOP)
.deckSize(30);
var myEntity1 = Crafty.e("Button")
.attr({x: INIT_LEFT + 15, y: INIT_TOP + 5 + HEIGHT , w:50, h:25, z:1 })
.makeText('END TURN')
.color('pink')
.bind('MouseUp',function(e){ alert('big black box was touched', e); });
deck2 = []
for (var i=0; i<20; i++) {
deck2.push(Crafty.e("Card")
.image("images/test_monkey.jpg")
.size(WIDTH, HEIGHT)
.place(OTHER_LEFT + (WIDTH + 5) * i, HEIGHT*4.5)
.onHit("Deck", function(obj) {
var deck = Crafty(obj[0].obj[0]);
deck.hand.removeCard()
deck.addCard(this);
this.unplace()
.stopDrag();
}))
}
var yourDeck = Crafty.e("Deck")
.putDeck([])
.size(WIDTH, HEIGHT)
.place(80 + 8*WIDTH, 10 + 6*HEIGHT)
.deckSize(30);
for (var i = 0; i < 7; i++) {
for (var j = 0; j < 7; j++) {
// zookeeper layer trimming
if ((j == 0 || j == 6) && [1,2,4,5].includes(i)) {
continue;
}
// battlefield layer
else if ((j == 2 || j == 4) && (i >= 1 && i <= 5)) {
Crafty.e("CardSlot")
.size(WIDTH, HEIGHT)
.place(INIT_LEFT + 35 + WIDTH+i*WIDTH, INIT_TOP+j*HEIGHT)
.setInnerColor("red");
}
// farm layer
else if ((j == 1 || j == 5) && (i >= 1 && i <= 5)) {
Crafty.e("CardSlot")
.size(WIDTH, HEIGHT)
.place(INIT_LEFT + 35 + WIDTH+i*WIDTH, INIT_TOP+j*HEIGHT)
.setInnerColor("brown");
}
// bottom zookeeper
else if (j == 6 && i == 3) {
Crafty.e("CardSlot")
.size(WIDTH-1, HEIGHT)
.place(INIT_LEFT + 35 + WIDTH+i*WIDTH, INIT_TOP+j*HEIGHT+1);
}
else {
Crafty.e("CardSlot")
.size(WIDTH, HEIGHT)
.place(INIT_LEFT + 35 + WIDTH+i*WIDTH, INIT_TOP+j*HEIGHT);
}
}
}
// initialize decks
// on deck touch, draw a card
var textField = Crafty.e('2D, DOM, Text')
.attr({
x: WIDTH*11.5,
y: INIT_TOP,
w: 1000
})
.text("YOUR OPPONENT'S HAND")
.textFont({ size: '20px', weight: 'bold' });
var textField = Crafty.e('2D, DOM, Text')
.attr({
x: WIDTH*12.5,
y: HEIGHT*7-15,
w: 1000
})
.text("YOUR HAND")
.textFont({ size: '20px', weight: 'bold' });
var handPrototype = {
addCard: function(card) {
this.push(card);
card.place(OTHER_LEFT + (WIDTH + 5) * i, HEIGHT * 5.5)
},
removeCard: function(card) {
this.pop(card);
}
}
var yourHand = [];
yourHand.prototype = handPrototype;
yourDeck.putHand(yourHand);
for (var i = 0; i < 1; i++) {
// yourHand.push()
}
var yourOpponentHand = [];
for (var i = 0; i < 7; i++) {
yourOpponentHand.push(Crafty.e("BackCard")
.color("green")
.size(WIDTH, HEIGHT)
.place(OTHER_LEFT + (WIDTH + 5) * i, HEIGHT)
)
}
})