add player and hunter class

This commit is contained in:
Thorsten Rausch 2021-06-10 10:09:16 +02:00
parent dc1af4eae6
commit bc6d839294
3 changed files with 42 additions and 1 deletions

View File

@ -56,6 +56,7 @@
<script src="js/Button.js"></script> <script src="js/Button.js"></script>
<script src="js/Sprite.js"></script> <script src="js/Sprite.js"></script>
<script src="js/chat.js"></script> <script src="js/chat.js"></script>
<script src="js/player.js"></script>
<script src="js/game.js"></script> <script src="js/game.js"></script>
<script src="js/index.js"></script> <script src="js/index.js"></script>
</body> </body>

View File

@ -6,9 +6,10 @@
sprite.jpg: https://media.istockphoto.com/photos/gray-granite-stone-texture-seamless-square-background-tile-ready-picture-id1096464726 sprite.jpg: https://media.istockphoto.com/photos/gray-granite-stone-texture-seamless-square-background-tile-ready-picture-id1096464726
*/ */
let curr_player = 1; 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_color = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00];
let player_sprite_array = []; let player_sprite_array = [];
let hunter = new Hunter();
let answer = null; let answer = null;
let show_card = false; let show_card = false;

39
public/js/player.js Normal file
View File

@ -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;
}
}
}
}