Преглед изворни кода

Merge branch 'master' into 'master'

mise à jour du fonctionnement des tours

See merge request tompeur/ecr19-t3-e!10
KREBS-CHEVRESSON CLEMENT пре 6 година
родитељ
комит
37b4db7492
14 измењених фајлова са 563 додато и 78 уклоњено
  1. 6 2
      css/style.css
  2. 37 0
      eventCTRL.js
  3. 107 0
      events.js
  4. 2 2
      html/index.html
  5. 0 74
      html/jeu.html
  6. 56 0
      indicatorCTRL.js
  7. 41 0
      jeu.html
  8. 58 0
      laws.js
  9. 131 0
      lawsCTRL.js
  10. 20 0
      main.js
  11. 59 0
      optionsCTRL.js
  12. 6 0
      start.js
  13. 12 0
      style.css
  14. 28 0
      turn.js

+ 6 - 2
css/style.css

@@ -7,6 +7,10 @@ body {
 	flex-direction: row;
 }
 
-#topNavBar {
-	
+div {
+	border: solid 1px red;
+}
+
+.indicator {
+	margin-right: 5rem;
 }

+ 37 - 0
eventCTRL.js

@@ -0,0 +1,37 @@
+
+
+/* Fonction qui prend un event au hazard */
+function randEvent(){
+  let found = false;
+  let id = -1;
+  if (randInt(0, 1) == 0) {
+    while (!found) {
+      if (usedEvents.length >= events.length) {
+        break;
+      }
+      id = randInt(0, events.length - 1);
+      found = true;
+      for (var i = 0; i < usedEvents.length; i++) {
+        if (usedEvents[i] == id) {
+            found = false;
+        }
+      }
+    }
+  }
+  console.log(id);
+  return id;
+}
+
+/* fonction qui génère l'HTML pour un evenement */
+
+function displayEvent(eventID) {
+  document.querySelector("#event").innerHTML = genEvent(eventID);
+}
+
+function genNoEvent() {
+  document.querySelector("#event").innerHTML = "Pas d'evenement";
+}
+
+function genEvent(eventID) {
+  return '<p>' + events[eventID].nom + '</p><p>' + events[eventID].description + "</p>";
+}

+ 107 - 0
events.js

