Browse Source

Refactoring: playerInit-Funktion neu geschrieben und optimiert

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

48
schlangen_und_leitern/js/playerHandling.js

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

Loading…
Cancel
Save