Skip to content

Commit 0932ab7

Browse files
tabunagithub-actions[bot]
authored andcommitted
Fixed code style
1 parent c8e99cc commit 0932ab7

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

resources/css/gagarin.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
bottom: -50%;
3434
top: -50%;
3535
left: -50%;
36-
right: -50%
36+
right: -50%;
3737
}
3838

3939
svg {

resources/js/controllers/vostok_controller.js

+45-37
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { Controller } from '@hotwired/stimulus';
22

3-
43
export default class extends Controller {
5-
static targets = ["game", "ship", "comet", "message", "timer", "audioBackground", "startPlaceholder", "endPlaceholder"];
4+
static targets = [
5+
'game',
6+
'ship',
7+
'comet',
8+
'message',
9+
'timer',
10+
'audioBackground',
11+
'startPlaceholder',
12+
'endPlaceholder',
13+
];
614

715
connect() {
816
this.svg = this.gameTarget;
@@ -13,22 +21,22 @@ export default class extends Controller {
1321
this.cometWidth = 60;
1422
this.cometHeight = 60;
1523
this.cometInterval = 1000;
16-
document.addEventListener("keydown", this.keyDownHandler.bind(this));
17-
document.addEventListener("keyup", this.keyUpHandler.bind(this));
24+
document.addEventListener('keydown', this.keyDownHandler.bind(this));
25+
document.addEventListener('keyup', this.keyUpHandler.bind(this));
1826
this.audioBackgroundTarget.loop = true;
1927
}
2028

2129
disconnect() {
22-
document.removeEventListener("keydown", this.keyDownHandler.bind(this));
23-
document.removeEventListener("keyup", this.keyUpHandler.bind(this));
30+
document.removeEventListener('keydown', this.keyDownHandler.bind(this));
31+
document.removeEventListener('keyup', this.keyUpHandler.bind(this));
2432
}
2533

2634
fresh() {
2735
while (this.svg.firstChild) {
2836
this.svg.removeChild(this.svg.firstChild);
2937
}
3038

31-
this.timer = 0
39+
this.timer = 0;
3240
this.cometSpeed = this.baseCometSpeed;
3341
this.shipX = (this.svg.width.baseVal.value - this.shipWidth) / 2;
3442
this.shipY = this.svg.height.baseVal.value - this.shipHeight - 10;
@@ -41,28 +49,28 @@ export default class extends Controller {
4149
}
4250

4351
keyDownHandler(event) {
44-
if (event.key === "ArrowLeft") {
52+
if (event.key === 'ArrowLeft') {
4553
this.leftPressed = true;
46-
} else if (event.key === "ArrowRight") {
54+
} else if (event.key === 'ArrowRight') {
4755
this.rightPressed = true;
4856
}
4957
}
5058

5159
keyUpHandler(event) {
52-
if (event.key === "ArrowLeft") {
60+
if (event.key === 'ArrowLeft') {
5361
this.leftPressed = false;
54-
} else if (event.key === "ArrowRight") {
62+
} else if (event.key === 'ArrowRight') {
5563
this.rightPressed = false;
5664
}
5765
}
5866

5967
createShipElement() {
6068
const shipElement = this.shipTarget.cloneNode(true);
61-
shipElement.setAttribute("x", this.shipX);
62-
shipElement.setAttribute("y", this.shipY);
63-
shipElement.setAttribute("width", this.shipWidth);
64-
shipElement.setAttribute("height", this.shipHeight);
65-
shipElement.setAttribute("fill", "#FFFFFF");
69+
shipElement.setAttribute('x', this.shipX);
70+
shipElement.setAttribute('y', this.shipY);
71+
shipElement.setAttribute('width', this.shipWidth);
72+
shipElement.setAttribute('height', this.shipHeight);
73+
shipElement.setAttribute('fill', '#FFFFFF');
6674
this.svg.appendChild(shipElement);
6775
return shipElement;
6876
}
@@ -73,22 +81,22 @@ export default class extends Controller {
7381
} else if (this.rightPressed && this.shipX < this.svg.width.baseVal.value - this.shipWidth) {
7482
this.shipX += this.shipSpeed;
7583
}
76-
this.shipElement.setAttribute("x", this.shipX);
84+
this.shipElement.setAttribute('x', this.shipX);
7785
}
7886

7987
createCometElement(x, y) {
8088
const cometElement = this.cometTarget.cloneNode(true);
81-
cometElement.setAttribute("x", x);
82-
cometElement.setAttribute("y", y);
83-
cometElement.setAttribute("width", this.cometWidth);
84-
cometElement.setAttribute("height", this.cometHeight);
85-
cometElement.setAttribute("fill", "#FF0000");
89+
cometElement.setAttribute('x', x);
90+
cometElement.setAttribute('y', y);
91+
cometElement.setAttribute('width', this.cometWidth);
92+
cometElement.setAttribute('height', this.cometHeight);
93+
cometElement.setAttribute('fill', '#FF0000');
8694
this.svg.appendChild(cometElement);
8795
return cometElement;
8896
}
8997

9098
moveComets() {
91-
this.comets.forEach(comet => {
99+
this.comets.forEach((comet) => {
92100
comet.y += this.cometSpeed;
93101
comet.x = comet.element.getAttribute('x');
94102
comet.x -= this.cometSpeed;
@@ -97,12 +105,12 @@ export default class extends Controller {
97105
const distance = Math.sqrt(dx * dx + dy * dy);
98106
const vx = dx / distance;
99107
const vy = dy / distance;
100-
if(distance > 100){
108+
if (distance > 100) {
101109
comet.x += vx;
102110
comet.y += vy;
103111
}
104-
comet.element.setAttribute("x", comet.x);
105-
comet.element.setAttribute("y", comet.y);
112+
comet.element.setAttribute('x', comet.x);
113+
comet.element.setAttribute('y', comet.y);
106114
if (comet.y > this.svg.height.baseVal.value) {
107115
this.svg.removeChild(comet.element);
108116
this.comets.splice(this.comets.indexOf(comet), 1);
@@ -111,20 +119,21 @@ export default class extends Controller {
111119
}
112120

113121
createComet() {
114-
let x = Math.random() * this.svg.width.baseVal.value + (this.svg.width.baseVal.value * 0.5);
122+
let x = Math.random() * this.svg.width.baseVal.value + this.svg.width.baseVal.value * 0.5;
115123
if (this.shipX > this.svg.width.baseVal.value / 3) {
116-
x += (this.shipX * 0.5);
124+
x += this.shipX * 0.5;
117125
}
118126
const y = 0;
119127
const cometElement = this.createCometElement(x, y);
120-
this.comets.push({element: cometElement, y: y});
128+
this.comets.push({ element: cometElement, y: y });
121129
}
122130

123131
collisionDetection(fuzziness) {
124132
const shipRect = this.shipElement.getBoundingClientRect();
125-
this.comets.forEach(comet => {
133+
this.comets.forEach((comet) => {
126134
const cometRect = comet.element.getBoundingClientRect();
127-
const fuzzinessFactor = fuzziness * Math.min(shipRect.width, shipRect.height, cometRect.width, cometRect.height);
135+
const fuzzinessFactor =
136+
fuzziness * Math.min(shipRect.width, shipRect.height, cometRect.width, cometRect.height);
128137
if (
129138
shipRect.left + fuzzinessFactor < cometRect.right &&
130139
shipRect.right - fuzzinessFactor > cometRect.left &&
@@ -140,15 +149,14 @@ export default class extends Controller {
140149
});
141150
}
142151

143-
stats(){
152+
stats() {
144153
this.timer = this.timer + 0.5;
145-
let value = (this.timer / 100).toFixed(2)
154+
let value = (this.timer / 100).toFixed(2);
146155

147156
this.timerTarget.innerText = value;
148157
this.cometSpeed = this.baseCometSpeed + value * 0.1;
149158

150-
151-
if(value > 20) {
159+
if (value > 20) {
152160
clearInterval(this.intervalComet);
153161
clearInterval(this.intervalGame);
154162

@@ -159,12 +167,12 @@ export default class extends Controller {
159167
draw() {
160168
this.moveShip();
161169
this.moveComets();
162-
this.collisionDetection(0.4); // Погрешность 40%
170+
this.collisionDetection(0.4); // Погрешность 40%
163171
this.stats();
164172
}
165173

166174
start() {
167-
if(this.audioBackgroundTarget.currentTime === 0) {
175+
if (this.audioBackgroundTarget.currentTime === 0) {
168176
this.audioBackgroundTarget.play();
169177
}
170178

0 commit comments

Comments
 (0)