diff --git a/public/index.html b/public/index.html index b30a019..8cffa3f 100644 --- a/public/index.html +++ b/public/index.html @@ -56,6 +56,7 @@ + diff --git a/public/js/game.js b/public/js/game.js index 5c79357..d6261d5 100644 --- a/public/js/game.js +++ b/public/js/game.js @@ -6,9 +6,10 @@ sprite.jpg: https://media.istockphoto.com/photos/gray-granite-stone-texture-seamless-square-background-tile-ready-picture-id1096464726 */ let curr_player = 1; -let player_array = [1, 1, 1, 1]; +let player_array = createPlayers(4); let player_color = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00]; let player_sprite_array = []; +let hunter = new Hunter(); let answer = null; let show_card = false; diff --git a/public/js/player.js b/public/js/player.js new file mode 100644 index 0000000..d1e8ce0 --- /dev/null +++ b/public/js/player.js @@ -0,0 +1,39 @@ +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++) { + if (players[i].position === this.position) { + players[i].alive = false; + } + } + } +} \ No newline at end of file