This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
105 lines (78 loc) · 2.23 KB
/
game.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
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: [Scene1]
};
let deck=[];
//will grab currency specified from local storage
let currency;
//Bet amount for player
let betAmount = 10;
//let betLabel = betAmount
//Current amount of money for player.
let cashAmount = 100;
//let cashLabel = cashAmount
//Have the cards been dealt?
let cardsDealt = false;
//Value of the cards that the dealer and user have + initialiazation.
var userCardValue = 0;
var dealerCardValue = 0;
//Create empty arrays for the hands of the user and the dealer.
let userHand = [];
let dealerHand = [];
//so we can access buttons at a file level
let stayButton;
let hitButton;
let dealButton;
let raiseBetButton;
let lowerBetButton;
//
let roundResultText;
//used for UI
let userCardSlots = [];
let dealerCardSlots = [];
var game = new Phaser.Game(config);
/**
* @author morganaj (morganaj@mail.uc.edu).
* @summary creates array of cards
*/
function freshDeck() {
//setup deck array
var suits = ["C", "D", "H", "S"];
var pips = ["2" ,"3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"];
for(x = 0; x < pips.length; x++){
for(i = 0; i < suits.length; i++){
deck.push(pips[x] + suits[i]);
}
}
}
/**
* @author morganaj (morganaj@mail.uc.edu).
* @summary randomizes order of cards in deck array
*/
function shuffleDeck(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function enterButtonHoverState(button){
button.setScale(.8);
}
function enterButtonRestState(button){
button.setScale(.6);
}
function draw(array) {
var selectedIndex = array.shift(); //Removed first element in array and selects it.
console.log("Drawn Card: " + selectedIndex); //Log the drawn card.
return selectedIndex;
}