Code:
#include <conio.h>
#include <fstream.h>
#include <stdlib.h>
#include <time.h>
int create(char nme[100])
{
clrscr();
gotoxy(34,2);
cout << "STATS:" << endl;
cout << endl;
gotoxy(34,4);
cout << "NAME: " << nme;
gotoxy(34,5);
int lvl=1;
cout << "LEVEL: " << lvl << endl;
int hp=rand()%6;
hp=hp+10;
gotoxy(34,6);
cout << "HIT POINTS:" << hp << endl;
int at=rand()%5;
at=at+1;
gotoxy(34,7);
cout << "ARMOR: " << at << endl;
gotoxy(34,8);
int gp=0;
cout << "GOLD PIECES: " << gp << endl;
gotoxy(39,9);
getch();
return 0;
}
int load()
{
char nme[100];
int lvl;
int hp;
int at;
int gp;
int lp4=5;
while(lp4!=0)
{
if(lp4==5)
{
ifstream b_file("nme.txt");
b_file >> nme;
b_file.close();
}
else if(lp4==4)
{
ifstream b_file("lvl.txt");
b_file >> lvl;
b_file.close();
}
else if(lp4==3)
{
ifstream b_file("hp.txt");
b_file >> hp;
b_file.close();
}
else if(lp4==2)
{
ifstream b_file("at.txt");
b_file >> at;
b_file.close();
}
else if(lp4==1)
{
ifstream b_file("gp.txt");
b_file >> gp;
b_file.close();
}
lp4=lp4-1;
}
return 0;
}
int sleep(float secs)
{
clock_t delay = secs * CLOCKS_PER_SEC;
clock_t start = clock();
while (clock() - start < delay)
;
return 0;
}
int save(int hp,int lvl,int at,int gp,char nme[100])
{
int lp=5;
while(lp!=0)
{
if(lp==5)
{
ofstream a_file("nme.txt", ios::app);
a_file << nme;
a_file.close();
}
else if(lp==4)
{
ofstream a_file("lvl.txt", ios::app);
a_file << lvl;
a_file.close();
}
else if(lp==3)
{
ofstream a_file("hp.txt", ios::app);
a_file << hp;
a_file.close();
}
else if(lp==2)
{
ofstream a_file("at.txt", ios::app);
a_file << at;
a_file.close();
}
else if(lp==1)
{
ofstream a_file("gp.txt", ios::app);
a_file << gp;
a_file.close();
}
lp=lp-1;
}
return 0;
}
int tmdseq(float slpamt,char word[100])
{
int lp2=5;
while(lp2!=0)
{
clrscr();
gotoxy(34,12);
cout << word;
sleep(slpamt);
cout << ".";
sleep(slpamt);
cout << ".";
sleep(slpamt);
cout << "." << endl;
sleep(slpamt);
lp2=lp2-1;
}
return 0;
}
int main(void)
{
int lp3=1;
while(lp3!=0)
{
gotoxy(34,2);
cout << "Dungeon Explorer";
gotoxy(34,3);
cout << "Main Menu: ";
gotoxy(34,5);
cout << "1. New Game";
gotoxy(34,6);
cout << "2. Continue Game";
gotoxy(34,7);
char ch=getch();
if(ch=='1')
{
clrscr();
gotoxy(34,12);
char nme[100];
cout << "Name: ";
cin >> nme;
clrscr();
tmdseq(.50,"Creating");
create(nme);
lp3=0;
}
if(ch=='2')
{
clrscr();
tmdseq(.50,"Loading");
load();
lp3=0;
}
int lp5=1;
while(lp5!=0)
{
clrscr();
gotoxy(34,2);
cout << "Dungeon Explorer";
gotoxy(34,3);
cout << "Town Menu: ";
gotoxy(34,5);
cout << "1. Save";
gotoxy(34,6);
cout << "2. Stats";
gotoxy(34,7);
cout << "3. Quit";
char ch2=getch();
if(ch2=='1')
{
tmdseq(.50,"Saving");
save(hp,lvl,at,gp,nme);
}
if(ch2=='2')
{
clrscr();
gotoxy(34,2);
cout << "STATS:" << endl;
cout << endl;
gotoxy(34,4);
cout << "NAME: " << nme;
gotoxy(34,5);
cout << "LEVEL: " << lvl << endl;
gotoxy(34,6);
cout << "HIT POINTS:" << hp << endl;
gotoxy(34,7);
cout << "ARMOR: " << at << endl;
gotoxy(34,8);
cout << "GOLD PIECES: " << gp << endl;
gotoxy(34,9);
getch();
}
if(ch2=='3')
{
lp5=0;
}
}
}
return 0;
}