-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
141 lines (131 loc) · 3.8 KB
/
main.js
File metadata and controls
141 lines (131 loc) · 3.8 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
import cry from "./images/cry.gif";
import pooped from "./images/pooped.gif";
import cuddle from "./images/cuddle.gif";
import playing from "./images/play.gif";
import tobed from "./images/gotobed.gif";
import scared from "./images/scared.gif";
import happytosee from "./images/happytosee.gif";
import kisses from "./images/kisses.gif";
import shocked from "./images/shocked.gif";
import laugh from "./images/laughwithtears.gif";
const about = document.getElementById("about");
const clean = document.getElementById("clean");
const bio = document.querySelector(".bio");
const poop = document.querySelector(".poop");
const petMe = document.querySelector("#petMe");
const play = document.querySelector("#play");
const sleep = document.querySelector("#sleep");
const scold = document.querySelector("#scold");
const eat = document.querySelector("#eat");
const walk = document.querySelector("#walk");
const pic = document.querySelector("#shiba");
const burger = document.querySelector(".burger");
var cont = document.getElementById("myProgress");
var elem = document.getElementById("myBar");
const energy = document.getElementById("energy");
const happy = document.getElementById("happy");
const toilet = document.getElementById("toilet");
const hunger = document.getElementById("hunger");
function move(interval, color) {
cont.style.display = "block";
var i = 0;
if (i == 0) {
i = 1;
var width = 1;
var id = setInterval(frame, interval);
function frame() {
if (width >= 100) {
clearInterval(id);
i = 0;
} else {
width++;
elem.style.width = width + "%";
elem.style.backgroundColor = color;
if (width === 98) {
cont.style.display = "none";
}
}
}
}
}
about.addEventListener("click", showBio);
let birthday = new Date("November 3, 2021 03:24:00");
let now = new Date();
var myCount = setInterval(function () {
count();
}, 5000);
var countProgress = 1;
function count() {
if (countProgress > 10) {
energy.value -= 1;
happy.value -= 1.5;
toilet.value -= 2.5;
hunger.value -= 2;
}
if (toilet.value == 0) {
pic.setAttribute("src", pooped);
poop.style.display = "block";
toilet.value = 100;
}
if (energy.value === 0 && happy.value === 0 && hunger.value === 0) {
pic.setAttribute("src", cry);
}
countProgress++;
}
function showBio() {
bio.classList.toggle("bioOn");
}
petMe.addEventListener("click", petTheDog);
function petTheDog() {
pic.setAttribute("src", cuddle);
elem.textContent = "Счастье";
move(10, "green");
happy.value += 20;
}
play.addEventListener("click", playWithMe);
function playWithMe() {
pic.setAttribute("src", playing);
elem.textContent = "Счастье";
move(10, "green");
happy.value += 20;
}
sleep.addEventListener("click", goToBed);
function goToBed() {
pic.setAttribute("src", tobed);
elem.textContent = "Энергия";
move(10, "green");
energy.value = 100;
}
scold.addEventListener("click", scareMe);
function scareMe() {
pic.setAttribute("src", scared);
elem.textContent = "Счастье";
move(10, "red");
happy.value -= 20;
}
eat.addEventListener("click", feedMe);
function food() {
burger.classList.remove("burgerTrue");
}
function feedMe() {
pic.setAttribute("src", happytosee);
elem.textContent = "Сытость";
move(10, "green");
burger.classList.add("burgerTrue");
setTimeout(food, 5000);
setTimeout(() => pic.setAttribute("src", kisses), 5000);
hunger.value += 50;
}
walk.addEventListener("click", goForWalk);
function goForWalk() {
pic.setAttribute("src", shocked);
elem.textContent = "Туалет";
move(10, "green");
document.body.classList.toggle("beach");
toilet.value = 100;
}
clean.addEventListener("click", cleanPoops);
function cleanPoops() {
poop.style.display = "none";
pic.setAttribute("src", laugh);
}