-
Notifications
You must be signed in to change notification settings - Fork 147
/
script.js
88 lines (71 loc) · 1.94 KB
/
script.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
$(document).ready(function() {
//what does this do?
var convert_value_to_string = function(value) {
if (value > 10) {
switch (value) {
case 11:
return 'Jack';
break;
case 12:
return 'Queen';
break;
case 13:
return 'King';
break;
}
}
return value.toString();
}
//what does this do?
var deck = [];
var suits = ['hearts', 'diamonds', 'spades', 'clubs'];
for (var i = 0; i<suits.length; i++) {
var suit = suits[i];
for (var j = 0; j<13; j++) {
deck.push({number: j+1, suit: suit});
}
}
//what does this do?
var shuffle = function(array) {
var copy = [];
var n = array.length;
var i;
while (n) { i = Math.floor(Math.random() * array.length);
if (i in array) {
copy.push(array[i]);
delete array[i];
n--;
}
}
return copy;
}
//Now call the shuffle function and save the result of what shuffle returns into your deck variable
var cards_player_1 = [];
var cards_player_2 = [];
// write a function called deal that will evently divide the deck up between the two players
//create a function (algorithm) called "war" that takes two cards as parameters, compares them and returns a winner. A tie should return false.
var war = function(){
}
var advance = function(){
//take the top two cards and display them
if (cards_player_1.length) {
var card_1 = cards_player_1[0];
var card_2 = cards_player_2[0];
$("#opp-card").html(convert_value_to_string(card_1.number)+" "+card_1.suit);
$("#opp-card-count").html(cards_player_1.length);
$("#my-card").html(convert_value_to_string(card_2.number)+" "+card_2.suit);
$("#my-card-count").html(cards_player_2.length);
}
}
//create a play function
//compare the cards
//give the winner both cards (at end of deck)
var play = function(){
//this function (defined below) will continue to the next turn
advance();
}
advance();
$(".btn").click(function() {
play();
});
});