aboutsummaryrefslogtreecommitdiff
path: root/player.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'player.mjs')
-rw-r--r--player.mjs37
1 files changed, 37 insertions, 0 deletions
diff --git a/player.mjs b/player.mjs
new file mode 100644
index 0000000..a0e2535
--- /dev/null
+++ b/player.mjs
@@ -0,0 +1,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;
+ return this.render();
+ }
+ 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=${"player_" + this.id} ${type} onclick='togglePlayer(${this.id})'>${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;
+} \ No newline at end of file