Explorar o código

Implémentation des fonctionnalités, en repartant un peu depuis le début

Nathanael Klapczynski %!s(int64=6) %!d(string=hai) anos
pai
achega
d5da81831a
Modificáronse 10 ficheiros con 560 adicións e 0 borrados
  1. 37 0
      eventCTRL.js
  2. 114 0
      events.js
  3. 56 0
      indicatorCTRL.js
  4. 40 0
      jeu.html
  5. 58 0
      laws.js
  6. 150 0
      lawsCTRL.js
  7. 20 0
      main.js
  8. 53 0
      optionsCTRL.js
  9. 6 0
      start.js
  10. 26 0
      turn.js

+ 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>";
+}

+ 114 - 0
events.js

@@ -0,0 +1,114 @@
+const events = [
+    {
+        "nom" : "nomEvenement1",
+        "description" : "descEvenement1",
+        "lois" : [
+            {
+                "id": 0,
+                "nom": "Evenement1loi1",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            },
+            {
+                "id": 1,
+                "nom": "Evenement1loi2",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": -100, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            }
+        ]
+    },
+    {
+        "nom" : "nomEvenement2",
+        "description" : "descEvenement2",
+        "lois" : [
+            {
+                "id": 0,
+                "nom": "Evenement2loi1",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": +100, "nob": 0, "peu": 0},
+                "niveau": 0
+            },
+            {
+                "id": 1,
+                "nom": "Evenement2loi2",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            }
+        ]
+    },
+    {
+        "nom" : "nomEvenement3",
+        "description" : "descEvenement3",
+        "lois" : [
+            {
+                "id": 0,
+                "nom": "Evenement3loi1",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            },
+            {
+                "id": 1,
+                "nom": "Evenement3loi2",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            }
+        ]
+    },
+    {
+        "nom" : "nomEvenement4",
+        "description" : "descEvenement4",
+        "lois" : [
+            {
+                "id": 0,
+                "nom": "Evenement4loi1",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            },
+            {
+                "id": 1,
+                "nom": "Evenement4loi2",
+                "descriptions": [
+                    "desc1",
+                    "desc2",
+                    "desc3"
+                ],
+                "effets": {"cri": 0, "rel": 0, "eco": 0, "nob": 0, "peu": 0},
+                "niveau": 0
+            }
+        ]
+    }
+]

+ 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;
+}

+ 40 - 0
jeu.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="fr">
+  <head>
+    <meta charset="utf-8">
+    <title>Home</title>
+  </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
+    }
+]

+ 150 - 0
lawsCTRL.js

@@ -0,0 +1,150 @@
+/* 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]);
+  }
+  for (var i = 0; i < tableEventsLaws.length; i++) {
+    res = res + genTableEventsLaw(tableEventsLaws[i][0], tableEventsLaws[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;
+}
+
+/* Ajouter une loi non evenementiel */
+
+function displayAddLaws(newEventId){
+  let res = "";
+
+
+  console.log(newEventId);
+  console.log("bon");
+  if (newEventId == -1) {
+    res = genListeAddLaws();
+  }
+  else {
+    res = genAddEventLaw(newEventId, 0) + genAddEventLaw(newEventId, 1);
+  }
+  return res;
+}
+
+const numberAddLaws = 3;
+
+function 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;
+}

+ 53 - 0
optionsCTRL.js

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

+ 26 - 0
turn.js

@@ -0,0 +1,26 @@
+/* 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();
+    }
+    else {
+      displayEvent(newEventId);
+        usedEvents.unshift(newEventId);
+      }
+    genAllIndicators();
+    resetOptions();
+    genListeOptions(newEventId);
+    // generation d'une simple liste des lois
+    document.querySelector("#listLaws").innerHTML = genListeTableLaws();
+    currentTurn = currentTurn + 1;
+
+  }
+}