aboutsummaryrefslogtreecommitdiffstats
path: root/src/Ball.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ball.ts')
-rw-r--r--src/Ball.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Ball.ts b/src/Ball.ts
new file mode 100644
index 0000000..c520cb8
--- /dev/null
+++ b/src/Ball.ts
@@ -0,0 +1,27 @@
+import { START_NO_OF_BALLS, MAP_WIDTH, MAP_HEIGHT, COLORS, TD_SIZE, CIRCLE_SIZE } from "./consts";
+import { getRandomInt, getRandomEl } from "./utils";
+
+export default class Ball {
+ x: number;
+ y: number;
+ color: string;
+
+ constructor(x: number, y: number, color: string) {
+ this.x = x;
+ this.y = y;
+ this.color = color;
+ }
+ onclick(el: PointerEvent) {
+ }
+ static generateStartBalls(): Array<Ball> {
+ const out = <Ball[]>[];
+ for (let i = 0; i < START_NO_OF_BALLS; i++) {
+ let x: number, y: number, color: string;
+ do {
+ [x, y, color] = [getRandomInt(0, MAP_HEIGHT), getRandomInt(0, MAP_WIDTH), getRandomEl(COLORS)];
+ } while (out.filter(b => b.x === x && b.y === y).length !== 0)
+ out.push(new Ball(x, y, color));
+ }
+ return out;
+ }
+}