Projektmanagement-Game/public/js/player.js

39 lines
729 B
JavaScript
Raw Normal View History

2021-06-10 08:09:16 +00:00
function createPlayers(amount) {
let players = new Array(amount);
for (let i = 0; i < amount; i++) {
players[i] = new Player();
}
return players;
}
class Player {
constructor() {
this.position = 0;
this.alive = true;
}
move(amount) {
this.position += amount;
if (this.position === 15) {
// todo: win
}
}
}
class Hunter {
constructor() {
this.position = 0;
}
move(amount) {
this.position += amount;
}
hunt(players) {
for (let i = 0; i < players.length; i++) {
2021-06-10 08:21:45 +00:00
if (players[i].position <= this.position) {
2021-06-10 08:09:16 +00:00
players[i].alive = false;
}
}
}
}