|
|
@@ -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()
|
|
|
+}
|