Transition JS complète

This commit is contained in:
gauvainboiche
2024-12-18 12:42:29 +01:00
parent 254a1a29e8
commit 5d16a681b0
2 changed files with 35 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
exports.planetType = {
"Tempérée" : {
"population" : 100,
"population" : 100
},
"Glacée" : {
"population" : 1

View File

@@ -1,6 +1,37 @@
//import { planetPopulationType, planetNamePrefix, planetNameSuffix } from "./pl_stat.js";
let pl_stat = require("./pl_stat.js");
let stat = require("./plStat.js");
console.log("Hey !");
const getRandomValue = (min, max) => {return Math.floor(Math.random() * (max - min + 1)) + min;}
const Random = (array) => {return array[Math.floor(Math.random() * array.length)];}
const RandomPlanet = (planet) => {
const keys = Object.keys(planet);
return keys[Math.floor(Math.random() * keys.length)];
}
console.log(pl_stat.planetPopulationType);
const GeneratePlanet = () => {
const planetTypeGeneration = RandomPlanet(stat.planetType);
const planetName = Random(stat.planetNamePrefix) + Random(stat.planetNameSuffix);
const planetPopulationPeople = Random(stat.planetPopulationType);
const planetPopulationNumber = stat.planetType[planetTypeGeneration]["population"] * getRandomValue(5, 15) / 10;
const planetDescription =
// Keep this formatting, or else play with the console.log of func PlanetLoop
(`
Planète : ${planetName}
Type : ${planetTypeGeneration}
Population :
${planetPopulationNumber} milliards
Majoritairement ${planetPopulationPeople}`);
return planetDescription;
}
const PlanetLoop = (number) => {
let count = 1;
while (count <= number) {
const planet = GeneratePlanet();
console.log(planet + `\n\n------------------------------`);
count++;
}
}
PlanetLoop(5);