Sépération du code
This commit is contained in:
84
javascript/plStat.js
Normal file
84
javascript/plStat.js
Normal file
@@ -0,0 +1,84 @@
|
||||
exports.planetType = {
|
||||
"Tempérée" : {
|
||||
"population" : 100
|
||||
},
|
||||
"Glacée" : {
|
||||
"population" : 1
|
||||
},
|
||||
"Volcanique" : {
|
||||
"population" : 2
|
||||
},
|
||||
"Marécageuse" : {
|
||||
"population" : 10
|
||||
},
|
||||
"Forestière" : {
|
||||
"population" : 20
|
||||
},
|
||||
"Océanique" : {
|
||||
"population" : 25
|
||||
},
|
||||
"Oecuménopole" : {
|
||||
"population" : 2000
|
||||
},
|
||||
"Désert" : {
|
||||
"population" : 50
|
||||
},
|
||||
"Minéralogique" : {
|
||||
"population" : 3
|
||||
},
|
||||
"Gazeuse" : {
|
||||
"population" : 1
|
||||
},
|
||||
"Acide" : {
|
||||
"population" : 1
|
||||
},
|
||||
"Monde usine" : {
|
||||
"population" : 500
|
||||
}
|
||||
};
|
||||
|
||||
exports.planetPopulationType = [
|
||||
"Humains",
|
||||
"Presqu'humains",
|
||||
"Animaux pacifiques",
|
||||
"Animaux belliqueux",
|
||||
"Aliens"
|
||||
];
|
||||
|
||||
exports.planetNamePrefix = [
|
||||
"Acod", "Acht",
|
||||
"Bex",
|
||||
"Carob",
|
||||
"Daris",
|
||||
"Ecop",
|
||||
"Fron",
|
||||
"Glac", "Glad",
|
||||
"Hac", "Hor",
|
||||
"Is",
|
||||
"Jud",
|
||||
"Kor",
|
||||
"Ler",
|
||||
"Marel",
|
||||
"Naur",
|
||||
"Olep",
|
||||
"Prid", "Plex",
|
||||
"Qef",
|
||||
"Rem",
|
||||
"Sarit",
|
||||
"Thec", "Thex", "Thet",
|
||||
"Uv",
|
||||
"Volc", "Vold",
|
||||
"Wann",
|
||||
"Xal",
|
||||
"Yr",
|
||||
"Zot"
|
||||
];
|
||||
|
||||
exports.planetNameSuffix = [
|
||||
"a Minor", "a Major", "ant", "alor",
|
||||
"eri",
|
||||
"inia", "irid", "is",
|
||||
"o Zion", "or", "oria",
|
||||
"us", "us Prime", "us Secondus",
|
||||
"land", "yard"
|
||||
]
|
||||
37
javascript/planets.js
Normal file
37
javascript/planets.js
Normal file
@@ -0,0 +1,37 @@
|
||||
//import { planetPopulationType, planetNamePrefix, planetNameSuffix } from "./pl_stat.js";
|
||||
let stat = require("./plStat.js");
|
||||
|
||||
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)];
|
||||
}
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user