From a5c54a54fce2fe99763df5be2461b89d6bab18b0 Mon Sep 17 00:00:00 2001 From: Richard Halsall <–richard-glyn.halsall@informatik.hs-fulda.e> Date: Wed, 8 Feb 2023 16:32:32 +0100 Subject: [PATCH] =?UTF-8?q?Refactoring:=20Funktion=20zum=20Ein-=20und=20Au?= =?UTF-8?q?sblenden=20von=20HTML-Elementen=20hinzugef=C3=BCgt=20und=20wo?= =?UTF-8?q?=20n=C3=B6tig=20eingesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schlangen_und_leitern/js/makeBoard.js | 28 ++++++++++++---------- schlangen_und_leitern/js/playerHandling.js | 6 ++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/schlangen_und_leitern/js/makeBoard.js b/schlangen_und_leitern/js/makeBoard.js index 29637c8..ba30bd7 100644 --- a/schlangen_und_leitern/js/makeBoard.js +++ b/schlangen_und_leitern/js/makeBoard.js @@ -261,9 +261,9 @@ function checkPosition(player, objectArr){ //win condition if(player.newPosition == 100){ player.won = true; - document.getElementById("continue").style.display = "block" - document.getElementById("replay").style.display = "block" - document.getElementById("würfelBereich").style.display = "none" + changeElement("continue", "block") + changeElement("replay", "block") + changeElement("würfelBereich", "none") } //snake condition @@ -279,26 +279,28 @@ function checkPosition(player, objectArr){ function continueGame (){ - document.getElementById("continue").style.display = "none" - document.getElementById("replay").style.display = "none" - document.getElementById("würfelBereich").style.display = "grid" - + changeElement("continue", "none") + changeElement("replay", "none") + changeElement("würfelBereich", "grid") } function hideStartMenu(){ //playerselect versctecken - document.getElementById("2Player").style.display = "none"; - document.getElementById("3Player").style.display = "none"; - document.getElementById("4Player").style.display = "none"; - document.getElementById("isUp").style.display = "block"; + changeElement("2Player", "none") + changeElement("3Player", "none") + changeElement("4Player", "none") + changeElement("isUp", "block") // Wufelbereich zeigen. - document.getElementById("würfelBereich").style.display = "grid"; + changeElement("würfelBereich", "grid") } - \ No newline at end of file + function changeElement(id, style){ + + document.getElementById(id).style.display = style; + } \ No newline at end of file diff --git a/schlangen_und_leitern/js/playerHandling.js b/schlangen_und_leitern/js/playerHandling.js index f8da9ea..406d6f0 100644 --- a/schlangen_und_leitern/js/playerHandling.js +++ b/schlangen_und_leitern/js/playerHandling.js @@ -194,9 +194,9 @@ function checkPosition(player, objectArr){ //win condition if(player.newPosition == 100){ player.won = true; - document.getElementById("continue").style.display = "block" - document.getElementById("replay").style.display = "block" - document.getElementById("würfelBereich").style.display = "none" + changeElement("continue","block") + changeElement("replay","block") + changeElement("würfelBereich","none") } //snake condition