-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslotMachineJS.html
131 lines (124 loc) · 3.23 KB
/
slotMachineJS.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<style>
.slotMachineWrapper{
width: 100%;
border: 1px solid black;
margin: auto;
}
.slotTop, .slotBottom{
margin: 10px auto;
display: block;
}
.pattern{
display: inline-block;
border: 1px solid black;
width:20%;
height: 300px;
font-size: 5em;
}
.slotBarWrapper{
width:10%;
height: 300px;
display: inline-block;
cursor: pointer;
}
.slotBall{
width: 50px;
height: 50px;
margin-right: 50px;
border-radius: 50%;
background-color: red;
}
.slotBar{
width: 20px;
height: 100px;
margin-top: -3px;
margin-left: 15px;
background-color: #d0d0d0;
}
</style>
<script>
window.onload = function(){
document.getElementById("slotBarWrapper").addEventListener("click", SlotMachine.runSlot);
}
var SlotMachine = (function(){
var runSlot = function(){
var userMoney = document.getElementById("userMoney").value;
var betMoney = document.getElementById("betMoney").value;
var patterns = ['apple', 'lemon', 'orange', 'bananas', 'peach', 'grapes', 'seven'];
var pattern1, pattern2, patter3;
if(betMoney == 0) {
alert("베팅 금액을 입력해주세요.");
return;
}
console.log(userMoney, betMoney);
// if(userMoney < betMoney){
// alert("돈 없으면 꺼져.");
// return;
// }
userMoney -= betMoney;
document.getElementById("userMoney").value = userMoney;
var num1 = Math.round(Math.random() * 10) % 7;
var num2 = Math.round(Math.random() * 10) % 7;
var num3 = Math.round(Math.random() * 10) % 7;
pattern1 = "./" + patterns[num1] + ".svg";
pattern2 = "./" + patterns[num2] + ".svg";
pattern3 = "./" + patterns[num3] + ".svg";
document.getElementById("pattern1Img").setAttribute("src", pattern1);
document.getElementById("pattern2Img").setAttribute("src", pattern2);
document.getElementById("pattern3Img").setAttribute("src", pattern3) ;
if(pattern1 === pattern2 && pattern1 === pattern3){
alert("jackpot!!!!");
}
if(userMoney < 0){
alert("당신은 파산하였습니다.");
return;
}
}
var getPrize = function(betMoney){
}
return {
runSlot: runSlot
}
})();
</script>
</head>
<body>
<div class="slotMachineWrapper">
<div class="slotTop">
<div class="userMoneyWrapper">
<span id="userMoneyTitle">You got $</span>
<input id="userMoney" type="number" value="1000" readonly/>
</div>
</div>
<div class="slotMain">
<div id="pattern1" class="pattern">
<img id="pattern1Img" src="">
</div>
<div id="pattern2" class="pattern">
<img id="pattern2Img" src="">
</div>
<div id="pattern3" class="pattern">
<img id="pattern3Img" src="">
</div>
<div id="slotBarWrapper" class="slotBarWrapper">
<div id="slotBall" class="slotBall"></div>
<div id="slotBar" class="slotBar"></div>
</div>
</div>
<div class="slotBottom">
<div class="prizeWrapper">
<span id="prizeTitle">You win: $</span>
<span id="prizeContent">0</span>
</div>
<div class="betMoneyWrapper">
<span id="betMoneyTitle">Put $</span>
<input id="betMoney" type="number" value="0"/>
</div>
</div>
</div>
</body>
</html>