add player and hunter class
This commit is contained in:
parent
dc1af4eae6
commit
bc6d839294
@ -56,6 +56,7 @@
|
||||
<script src="js/Button.js"></script>
|
||||
<script src="js/Sprite.js"></script>
|
||||
<script src="js/chat.js"></script>
|
||||
<script src="js/player.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
</body>
|
||||
|
@ -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;
|
||||
|
39
public/js/player.js
Normal file
39
public/js/player.js
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user