-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagency.html
More file actions
189 lines (174 loc) · 8.89 KB
/
agency.html
File metadata and controls
189 lines (174 loc) · 8.89 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<style>
body {height: auto; width: 100vw; max-width: 1080px; margin: 0 auto;}
</style>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body
style="background-image: url('imgs/board.jpg'); background-repeat: no-repeat; background-attachment: fixed; background-size: 100% 100%;">
<div style="scroll-margin-top: 0;">
<center>
<img src="imgs/hi.gif" alt="" width="350" height="100">
<img src="imgs/hi.gif" alt="" width="350" height="100">
<img src="imgs/hi.gif" alt="" width="350" height="100">
</center>
</div>
<div style="margin-top: 5%; color: azure;">
<button id="pickCard" onclick="addscore()">Hit!</button>
<button id="getResult" onclick="getResult()">Stand</button>
<button id = "gameover" onclick="gameover(true)">Continue</button>
<button id = "gameover" onclick="gameover(false)">Game End</button>
</div>
<div id="dealerCard">
</div>
<div id="card">
</div>
<script>
let playermoney = 10000;
let detector = true;
let dealerscore = 0;
let playerscore = 0;
let dealerCard = [];
let filelist = [
{"filename" : "2C.png", "score":"2"}, {"filename" : "3C.png", "score":"3"}, {"filename" : "4C.png", "score":"4"}, {"filename" : "5C.png", "score":"5"}, {"filename" : "6C.png", "score":"6"},
{"filename" : "7C.png", "score":"7"}, {"filename" : "8C.png", "score":"8"}, {"filename" : "9C.png", "score":"9"}, {"filename" : "10C.png", "score":"10"}, {"filename" : "AC.png", "score":"1"},
{"filename" : "KC.png", "score":"10"}, {"filename" : "QC.png", "score":"10"}, {"filename" : "JC.png", "score":"10"},
{"filename" : "2D.png", "score":"2"}, {"filename" : "3D.png", "score":"3"}, {"filename" : "4D.png", "score":"4"}, {"filename" : "5D.png", "score":"5"}, {"filename" : "6D.png", "score":"6"},
{"filename" : "7D.png", "score":"7"}, {"filename" : "8D.png", "score":"8"}, {"filename" : "9D.png", "score":"9"}, {"filename" : "10D.png", "score":"10"}, {"filename" : "AD.png", "score":"1"},
{"filename" : "KD.png", "score":"10"}, {"filename" : "QD.png", "score":"10"}, {"filename" : "JD.png", "score":"10"},
{"filename" : "2H.png", "score":"2"}, {"filename" : "3H.png", "score":"3"}, {"filename" : "4H.png", "score":"4"}, {"filename" : "5H.png", "score":"5"}, {"filename" : "6H.png", "score":"6"},
{"filename" : "7H.png", "score":"7"}, {"filename" : "8H.png", "score":"8"}, {"filename" : "9H.png", "score":"9"}, {"filename" : "10H.png", "score":"10"}, {"filename" : "AH.png", "score":"1"},
{"filename" : "KH.png", "score":"10"}, {"filename" : "QH.png", "score":"10"}, {"filename" : "JH.png", "score":"10"},
{"filename" : "2S.png", "score":"2"}, {"filename" : "3S.png", "score":"3"}, {"filename" : "4S.png", "score":"4"}, {"filename" : "5S.png", "score":"5"}, {"filename" : "6S.png", "score":"6"},
{"filename" : "7S.png", "score":"7"}, {"filename" : "8S.png", "score":"8"}, {"filename" : "9S.png", "score":"9"}, {"filename" : "10S.png", "score":"10"}, {"filename" : "AS.png", "score":"1"},
{"filename" : "KS.png", "score":"10"}, {"filename" : "QS.png", "score":"10"}, {"filename" : "JS.png", "score":"10"}
];
//-----------------------------------------카드 뽑기-----------------------------------------
let tempCardList = filelist.map((v)=>{return v;});
function refillChecker(){
if (tempCardList.length < 1) {
tempCardList = filelist.map((v)=>{return v;});
}
}
function dealerPickCard() {
refillChecker();
let dealerCardIndex = parseInt(Math.random()*tempCardList.length);
let dealerCardName = tempCardList[dealerCardIndex];
dealerCard.push(tempCardList[dealerCardIndex]);
tempCardList.splice(dealerCardIndex, 1);
// console.log("dealer : ", dealerCardName.filename);
document.getElementById("dealerCard").innerHTML += '<img src=52_cards/'+ "red_back.png" +' alt="" style="float: right; width: 10%">';
return dealerCardName.score
}
function playerPickCard() {
refillChecker();
let cardIndex = parseInt(Math.random()*tempCardList.length);
let cardName = tempCardList[cardIndex];
tempCardList.splice(cardIndex, 1);
// console.log("player : ", cardName.filename);
document.getElementById("card").innerHTML += '<img src=52_cards/'+ cardName.filename +' alt="" style="float: left; width: 10%">';
return cardName.score
}
function pickCard(){
if (detector){
return {"userScore" : playerPickCard(), "dealerScore" : dealerPickCard()};
}
}
//-----------------------------------------게임 오버-----------------------------------------
//document.getElementById("gameover").addEventListener("click",gameover);
function gameover(bool){
if(!detector){
document.getElementById("card").innerHTML = "";
document.getElementById("dealerCard").innerHTML = "";
document.getElementById("result").innerHTML = "<div> </div>";
if(!bool){
playermoney = 10000;
tempCardList = filelist.map((v)=>{return v;});
}
dealerCard = [];
playerscore = 0;
dealerscore = 0;
detector = true;
}
}
//-----------------------------------------score 합치기-----------------------------------------
function addscore(){
let oneTime = pickCard();
dealerscore += parseInt(oneTime.dealerScore);
playerscore += parseInt(oneTime.userScore);
let bust = bustedDetector();
if(bust!=undefined){
getResult();
//document.getElementById("result").innerText += bust;
}
}
//-----------------------------------------어느 한쪽이라도 버스티드면 이리로 보냄-----------------------------------------
function bustedDetector(){
if(dealerscore > 21 && playerscore > 21){
detector = false;
return "유저 패배! 둘다 파산";
} else if (dealerscore > 21 && playerscore <= 21) {
detector = false;
return "유저 승리! 딜러 파산";
} else if (dealerscore <= 21 && playerscore > 21) {
detector = false;
return "딜러 승리! 유저 파산";
}
}
function win(){
playermoney += 100;
console.log("money : ", playermoney);
}
function lose(){
playermoney -= 100;
console.log("money : ", playermoney);
}
//-----------------------------------------딜러가 17이 안될경우 계속 가야하는 로직-----------------------------------------
function additionalDealer(){
while (dealerscore < 17){
dealerscore += parseInt(dealerPickCard());
}
}
let winner = "";
//-----------------------------------------결과 계산-----------------------------------------
function getResult(){
additionalDealer();
document.getElementById("result").innerHTML = " 딜러 : " + dealerscore;
document.getElementById("result").innerHTML += " 플레이어 : " + playerscore +"<br>";
let bust = bustedDetector();
if(bust!=undefined && !detector){
winner = bust;
}
if (detector) {
if (dealerscore> playerscore) {
winner = " 딜러 승리 ";
} else if (playerscore> dealerscore){
winner = " 유저 승리 ";
} else {
winner = " 무승부 ";
}
detector = false;
}
document.getElementById("result").innerText += winner;
document.getElementById("dealerCard").innerHTML = '';
for(let dealercard of dealerCard){
document.getElementById("dealerCard").innerHTML += '<img src=52_cards/'+ dealercard.filename +' alt="" style="float: right; width: 10%">';
}
}
</script>
<div id="result" style="margin-top: 50%; color: azure;">  
</div>
<div style="margin-top: 10%;">
<center>
<img src="imgs/175.gif" alt="">
<img src="imgs/175.gif" alt="">
<img src="imgs/175.gif" alt="">
</center>
</div>
</body>
</html>
<!-- 3. 종합점수 계산(승수 쌓인거라던지) -->