Need critique and some help with my first prototype

Started by
1 comment, last by ninnghazad 8 years, 6 months ago

I'm a graphic/web designer with some front-end web development experience. I've always been interested in game design but never really knew where to start, or didn't think I was a good enough programmer to get anywhere. But I've been coding a lot more Javascript/jQuery this past year or so, and that experience has inspired me to go ahead and jump in with an idea I've been kicking around for a while.

The game is a political Strategy/RPG (roughly in the vein of Paradox's Clausewitz stuff). I won't go into too many details, but the backbone of the game is a simple simulation of a population of citizens (somewhat similar to the "pops" in Victoria II). The player indirectly affects the population's well-being by enacting political reforms that tug on some RNG modifiers.

For my first sort of proof-of-concept prototype, I've started by simulating the life of a single citizen. The math is a little oversimplified and not finely tuned yet, but already it achieves some pretty plausible results!

The simulation is here: http://dannymcgee.net/games/epluribusunum/p1.html (Instructions: Pretty self-explanatory, but the End Turn button advances time by 1 year. RealTime just auto-advances 1 year every second.)

And the source code is here: http://dannymcgee.net/games/epluribusunum/game.js

First, I'd love to get a general sort of critique of my code. I've read a few articles about OOP in Javascript, but I'm probably missing some opportunities for optimization or better organization, and my math is pretty sketchy.

Secondly, I'm not really clear on how to expand from here. The next logical step—I think—would be to scale up the number of citizens. For the sake of simplicity, let's say the sim starts with 12 citizens. When one dies, a new one is "born" to replace it. However, I haven't the foggiest idea how to implement something like that. Can anyone nudge me in the right direction? Linking to an article or video that covers what I would need to know would be a totally acceptable answer. I'm just not even sure what to search for.

Thanks!

Advertisement
Well I don't think you're missing that much in terms of organization at this point because there isn't much to organize yet! But, I think your next step is to extract everything related to a citizen into a class, something like:

//Forgive any syntax errors, my JS is rusty
function Citizen()
{
this.Age = 0;
this.Wealth = 0;
this.Education = 0;
}

Citizen.prototype.giveMoney = function(){...}
Citizen.prototype.giveEducation= function(){...}
Citizen.prototype.increaseAge = function(){...}

And then convert your current code to use an instance of this class:

var citizen1 = new Citizen();
...
citizen1.giveMoney();
citizen1.giveEducation();
citizen1.increaseAge();
...

Once you have it working with one citizen, using an instance of the class, you can then work on instantiating multiple citizens and displaying their values, or replacing a dead citizen with a new one.

EDIT: The type of class I showed here is probably the simplest form of OOP in JS. I suggest you use this style for a while and ignore the more complex ones such as Parasitic inheritance that you may have read about. Yes, most people prefer the more advanced ways of handling objects, but they tend to be a lot more complicated in implementation.

More citizens! And more variables. Then make up a rate at which citizens multiply based on some of those.

Also overall counters - how much wealth in population, avg age and so on.

Introduce factors that may have negative effects, like food, or the lack of it.

Think of relations between those factors, like a price for food.

Then introduce events that manipulate those factors for all or a subset of population.

Like a drought, reduces food, probably only for the poor.

Have a think about dunbar's number and its possible effects, as well as other demographics you can catch some ideas from.

Like relations between wealth and length of life, or age and income, or in how far the parents' status affects the offspring.

If your doing JS, maybe throw some nice graphs in there to see changes over time or other distributions.

This topic is closed to new replies.

Advertisement