aboutsummaryrefslogtreecommitdiffstats
path: root/src/Ball.ts
blob: c520cb8b6cec5141d3645e74473f0ca3e7d474f9 (plain) (blame)
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
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;
  }
}