@@ -0,0 +1,107 @@
+const events = [
+    {
+        nom : "Tremblement de terre",
+        description : "Un tremblement de terre vient de surgir, et beacoup des paysans se retrouvent sans toit sur leur têtes.",
+        lois : [
+            {
+                nom: "Recueil par les nobles",
+                descriptions: [
+                    "Les seigneurs ont pour obligation de recueillir dans leur château au moins le tiers le plus touché",
+                    "Les seigneurs ont pour obligation de recueillir dans leur château au moins la moitiée  la plus touchée",
+                    "Les seigneurs doivent recueillir l'ensemble de leurs paysans affectés"
+                ],
+                effets: {cri: 0, rel: 0, eco: 0, nob: -5, peu: 8},
+                niveau: 0
+            },
+            {
+                nom: "Recueil par l'église",
+                descriptions: [
+                    "L'église a pour obligation de recueillir au moins le tiers des fidèles les plus touché",
+                    "L'église a pour obligation de recueillir au moins la moitié des fidèles les plus touché",
+                    "L'église a pour obligation de recueillir la totalité des fidèles "
+                ],
+                effets: {cri: 0, rel: -3, eco: 0, nob: 0, peu: 4},
+                niveau: 0
+            }
+        ]
+    },
+    {
+        nom : "Annonce du pape",
+        description : "Le pape vient de déclarer que les criminels devaient être punis moins fortemment, en tant qu'enfants du seigneur.",
+        lois : [
+            {
+                nom: "Baisse des sentences criminelles",
+                descriptions: [
+                    "La peine de mort est réservée aux assassins.",
+                    "Les prisons sont financés par un nouvel impôt.",
+                    "Plus aucun criminel n'est puni, ils doivent seulement se repentir devant dieu."
+                ],
+                effets: {cri: 10, rel: 5, eco: -5, nob: -5, peu: -3},
+                niveau: 0
+            },
+            {
+                nom: "Transfert des criminels au vatican",
+                descriptions: [
+                    "Un centième des criminels sont désormais evoyés directement au pape.",
+                    "Un dixieme des criminels sont désormais evoyés directement au pape.",
+                    "La moitié des criminels sont désormais evoyés directement au pape.",
+                ],
+                effets: {cri: -10, rel: -3, eco: -3, nob: 2, peu: 4},
+                niveau: 0
+            }
+        ]
+    },
+    {
+        nom : "Famine",
+        description : "Les récoltes ont été pitoyables. Votre peuple se meurt de faim.",
+        lois : [
+            {
+                nom: "Baisse de la dime du clergé",
+                descriptions: [
+                    "La part de la dime réservée au clergé baisse d'un tiers.",
+                    "La part de la dime réservée au clergé baisse d'un quart.",
+                    "La part de la dime réservée au clergé baisse de moitié.",
+                ],
+                effets: {cri: 0, rel: -5, eco: 5, nob: 3, peu: 13},
+                niveau: 0
+            },
+            {
+                nom: "Baisse de la dime de la noblesse",
+                descriptions: [
+                    "La part de la dime réservée à la noblesse baisse d'un tiers.",
+                    "La part de la dime réservée à la noblesse baisse d'un quart.",
+                    "La part de la dime réservée à la noblesse baisse de moitié.",
+                ],
+                effets: {cri: 0, rel: 3, eco: 5, nob: -5, peu: 13},
+                niveau: 0
+            }
+        ]
+    },
+    {
+        nom : "Epidemie",
+        description : "Une épidémie d'une maladie inconnue s'est déclarée. Les victimes se font déjà nombreuses.",
+        lois : [
+            {
+                nom: "Loi anti importations",
+                descriptions: [
+                    "Les impots sur les importations sont augmentés de 10%",
+                    "Les impots sur les importations sont augmentés de 20%",
+                    "Les impots sur les importations sont augmentés de 30%"
+                ],
+                effets: {cri: 0, rel: -5, eco: 5, nob: 3, peu: 13},
+                niveau: 0
+            },
+            {
+                nom: "Lois sur l'hygiène",
+                descriptions: [
+                    "Contrôles sanitaires recommandés",
+                    "Contrôles sanitaires renforcés",
+                    "Contrôles sanitaires obligatoires"
+
+                ],
+                effets: {cri: 0, rel: 3, eco: 5, nob: -5, peu: 13},
+                niveau: 0
+            }
+        ]
+    }
+]

+ 2 - 2
html/index.html

@@ -7,8 +7,8 @@
 
     <body>
         <div>
-             <button onclick="location.href = 'jeu.html';">Nouvelle partie</button>
+             <button onclick="location.href = '../jeu.html';">Nouvelle partie</button>
              <button onclick="location.href = 'tuto.html';">Tutoriel</button>
         </div>
     </body>
-</html>
+</html>

+ 0 - 74
html/jeu.html

