This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (85 loc) · 2.33 KB
/
index.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
if (localStorage.getItem('game') == null) {
makeGame()
} else {
runGame()
}
function makeGame() {
var obj = {
'gen': {
'fuel': 100,
'level': 1
},
'fridge': {
'contents': {
'mc': 5
},
'level': 1
},
'oven': {
'level': 1
},
'bank': {
'level': 1,
'money': 0
}
}
localStorage.setItem('game', JSON.stringify(obj))
location.reload()
}
function runGame() {
var game = JSON.parse(localStorage.getItem('game'))
var foodKey = {
'mc': 'mac and cheese'
}
var p = document.createElement('p')
console.log(Object.keys(game.fridge.contents).length)
var list = []
var lString = ''
for (var i = 0; i < Object.keys(game.fridge.contents).length; i++) {
var obk = Object.keys(game.fridge.contents)[i]
var obj = {}
obj[obk] = Object.values(game.fridge.contents)[i]
list.push(obj)
}
for (var i = 0; i < list.length; i++) {
if (list.length == 0) {break}
lString += `${foodKey[String(Object.keys(list[i]))]}: ${Object.values(list[i])[i]} `
}
if (lString == '') {lString = 'Nothing!'}
console.log(list, lString)
p.innerText = `
Generator: ${game.gen.fuel}
Fridge: ${lString}
`
document.body.append(p)
drawButtons()
}
function drawButtons() {
var refuel = document.createElement('button')
var bank = document.createElement('button')
var eat = document.createElement('button')
refuel.innerText = 'refuel'
bank.innerText = 'bank'
eat.innerText = 'eat'
try {
refuel.addEventListener('click', function() {btnHandler('refuel')})
bank.addEventListener('click', function() {btnHandler('bank')})
eat.addEventListener('click', function() {btnHandler('eat')})
} catch (error) {
location.reload()
}
document.body.append(refuel, bank, eat)
}
function btnHandler(btn) {
switch (btn) {
case 'refuel': {
break
}
case 'bank': {
break
}
case 'eat': {
break
}
}
}