I am currently working on a text based sim game. Win32 Console App to be exact. Here is the code I have so far (written in 1 hour so it's really just a skeleton or structure for what is to come):
Code:
#include <iostream.h>
#include <string.h>
int health;
int sleep;
int hunger;
int money;
char char_name[50];
void newgame();
int loadgame();
void game_initialize();
int exercise();
int sleeping();
int eat();
int work();
void stats();
int main()
{
int input;
cout<<"1. New Game"<<endl;
cout<<"2. Load Game"<<endl;
cout<<"3. Exit"<<endl;
cin>>input;
switch(input)
{
case 1: newgame();
break;
case 2: loadgame();
break;
case 3: return 0;
break;
}
}
void newgame()
{
cout<<"Please input your Simz's name:"<<endl;
cin>>char_name;
health=50;
sleep=50;
hunger=50;
money=50;
game_initialize();
}
int loadgame()
{
return 0;
}
void game_initialize()
{
int choice;
cout<<"Please select an action:"<<endl;
cout<<"1. Exercise"<<endl;
cout<<"2. Sleep"<<endl;
cout<<"3. Eat"<<endl;
cout<<"4. Work"<<endl;
cout<<"5. View Stats"<<endl;
cout<<"6. Exit to Main Menu"<<endl;
cin>>choice;
switch(choice)
{
case 1: exercise();
break;
case 2: sleeping();
break;
case 3: eat();
break;
case 4: work();
break;
case 5: stats();
break;
case 6: main();
break;
}
}
int exercise()
{
int minutes;
cout<<"How many minutes would you like to exercise for?"<<endl;
cout<<"(1 minute = +5 health, -2 sleep, -2 hunger, -1 dollars)"<<endl;
cin>>minutes;
health=health+(5*minutes);
sleep=sleep-(2*minutes);
hunger=hunger-(2*minutes);
money=money-minutes;
cout<<"You gained "<<5*minutes<<" health points, you lost "<<2*minutes<<" sleep points, you lost "<<2*minutes<<" hunger points, and you lost "<<minutes<<" dollars."<<endl;
if(health<0)
{
cout<<"You have died from sickness.";
return 0;
}
else if(sleep<0)
{
cout<<"You have died from sleep deprivation.";
return 0;
}
else if(hunger<0)
{
cout<<"You have died from starvation.";
return 0;
}
else if(money<0)
{
cout<<"You went broke!";
return 0;
}
game_initialize();
}
int sleeping()
{
int hours;
cout<<"For how many hours would you like to sleep?"<<endl;
cout<<"(1 hour = +1 health, +5 sleep, -2 hunger)"<<endl;
cin>>hours;
health=health+hours;
sleep=sleep+(5*hours);
hunger=hunger-(2*hours);
cout<<"You gained "<<hours<<" health points, you gained "<<5*hours<<" sleep points, and lost"<<2*hours<<" hunger points."<<endl;
if(health<0)
{
cout<<"You have died from sickness.";
return 0;
}
else if(sleep<0)
{
cout<<"You have died from sleep deprivation.";
return 0;
}
else if(hunger<0)
{
cout<<"You have died from starvation.";
return 0;
}
else if(money<0)
{
cout<<"You went broke!";
return 0;
}
game_initialize();
}
int eat()
{
int lbs;
cout<<"How many lbs. of food do you want to eat?"<<endl;
cout<<"(1 lb. = +1 health, -1 sleep, +5 hunger, -10 dollars)"<<endl;
cin>>lbs;
health=health+lbs;
sleep=sleep-lbs;
hunger=hunger+(5*lbs);
money=money-(10*lbs);
cout<<"You gained "<<lbs<<" health points, you lost "<<lbs<<" sleep points, you gained "<<5*lbs<<" hunger points, and you lost "<<10*lbs<<" dollars."<<endl;
if(health<0)
{
cout<<"You have died from sickness.";
return 0;
}
else if(sleep<0)
{
cout<<"You have died from sleep deprivation.";
return 0;
}
else if(hunger<0)
{
cout<<"You have died from starvation.";
return 0;
}
else if(money<0)
{
cout<<"You went broke!";
return 0;
}
game_initialize();
}
int work()
{
int work_hours;
cout<<"How many hours would you like to work?"<<endl;
cout<<"(1 hour = -2 health, -2 sleep, -2 hunger, +10 dollars)"<<endl;
cin>>work_hours;
health=health-(2*work_hours);
sleep=sleep-(2*work_hours);
hunger=hunger-(2*work_hours);
money=money+(10*work_hours);
cout<<"You lost "<<2*work_hours<<" health points, you lost "<<2*work_hours<<" sleep points, you lost "<<2*work_hours<<" hunger points, and you gained "<<10*work_hours<<" dollars."<<endl;
if(health<0)
{
cout<<"You have died from sickness.";
return 0;
}
else if(sleep<0)
{
cout<<"You have died from sleep deprivation.";
return 0;
}
else if(hunger<0)
{
cout<<"You have died from starvation.";
return 0;
}
else if(money<0)
{
cout<<"You went broke!";
return 0;
}
game_initialize();
}
void stats()
{
cout<<char_name<<" STATS:"<<endl;
cout<<"Health: "<<health<<endl;
cout<<"Sleep: "<<sleep<<endl;
cout<<"Hunger: "<<hunger<<endl;
cout<<"Dollars: "<<money<<endl;
game_initialize();
}
I am planing on upgrading the program to have job classes, job upgradablility, personal item inventory, housing, friend NPC's, and go knows what else. Stay tuned! If you have any comments or suggestions please post em!