@@ -1,74 +0,0 @@
-<!DOCTYPE html>
-<html>
-	<head>
-		<title>Tompeur</title>
-		<link rel="stylesheet" type="text/css" href="../css/style.css">
-		<meta lang="fr" charset="utf-8">
-	</head>
-	<body>
-		<!-- Barre de navigation -->
-		<div id="topNavBar" class="flexRow">
-
-			<!-- Le tour de jeu actuel -->
-			<div id="tour" class="flexRow">
-				<p>Tour : </p>
-				<p id="tourVal">0</p>
-			</div>
-
-			<!-- Les indicateurs -->
-			<div id="lsIndics" class="flexRow">
-
-				<div class="indicateur flexRow"> <!-- un indicateur particulier -->
-					<p>Crime : </p>
-					<p id="crime">0</p>
-				</div>
-
-				<div class="indicateur flexRow">
-					<p>Religion : </p>
-					<p id="religion">0</p>
-				</div>
-
-				<div class="indicateur flexRow">
-					<p>Economie : </p>
-					<p id="economie">0</p>
-				</div>
-
-				<div class="indicateur flexRow">
-					<p>Noblesse : </p>
-					<p id="noblesse">0</p>
-				</div>
-
-				<div class="indicateur flexRow">
-					<p>Peuple : </p>
-					<p id="peuple">0</p>
-				</div>
-
-			</div>
-		</div>
-
-		<!-- Liste des lois votées -->
-		<div id="lsLois">
-			<!-- Les lois seront insérées ici dynamiquement par le javascript -->
-		</div>
-		<!-- Fenetre principale -->
-		<div id="main">
-			<div id="evenement">
-				
-			</div>
-			<div id="lsChoixLois">
-				<div class="choixLoi" id="choixLoi1">
-
-				</div>
-				<div class="choixLoi" id="choixLoi2">
-
-				</div>
-			</div>
-		</div>
-
-	</body>
-	<script type="text/javascript"  src="../js/laws.js"></script>
-	<script type="text/javascript"  src="../js/events.js"></script>
-	<script type="text/javascript"  src="../js/utils.js"></script>
-	<script type="text/javascript"  src="../js/interface.js"></script>
-	<script type="text/javascript"  src="../js/main.js"></script>
-</html>

+ 56 - 0
indicatorCTRL.js

@@ -0,0 +1,56 @@
+/* indicator table */
+
+var tableIndicators = [["Criminalité",0],["Religion",0],["Economie",0],["Noblesse",0],["Peuple",0]];
+
+var currentTurn = 0;
+
+/*  */
+
+function genAllIndicators() {
+  let element = document.querySelector("#indicator");
+  element.innerHTML = genTurn() + "<div>" + genListeIndicators() + "</div>";
+  }
+
+/* tour de jeu actuel */
+
+function genTurn() {
+  return '<div><p>Tour : </p><p>' + currentTurn + "</p></div>";
+  }
+
+/* indicator */
+
+function genListeIndicators() {
+  let res = "";
+  for (var i = 0; i < tableIndicators.length; i++) {
+      res = res + genIndicator(i);
+    }
+  return res;
+  }
+
+function genIndicator(i) {
+  return '<div><p>' + tableIndicators[i][0] + ' : </p><p>' + tableIndicators[i][1] + "</p></div>";
+  }
+
+function updateIndicatorsAddLaws(law) {
+  tableIndicators[0][1] = tableIndicators[0][1] + law.effets.cri;
+  tableIndicators[1][1] = tableIndicators[1][1] + law.effets.rel;
+  tableIndicators[2][1] = tableIndicators[2][1] + law.effets.eco;
+  tableIndicators[3][1] = tableIndicators[3][1] + law.effets.nob;
+  tableIndicators[4][1] = tableIndicators[4][1] + law.effets.peu;
+}
+
+function updateIndicatorsRemoveLaws(law) {
+  tableIndicators[0][1] = tableIndicators[0][1] - law.effets.cri;
+  tableIndicators[1][1] = tableIndicators[1][1] - law.effets.rel;
+  tableIndicators[2][1] = tableIndicators[2][1] - law.effets.eco;
+  tableIndicators[3][1] = tableIndicators[3][1] - law.effets.nob;
+  tableIndicators[4][1] = tableIndicators[4][1] - law.effets.peu;
+}
+
+function updateIndicatorsUpgradeLaws(law) {
+  tableIndicators[0][1] = tableIndicators[0][1] + law.effets.cri;
+  tableIndicators[1][1] = tableIndicators[1][1] + law.effets.rel;
+  tableIndicators[2][1] = tableIndicators[2][1] + law.effets.eco;
+  tableIndicators[3][1] = tableIndicators[3][1] + law.effets.nob;
+  tableIndicators[4][1] = tableIndicators[4][1] + law.effets.peu;
+}

