Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created September 26, 2013 02:52
Show Gist options
  • Select an option

  • Save jmcph4/6709264 to your computer and use it in GitHub Desktop.

Select an option

Save jmcph4/6709264 to your computer and use it in GitHub Desktop.
A very simple program which shows the evolution of a village. Just use Excel, it's better.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define POPULATION_DENSITY 10
#define GAME_LENGTH 10
class village
{
public:
string name; // village name
int population; // village population
float size; // village size in sqkm
int x; // village centre's x-coordinate
int y; // village centre's y-coordinate
int step; // turn number
village()
{
this->name = "The Compound";
this->population = 10;
this->size = this->population / POPULATION_DENSITY;
this->x = 0;
this->y = 0;
this->step = 0;
this->growth = 0.10;
}
int update(void)
{
this->updatePopulation();
this->updateSize();
this->addStep();
return this->step;
}
private:
float growth; // village growth rate
void updatePopulation(void)
{
this->population = this->population + (this->population * this->growth);
}
void updateSize(void)
{
this->size = this->population / POPULATION_DENSITY;
}
void addStep(void)
{
this->step = this->step++;
}
};
int main(void)
{
village VILLAGE;
int i = 0;
for(i = 0;i <= GAME_LENGTH;i++)
{
cout<<VILLAGE.name<<":"<<endl;
cout<<"----------Year "<<VILLAGE.step<<"----------"<<endl;
cout<<"Population: "<<VILLAGE.population<<endl;
cout<<"Land Area: "<<VILLAGE.size<<"sqkm"<<endl<<endl;
VILLAGE.update();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment