-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
180 lines (150 loc) · 5.66 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles/home.css" />
<title>Cooked</title>
</head>
<body>
<div class="game">
<!-- Status of fullness and Money Stats-->
<div class="barsArea">
<div id="timer">00:15</div>
<div class="healthBar">
<div class="totallyFull"></div>
<div class="midFull"></div>
<div class="notFull"></div>
</div>
<div class="moneyBar">
<span id="cakeCount">0</span> cakes
</div>
</div>
<!-- Customers-->
<div class="customersArea">
<div class="customers">
<div id="customer1Order"></div>
<div class="customer1" id="customer1CheckOrder">
<img src="images/char_bunny.png" />
</div>
<div id="customer2Order"></div>
<div class="customer2">
<img src="images/char_chick.png" />
</div>
<div id="customer3Order"></div>
<div class="customer3">
<img src="images/char_cow.png" />
</div>
</div>
</div>
<!-- Variety of Ingredients and Overall cooking work environment-->
<div class="cookingStationArea">
<div class="food">
<div class="topping1" id="addBanana"><img src="images/banana.png" /></div>
<div class="topping2" id="addStrawberry"><img src="images/strawberry.png" /></div>
<div class="topping3" id="addBlueberry"><img src="images/blueberry.png" /></div>
<div class="cake"><img src="images/cake.png" /></div>
<div class="cakeStand"><img src="images/cakeStand.png" /></div>
<div class="topping4" id="addPineapple"><img src="images/pineapple.png" /></div>
<div class="topping5" id="addSprinkles"><img src="images/sprinkles.png" /></div>
</div>
</div>
</div>
<script>
function getRandomInt(min, max) {
min = Math.ceil(min); // Round up to the nearest integer
max = Math.floor(max); // Round down to the nearest integer
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const toppings = [
"banana",
"strawberry",
"blueberry",
"pineapple",
"sprinkles",
];
function generateOrder() {
let numberOfToppings = getRandomInt(0, 2);
let selectedToppings = [];
for (let i = 0; i <= numberOfToppings; i++) {
let foundUniqueTopping = false
while (!foundUniqueTopping) {
let randomToppingIndex = getRandomInt(0, toppings.length - 1);
if (!selectedToppings.includes (toppings[randomToppingIndex])){
selectedToppings.push(toppings[randomToppingIndex])
foundUniqueTopping = true
}
}
}
return selectedToppings
}
let customer1Order
function resetCustomer1() {
customer1Order = generateOrder()
let element = document.getElementById("customer1Order")
let htmlUpdate = ""
for (let i = 0; i < customer1Order.length; i ++) {
let orderItem = customer1Order[i]
htmlUpdate += `<img src="images/${orderItem}.png" class="order">`
}
element.innerHTML = htmlUpdate
}
resetCustomer1()
let cakeIngredients = []
let cakeCount = 0
function addIngredient(event, ingredientName){
console.log(event)
console.log(ingredientName)
if (!cakeIngredients.includes(ingredientName)){
cakeIngredients.push(ingredientName)
}
console.log(cakeIngredients)
}
document.getElementById("addBanana").addEventListener("click", function (event) {
addIngredient(event, "banana")
})
document.getElementById("addStrawberry").addEventListener("click", function (event) {
addIngredient(event, "strawberry")
})
document.getElementById("addBlueberry").addEventListener("click", function (event) {
addIngredient(event, "blueberry")
})
document.getElementById("addPineapple").addEventListener("click", function (event) {
addIngredient(event, "pineapple")
})
document.getElementById("addSprinkles").addEventListener("click", function (event) {
addIngredient(event, "sprinkles")
})
document.getElementById("customer1CheckOrder").addEventListener("click", function(event){
let validOrder = true
customer1Order.forEach( function (ingredient){
if (!cakeIngredients.includes(ingredient)){
validOrder = false
}
})
if (validOrder == true) {
alert("Thank you!")
cakeCount++
document.getElementById("cakeCount").innerText=cakeCount
resetCustomer1()
}
else {
alert("Ew!")
}
})
let seconds = 15; // Start time in seconds
function startTimer() {
const timerElement = document.getElementById("timer");
setInterval(() => {
seconds--;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
timerElement.textContent =
`${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
}, 1000); // Update every second
}
// Start the timer when the page loads
startTimer();
</script>
</body>
</html>