Projektmanagement-Game/Webservice/Player.js

36 lines
720 B
JavaScript
Raw Normal View History

2021-06-17 06:45:45 +00:00
class Player {
2021-06-17 15:23:53 +00:00
curr_field = 0 ;
coord_x = 0;
coord_y = 0;
constructor(socketUsername, sprites) {
2021-06-17 06:45:45 +00:00
this.socketUsername = socketUsername;
2021-06-17 15:23:53 +00:00
this.sprites = sprites;
2021-06-17 06:45:45 +00:00
this.isAlive = true;
2021-06-17 15:23:53 +00:00
this.coord_x = sprites[0].getX();
this.coord_y = sprites[0].getY();
this.curr_field = 0;
}
getX(){
return this.coord_x;
2021-06-17 06:45:45 +00:00
}
2021-06-17 15:23:53 +00:00
getY(){
return this.coord_y;
}
2021-06-17 06:45:45 +00:00
move(amount) {
2021-06-17 15:23:53 +00:00
this.curr_field += amount;
this.coord_x = this.sprites[this.curr_field].getX();
this.coord_y = this.sprites[this.curr_field].getY();
2021-06-17 06:45:45 +00:00
if (this.position === 15) {
// todo: win
}
}
2021-06-17 15:23:53 +00:00
2021-06-17 06:45:45 +00:00
}
2021-06-17 15:23:53 +00:00
module.exports = Player;