+ 41 - 0
jeu.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang="fr">
+  <head>
+    <meta charset="utf-8">
+    <title>Home</title>
+    <link rel="stylesheet" type="text/css" href="css/style.css">
+  </head>
+  <body>
+
+    <div id="indicator">
+
+    </div>
+
+    <div id="main">
+
+      <div id="event">
+
+      </div>
+
+      <div id="options">
+
+      </div>
+
+    </div>
+
+    <div id="listLaws">
+
+    </div>
+
+  </body>
+</html>
+
+<script type="text/javascript" src="main.js"></script>
+<script type="text/javascript" src="laws.js"></script>
+<script type="text/javascript" src="lawsCTRL.js"></script>
+<script type="text/javascript" src="optionsCTRL.js"></script>
+<script type="text/javascript" src="indicatorCTRL.js"></script>
+<script type="text/javascript" src="events.js"></script>
+<script type="text/javascript" src="eventCTRL.js"></script>
+<script type="text/javascript" src="turn.js"></script>
+<script type="text/javascript" src="start.js"></script>

+ 58 - 0
laws.js

@@ -0,0 +1,58 @@
+const laws = [
+    {
+        "id": 0,
+        "nom": "Loi financement culte",
+        "descriptions": [
+            "Les lieux de culte sont financés à 1/3 par l'Etat",
+            "Les lieux de culte sont financés à moitié par l'Etat",
+            "Les lieux de culte sont entièrement financés par l'Etat"
+        ],
+        "effets": {"cri": 0, "rel": 5, "eco": -5, "nob": 0, "peu": 0},
+        "niveau": 0
+    },
+    {
+        "id": 1,
+        "nom": "Impôt sur le blé",
+        "descriptions": [
+            "Taxe de 3%",
+            "Taxe de 6%",
+            "Taxe de 9%"
+        ],
+        "effets": {"cri": 1, "rel": 0, "eco": 3, "nob": 1, "peu": -2},
+        "niveau": 0
+    },
+    {
+        "id": 2,
+        "nom": "Impôt sur le titre",
+        "descriptions": [
+            "Les nobles paient 3% d'impôts",
+            "Les nobles paient 6% d'impôts",
+            "Les nobles paient 9% d'impôts"
+
+        ],
+        "effets": {"cri":0, "rel": 0, "eco": 3, "nob": -2, "peu": 1},
+        "niveau": 0
+    },
+    {
+        "id": 3,
+        "nom": "Liberté d'expression",
+        "descriptions": [
+            "Abolition peine de mort pour les dissidents",
+            "Plus de prison pour les dissidents",
+            "Les gens peuvent dire ce qu'ils veulent"
+        ],
+        "effets": {"cri": -1, "rel": -5, "eco": 0, "nob": 1, "peu": 3},
+        "niveau": 0
+    },
+    {
+        "id": 4,
+        "nom": "Légalisation de la mandragore",
+        "descriptions": [
+            "Dépénalisation de la consommation",
+            "Légalisation de la consommation",
+            "Organisation de la consommation par l'Etat"
+        ],
+        "effets": {"cri": -2, "rel": -2, "eco": 1, "nob": 0, "peu": 1},
+        "niveau": 0
+    }
+]

+ 131 - 0
lawsCTRL.js

