Last active
May 26, 2017 15:23
-
-
Save HoeenCoder/bf83a57b6fb68f0d5f79607f0a9e10ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Star System Generator | |
WIP, shows the general idea will fill in blanks as needed. | |
*/ | |
function generateSystem() { | |
var system = {}; | |
system.name = ''; // TODO generate a system name | |
system.planets = {}; | |
for (var i = 0; i < Math.floor(Math.random() * 5) + 4; i++) { // Generate 4 - 9 planets per system | |
var planet = ''; | |
do { | |
planet = genName(); | |
} while (planet in system.planets); // No two planets can have the same name whithin a system | |
system.planets[planet] = {name: planet}; | |
planet = system.planets[planet]; | |
// TODO: what resource, how much space, other atributes? (temprature ect) | |
} | |
// TODO: other atributes of a star system. (possibly space pirates) | |
return system; | |
} | |
function genName() { | |
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''); | |
var name = ''; | |
for (var i = 0; i < Math.floor(Math.random() * 3) + 3; i++) { | |
name += letters[Math.floor(Math.random() * letters.length)]; | |
} | |
name += "-"; | |
let num = Math.ceil(Math.random() * 999); | |
if (num < 10) { | |
name += "00" + num; | |
} else if (num < 100) { | |
name += "0" + num; | |
} else { | |
name += num; | |
} | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment