-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
161 lines (140 loc) · 4.28 KB
/
index.html
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/fivehundred.scss.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600|Ubuntu+Condensed" rel="stylesheet" type="text/css">
<style>
.card {
position: relative;
cursor: pointer;
}
#cards {
padding-top: 100px;
}
</style>
</head>
<body>
<h1>500 cards dealer</h1>
<div>
<label for="seed">The secret code for this round is:</label>
<input id="seed" />
<button onclick="newCode()">🎲 New Code</button>
</div>
<div>
<label for="player-option">I am the player:</label>
<select id="player-option">
<option></option>
<option value=0>Vince</option>
<option value=1>Bec</option>
<option value=2>Aaron</option>
<option value=3>Nathan</option>
</select>
<button onclick="dealHand()">🃋 Deal me the cards</button>
<button onclick="dealKitty()">😻 meow</button>
</div>
<ul id="cards">
</ul>
<script src="static/scripts.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.0/seedrandom.min.js">
</script>
<script>
var FiveHundredCard = {
values: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
suits: ['S', 'C', 'D', 'H'],
new: function(value, suit) {
return {
value: value,
suit: suit,
repr: function() {
if (this.suit === 'X') return 'X';
var display_value = this.value;
if (this.value === 11) display_value = 'J';
if (this.value === 12) display_value = 'Q';
if (this.value === 13) display_value = 'K';
if (this.value === 14) display_value = 'A';
return display_value + this.suit;
},
sorting_value: function() {
if (this.suit === 'X') {
return 1000;
} else {
return FiveHundredCard.suits.indexOf(this.suit) * 100 + this.value;
}
},
};
},
compare: function(card1, card2) {
return card1.sorting_value() - card2.sorting_value();
},
generate_deck: function() {
var cards = [];
this.suits.forEach((suit) => {
this.values.forEach((val) => {
cards.push(this.new(val, suit));
})
});
cards.push(this.new(4, 'D'));
cards.push(this.new(4, 'H'));
cards.push(this.new(0, 'X'));
return cards;
}
};
var hands = [];
var kitty = [];
function shuffle(array) {
var i = 0
, j = 0
, temp = null
for (i = array.length - 1; i > 0; i -= 1) {
j = Math.floor(Math.random() * (i + 1))
temp = array[i]
array[i] = array[j]
array[j] = temp
}
}
function dealHand() {
var seed = document.getElementById('seed').value;
var option = document.getElementById('player-option');
var player_id = option.options[option.selectedIndex].value;
if (!seed || !player_id) return;
document.getElementById('cards').innerHTML = '';
// reset the hands
hands = [];
cards = FiveHundredCard.generate_deck();
Math.seedrandom(seed);
shuffle(cards);
hands.push(cards.slice(0, 10));
hands.push(cards.slice(10, 20));
hands.push(cards.slice(20, 30));
hands.push(cards.slice(30, 40));
kitty = cards.slice(40, 43);
hands[player_id].sort(FiveHundredCard.compare);
hands[player_id].forEach((card) => {
var item = generateCard(card);
document.getElementById("cards").appendChild(item);
});
}
function dealKitty() {
if (!kitty.length) return;
kitty.forEach((card) => {
var item = generateCard(card);
document.getElementById("cards").appendChild(item);
});
kitty = []; // reset the kitty
}
function newCode() {
var random_code = Math.random().toString(36).slice(2);
window.location.search = 'code=' + random_code;
}
var current_seed = getParameterByName('code');
if (current_seed) {
document.getElementById('seed').value = current_seed;
} else {
newCode();
}
</script>
</body>
</html>