-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
182 lines (166 loc) · 6.41 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
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
console.log("DON'T WRITE ANYTHING YOU DON'T UNDERSTAND OR ELSE YOUR BROWSER COULD CRASH AND YOU WON'T BE ABLE TO OPEN THE SAME BROWSER AGAIN, I AM NOT KIDDING")
//putting html elements in variables so that i can use it in the later part of the code
const input_gender = document.getElementById("gender-input");
const input_submit = document.getElementById("gender-submit");
const gender_div = document.getElementById("gend-div");
const avatar = document.getElementById("avatar-image");
const bet_button = document.getElementById("bet-button");
const bet_input = document.getElementById("bet-money");
const money_left_text = document.getElementById("user-money-left");
const roll_button = document.getElementById("roll-button");
const random_dice = document.getElementById("dice");
const computer_money_text = document.getElementById("money-left_computer");
//making variables to be used in the game
let gender;
let money_left = 10_000;
let state;
let money_inputted;
let seconds_before_reload = 1000;
let computer_money = 10_000;
//initializing sounds
const aww = new Audio("sounds/aww.mp3");
const money = new Audio("sounds/cash.mp3");
//setting text content to money left
$(computer_money_text).text(computer_money);
$(money_left_text).text(`Money left: ${money_left}`);
//functions
const genderCheck = () =>{
if((input_gender.value.toLowerCase() == "male") || (input_gender.value.toLowerCase() == "female")){
$(gender_div).addClass("gender-input-done");
$(gender_div).removeClass("gender-input");
if($(input_gender).val().toLowerCase() == "male"){
gender = "male";
avatar.style.background = "none";
avatar.style.borderRadius = "0%";
avatar.src = "images/profile.png";
}else if($(input_gender).val().toLowerCase() == "female"){
gender = "female";
avatar.src = "images/woman.png";
avatar.style.background = "white";
avatar.style.borderRadius = "50%";
}
}else{
location.reload();
}
}
const hideRollButton = () =>{
$(roll_button).hide();
}
const showRollButton = () =>{
$(roll_button).show();
}
const random = (min, max) => {
return Math.floor(Math.random() * (max - min)) + min;
};
hideRollButton();
$(input_submit).click(function (e) {
e.preventDefault();
genderCheck();
});
$(input_gender).keydown(function (e) {
if(e.key == "Enter"){
genderCheck();
}
});
let bet_money;
$(bet_button).click(function (e) {
e.preventDefault();
if(($(bet_input).val() > 0) && ($(bet_input).val() <= money_left)){
if(money_left == 0){
alert("You lost, the computer won")
location.reload();
}else{
money_inputted = Number($(bet_input).val());
$(money_left_text).text(`Money left: ${money_left}`);
}
$(bet_input).val("");
$(bet_button).hide();
$(bet_input).css("border", "4px solid transparent");
showRollButton();
}else{
$(bet_input).css("border", "4px solid red");
}
});
$(roll_button).click(function (e) {
window.scrollTo(0,document.body.scrollHeight);
e.preventDefault();
let random_num = random(1,12);
$(random_dice).text(random_num)
$(roll_button).hide();
$(bet_button).show();
$(random_dice).css("visibility", "visible");
if(random_num >= 7){
money.play();
state = "doubled";
money_left+= money_inputted;
computer_money -= money_inputted;
$(computer_money_text).text(computer_money);
$(money_left_text).text(`Money left: ${money_left}`);
setTimeout(() =>{
if(money_left == 0){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(money_left > 1_000_000){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
if(computer_money > 1_000_000){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(computer_money <= 0){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
},1000)
}else if(random_num <= 5){
state = "removed";
aww.play();
money_left -= money_inputted;
computer_money += money_inputted;
$(computer_money_text).text(computer_money);
$(money_left_text).text(`Money left: ${money_left}`);
setTimeout(() =>{
if(money_left == 0){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(money_left > 1_000_000){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
if(computer_money > 1_000_000){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(computer_money <= 0){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
},1000)
}else if(random_num == 6){
money.play();
state = "tripled";
money_left+= money_inputted + money_inputted;
computer_money -= money_inputted + money_inputted;
$(computer_money_text).text(computer_money);
$(money_left_text).text(`Money left: ${money_left}`);
setTimeout(() =>{
if(money_left == 0){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(money_left > 1_000_000){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
if(computer_money > 1_000_000){
alert("You lost, the computer won")
setTimeout(() =>{location.reload();},seconds_before_reload)
}else if(computer_money <= 0){
alert("You won,the computer lost")
setTimeout(() =>{location.reload();},seconds_before_reload)
}
},1000)
}else{
location.reload();
}
console.log(state);
});
console.log("hello world");