@@ -0,0 +1,131 @@
+/* c'est la table qui contient toutes les lois choisi par le joueur */
+
+var tableLaws = [];
+
+var tableEventsLaws = [];
+
+
+/* Lister les lois votee */
+
+function genListeTableLaws() {
+  let res = "";
+  for (var i = 0; i < tableLaws.length; i++) {
+    res = res + genTableLaw(tableLaws[i][0].id, tableLaws[i][1]);
+  }
+  return res;
+}
+
+function genTableLaw(lawID, lawLevel) {
+  return '<div><p>' + laws[lawID].nom + '</p><p>' + laws[lawID].descriptions[lawLevel] + "</p></div>";
+}
+
+function  genTableEventsLaw(eventID, id) {
+  return '<div><p>' + events[eventID].lois[id].nom + '</p><p>' + events[eventID].lois[id].descriptions[0] + "</p></div>";
+}
+
+/* id d'une loi non evenementiel au hazard */
+
+function randLaw(selectedLaws){
+  let found = false;
+  let id;
+  while (!found) {
+    if ((tableLaws.length + selectedLaws.length) >= laws.length) {
+      id = -1;
+      break;
+    }
+    id = randInt(0, laws.length - 1);
+    found = true;
+    for (var i = 0; i < selectedLaws.length; i++) {
+      if (selectedLaws[i].id == id) {
+          found = false;
+      }
+    }
+    for (var i = 0; i < tableLaws.length; i++) {
+      if (tableLaws[i][0].id == id) {
+          found = false;
+      }
+    }
+  }
+  return id;
+}
+
+const numberAddLaws = 3;
+
+function genListeAddLaws() {
+  console.log("genListeAddLaws");
+  let selectedLaws = [];
+  let res = "";
+  for (var i = 0; i < numberAddLaws; i++) {
+    let newLaw = randLaw(selectedLaws);
+    selectedLaws.push(laws[newLaw]);
+    if (newLaw > -1) {
+      res = res + genAddLaw(newLaw);
+    }
+  }
+  return res;
+}
+
+function genAddLaw(id){
+  return "<div onClick=\"addLaw(" + id + ")\"><p>" + laws[id].nom + '</p><p>' + laws[id].descriptions[0] + "</p></div>";
+}
+
+function addLaw(id){
+  tableLaws.unshift([laws[id], 0]);
+  updateIndicatorsAddLaws(laws[id]);
+  turnForward();
+}
+
+/* Ajouter une loi evenementiel */
+
+function genAddEventLaw(eventID, id){
+  return "<div onClick=\"addEventLaw(" + eventID + "," + id + ")\"><p>" + events[eventID].lois[id].nom + '</p><p>' + events[eventID].lois[id].descriptions[0] + "</p></div>";
+}
+
+function addEventLaw(eventID, id){
+  tableEventsLaws.unshift([eventID, id]);
+  updateIndicatorsAddLaws(events[eventID].lois[id]);
+  turnForward();
+}
+/* Supprimer une loi */
+
+function genListeRemoveLaws() {
+  let res = "";
+  for (var i = 0; i < tableLaws.length; i++) {
+    res = res + genRemoveLaw(tableLaws[i][0].id, tableLaws[i][1], i);
+  }
+  return res;
+}
+
+function genRemoveLaw(lawID, lawLevel, num) {
+  return '<div onClick=\"removeLaw('+ num + "," + lawID + ')\"><p>' + laws[lawID].nom + '</p><p>' + laws[lawID].descriptions[lawLevel] + "</p></div>";
+}
+
+function removeLaw(pos, lawID){
+  tableLaws.splice(pos, 1);
+  updateIndicatorsRemoveLaws(laws[lawID]);
+  turnForward()
+}
+
+/* Ameliorer une loi */
+
+function genListeUpgradeLaws() {
+  let res = "";
+  let num = 0;
+  for (var i = 0; i < tableLaws.length; i++) {
+    if (tableLaws[i][1] < 2) {
+      res = res + genUpgradeLaw(tableLaws[i][0].id, tableLaws[i][1], num);
+      num++;
+    }
+  }
+  return res;
+}
+
+function genUpgradeLaw(lawID, lawLevel, num) {
+  return "<div onClick=\"upgradeLaw(" + num + "," + lawID + ")\"><p>" + laws[lawID].nom + '</p><p>' + laws[lawID].descriptions[lawLevel] + "</p></div>";
+}
+
+function upgradeLaw(pos, lawID){
+  tableLaws[pos][1] = tableLaws[pos][1] + 1;
+  updateIndicatorsUpgradeLaws(laws[lawID]);
+  turnForward()
+}

+ 20 - 0
main.js

