Browse Source

Refactoring: playerInit-Funktion neu geschrieben und optimiert

main
Richard Halsall 2 years ago
parent
commit
311d72f60e
  1. 44
      schlangen_und_leitern/js/playerHandling.js

44
schlangen_und_leitern/js/playerHandling.js

@ -33,44 +33,26 @@ function movePlayer(player, roll){
player.newPosition = player.position + roll; player.newPosition = player.position + roll;
if(player.newPosition >= 100){ if(player.newPosition >= 100){
player.newPosition = 100; player.newPosition = 100;
//TODO gewinn aufrufen.
} }
//TODO Schlange oder Leiter fehlschalg.
} }
//Draw Spieler bei Spiele init
function playerInit(playerArray){
for(let i = 0; i < playerArray.length; i++){
function initialise(count, playerArray){
//player id ie. count 0 =
var id = count +1;
var Token = document.createElement("div") var Token = document.createElement("div")
if(i == 0){
let position = playerArray[i].position
var boardPostition = boardLocation(position);
Token.classList.add("p1");
Token.id = "p1";
document.getElementById(boardPostition).appendChild(Token)
}
else if(i == 1){
let position = playerArray[i].position
let position = playerArray[count].position
var boardPostition = boardLocation(position); var boardPostition = boardLocation(position);
Token.classList.add("p2");
Token.id = "p2";
Token.classList.add("p"+ id);
Token.id = "p" + id;
document.getElementById(boardPostition).appendChild(Token) document.getElementById(boardPostition).appendChild(Token)
}
else if(i == 2){
let position = playerArray[i].position
var boardPostition = boardLocation(position);
Token.classList.add("p3");
Token.id = "p3";
document.getElementById(boardPostition).appendChild(Token)
}
else if(i == 3){
let position = playerArray[i].position
var boardPostition = boardLocation(position);
Token.classList.add("p4");
Token.id = "p4";
document.getElementById(boardPostition).appendChild(Token)
}
}
//Draw Spieler bei Spiele init
function playerInit(playerArray){
for(let i = 0; i < playerArray.length; i++){
initialise(i,playerArray)
} }
} }

Loading…
Cancel
Save