Skip to content

Commit a74e13e

Browse files
committed
refactor: fix TheBallGame
1 parent fbee36c commit a74e13e

8 files changed

Lines changed: 318 additions & 267 deletions

File tree

TheBallGame.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Jogo da Bolinha</title>
66
<link rel="icon" href="resources/Bolinha_icon.ico"/>
77
<meta charset="UTF-8"/>
8-
<style> <!-- collapseit -->
8+
<!-- collapseit --> <style>
99
body {
1010
margin: 0px;
1111
width: 100%;
@@ -61,17 +61,13 @@
6161
</select>
6262
</div>
6363
<div name="background-FullSize" id="background"></div>
64-
<script name="Define Language">setLanguage(getCookie("language"))</script>
64+
<script name="Define Language"></script>
6565
<script name="Initialization"> /* collapseit */
66-
6766
</script>
6867
<script name="Events">
69-
7068
</script>
7169
<script name="Classes">
72-
73-
74-
</script>
70+
</script>
7571
<script name="Real Code"> /*collapseit*/
7672

7773
</script>

resources/languages/TheBallGame.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { element } from "../../src/JSTools";
22
import { canvas } from "../../src/TheBallGame/Initialization";
33

4-
let livesText_lang: string,
5-
scoreText_lang: string,
6-
playGameOption_lang: string,
7-
optionsOption_lang: string,
8-
downloadOption_lang: string,
9-
optionsSoon_lang: string,
10-
backToMenu_lang: string,
11-
exitOptionsButton_lang: string;
124
function setLanguage(language: "en" | "pt") {
135
switch (language) {
146
case "en":
@@ -18,14 +10,14 @@ function setLanguage(language: "en" | "pt") {
1810
element("backToIndex")!.innerHTML = "Back";
1911
element("reloadButton")!.innerHTML = "Reload";
2012
element("downloadGame")!.innerHTML = "Download Game (Portuguese only)";
21-
livesText_lang = "Lives";
22-
scoreText_lang = "Score";
23-
playGameOption_lang = "Play";
24-
optionsOption_lang = "Options";
25-
downloadOption_lang = "Download";
26-
optionsSoon_lang = "Soon";
27-
backToMenu_lang = "Exit";
28-
exitOptionsButton_lang = "Back to Main Menu";
13+
(window as any).globals.livesText_lang = "Lives";
14+
(window as any).globals.scoreText_lang = "Score";
15+
(window as any).globals.playGameOption_lang = "Play";
16+
(window as any).globals.optionsOption_lang = "Options";
17+
(window as any).globals.downloadOption_lang = "Download";
18+
(window as any).globals.optionsSoon_lang = "Soon";
19+
(window as any).globals.backToMenu_lang = "Exit";
20+
(window as any).globals.exitOptionsButton_lang = "Back to Main Menu";
2921
break;
3022
default:
3123
localStorage.removeItem("language");
@@ -35,26 +27,16 @@ function setLanguage(language: "en" | "pt") {
3527
element("backToIndex")!.innerHTML = "Voltar";
3628
element("reloadButton")!.innerHTML = "Recarregar";
3729
element("downloadGame")!.innerHTML = "Descarregar Jogo";
38-
livesText_lang = "Vidas";
39-
scoreText_lang = "Pontuação";
40-
playGameOption_lang = "Jogar";
41-
optionsOption_lang = "Opções";
42-
downloadOption_lang = "Descarregar";
43-
optionsSoon_lang = "Brevemente";
44-
backToMenu_lang = "Sair";
45-
exitOptionsButton_lang = "Voltar para o Menu Principal";
30+
(window as any).globals.livesText_lang = "Vidas";
31+
(window as any).globals.scoreText_lang = "Pontuação";
32+
(window as any).globals.playGameOption_lang = "Jogar";
33+
(window as any).globals.optionsOption_lang = "Opções";
34+
(window as any).globals.downloadOption_lang = "Descarregar";
35+
(window as any).globals.optionsSoon_lang = "Brevemente";
36+
(window as any).globals.backToMenu_lang = "Sair";
37+
(window as any).globals.exitOptionsButton_lang = "Voltar para o Menu Principal";
4638
break;
4739
}
4840
}
4941

50-
export {
51-
setLanguage,
52-
livesText_lang,
53-
scoreText_lang,
54-
playGameOption_lang,
55-
optionsOption_lang,
56-
downloadOption_lang,
57-
optionsSoon_lang,
58-
backToMenu_lang,
59-
exitOptionsButton_lang,
60-
};
42+
export { setLanguage };

src/JSTools.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,31 @@ class Rectangle extends Control {
282282
};
283283
}
284284
/*--------------------------------------Function-19-----------------------------------------------------------------*/
285-
function Circle(x: number, y: number, radius: number) {
286-
Control.call(this, x, y); //Inherit from Control
287-
this.radius = radius;
288-
}
289-
Circle.prototype = Object.create(Control.prototype);
290-
Circle.prototype.constructor = Circle;
291-
Circle.prototype.draw = function () {
292-
if (this.visible) {
293-
ctx.beginPath();
294-
ctx.fillStyle = this.color;
295-
ctx.strokeStyle = this.outlineColor;
296-
ctx.lineWidth = this.outlineWidth;
297-
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
298-
ctx.fill();
299-
ctx.stroke();
285+
class Circle extends Control {
286+
radius: number;
287+
288+
constructor(x: number, y: number, radius: number) {
289+
super(x, y); // Inherit from Control
290+
this.radius = radius;
291+
}
292+
293+
draw() {
294+
if (this.visible) {
295+
ctx.beginPath();
296+
ctx.fillStyle = this.color;
297+
ctx.strokeStyle = this.outlineColor;
298+
ctx.lineWidth = this.outlineWidth;
299+
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
300+
ctx.fill();
301+
ctx.stroke();
302+
}
303+
}
304+
305+
goTo(newX: number, newY: number) {
306+
this.x = newX + this.radius;
307+
this.y = newY + this.radius;
300308
}
301309
}
302-
Circle.prototype.goTo = function (newX: number, newY: number) {
303-
this.x = newX + this.radius;
304-
this.y = newY + this.radius;
305-
};
306310
/*--------------------------------------Function-20-----------------------------------------------------------------*/
307311
class Label extends Control {
308312
text: string;

0 commit comments

Comments
 (0)