@@ -0,0 +1,20 @@
+/*
+ * randInt : obtient un entier aleatoire entre min et max
+ */
+function randInt(min, max) {
+    return Math.round(Math.random() * (max - min) ) + min;
+}
+
+function fin(tableIndicators, currentTurn) {
+  if (currentTurn > 10 ) {
+    document.body.innerHTML = '<p>Fin</p><p>Vous avez gagnez</p><a href="jeu.html">Rejouer</a>';
+    return true;
+  }
+  for (var i = 0; i < tableIndicators.length; i++) {
+    if (tableIndicators[i][1] > 100 | tableIndicators[i][1] <= 0) {
+      document.body.innerHTML = '<p>Fin</p><p>Vous avez Perdu</p><a href="jeu.html">Rejouer</a>';
+      return true;
+    }
+  }
+  return false;
+}

+ 59 - 0
optionsCTRL.js

@@ -0,0 +1,59 @@
+var tableOptions = [["Ajouter une nouvelle loi", false],["Améliorer une loi", false],["Supprimer une loi", false]];
+
+function chooseOption(id) {
+  let listLaws = document.querySelector("#listLaws");
+  listLaws.innerHTML = genListeTableLaws();
+  switch (id) {
+    case 0:
+      listLaws.innerHTML = genListeAddLaws();
+      break;
+    case 1:
+      listLaws.innerHTML = genListeUpgradeLaws();
+      break;
+    case 2:
+      listLaws.innerHTML = genListeRemoveLaws();
+      break;
+    default:
+      listLaws.innerHTML = genListeTableLaws();
+  }
+  enableOption(id);
+}
+
+function genListeOptions(newEventId) {
+  console.log(newEventId);
+  let element = document.querySelector("#options");
+  let res = "";
+  if (newEventId == -1) {
+    for (var i = 0; i < tableOptions.length; i++) {
+        res = res + genOption(i);
+      }
+    element.innerHTML = res;
+    console.log(newEventId);
+  }
+  else {
+    console.log("ca marche2");
+    element.innerHTML = genAddEventLaw(newEventId, 0) + genAddEventLaw(newEventId, 1);
+  }
+}
+
+function enableOption(id) {
+  for (var i = 0; i < tableOptions.length; i++) {
+    if (i == id) {
+      tableOptions[i][1] = true;
+    }
+    else {
+      tableOptions[i][1] = false;
+    }
+  }
+  genListeOptions();
+}
+
+function resetOptions() {
+  for (var i = 0; i < tableOptions.length; i++) {
+    tableOptions[i][1] = false;
+  }
+}
+
+function genOption(id, newEventId) {
+  return "<p onClick=\"chooseOption(" + id + ")\">" + tableOptions[id][0] + "</p>";
+}

+ 6 - 0
start.js

@@ -0,0 +1,6 @@
+tableIndicators[0][1] = 30;
+tableIndicators[1][1] = 30;
+tableIndicators[2][1] = 30;
+tableIndicators[3][1] = 30;
+tableIndicators[4][1] = 30;
+turnForward();

+ 12 - 0
style.css

@@ -0,0 +1,12 @@
+body {
+	display: flex;
+}
+
+.flexRow {
+	display: flex;
+	flex-direction: row;
+}
+
+#topNavBar {
+	
+}

+ 28 - 0
turn.js

@@ -0,0 +1,28 @@
+/* liste des evenement deja produits */
+
+var usedEvents = [];
+
+/* fonction qui lance un tour */
+
+function turnForward() {
+  let isFin = fin(tableIndicators, currentTurn);
+  if (!isFin) {
+    let newEventId = randEvent();
+    if (newEventId == -1) {
+        genNoEvent();
+        // generation d'une simple liste des lois
+        document.querySelector("#listLaws").innerHTML = genListeTableLaws();
+    }
+    else {
+        console.log("test");
+        document.querySelector("#listLaws").innerHTML = "";
+        displayEvent(newEventId);
+        usedEvents.unshift(newEventId);
+    }
+    genAllIndicators();
+    resetOptions();
+    genListeOptions(newEventId);
+    currentTurn = currentTurn + 1;
+
+  }
+}