foeSure, Part 2

Dario Carlino
3 min readDec 3, 2021

Progress so Far

foeSure ended up becoming no just a foe generator but an NPC generator; why limit it to just making bad guys when it can serve for every generated character in the game?

It’s pretty much the same thing but with a friendly attribute, the other ones stay the same. Take a look,

foeSure attributes

I didn’t really focus on the css, I don’t care about that; I’m saving the front-end inspiration for the actual game where this module will fit

Anyways, now that the attributes are set I fleshed out the way to generate a character from 10 numbers.

The Numbers

kind of my inspiration for doing a 10 digit seed number

Attributes 1, 2, 3, 4, 6, 7, 8, 9 are pretty straight forward, you select as number and an attribute is automatically selected, for option 5 there’s a range, so selecting a number with select a random number within that range, here take look, much easier to explain with an image of code :)

How the number of items is picked, good ol’ switcharoo statement

You might be wondering, ‘but Dario, what is the randomInteger function’ and let me tell you it’s a life saver, because by passing it min and max values as arguments it will select a random number in between those values, take a look,

randomInteger

Super simple. Math.floor rounds up the number to a full integer, while Math.random randomizes the value in between the two numbers.

So by selecting a number of items, you’re really selecting a range for the randomizer to pick a number from.

Number 10 was a little trickier, it selects the name. So by selecting a number between 0 and 9 it will select a name with that many letters and it will select it based on sex. For now I only have a 3 names for each sex and each letter group, once this is implemented in The Game I’m going crazy with options

Here’s the constant housing the names,

and that constant is imported into the class component in Foe.js so that the generator can pick a name

It’s long and repetitive, not DRY at all but I just want to get it working before I optimize it.

The random() function works very similarly to the randomInteger() one, the difference is that it randomly selects an element in an names array.

So from the top, it checks if the sex is ‘Female’ or ‘Male’ with and IF statement, and then it proceeds with the switch statement, matching the number to the array containing the names with number of letters.

Conclusion

The generator is mostly complete, I just need to display the results on the front-end and clean up the code a bit, after that I’m going to begin preparations for The Game. Until next week! Peace Out!

--

--