aboutsummaryrefslogtreecommitdiff
path: root/player.mjs
blob: d75e65972525618d46bbcb709fe1b420a00f3055 (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
28
29
30
31
32
33
34
35
36
37
export class Player {
    constructor(id, name, level, status) {
        this.id = id;
        this.name = name;
        this.level = typeof level !== 'undefined' ? level : 1;
        this.status = typeof status !== 'undefined' ? status : false;
    }
    toggle() {
        this.status = !this.status;
        this.print();
    }
    print() {
        let status = this.status ? "active" : "inactive";
        console.log(this.name + " has a level of " + this.level + " and is currently " + status);
    }
    render() {
        let type = this.status ? "" : 'class="outline secondary"';
        return `<button id=${"regular_" + this.id} ${type}>${this.name}</button>`;
    }
}

function randomLevel() {
    const max_level = 10;
    return Math.floor(Math.random() * max_level + 1);
}

function randomStatus() {
    return Math.random() < 0.5;
}

export function generatePlayers() {
    let players = [];
    for (let i = 0; i < 71; i++) {
        players.push(new Player(i, "Player " + i, randomLevel(), randomStatus()));
    }
    return players;
}