I'm writing a small little program using Borland Turbo C++ 3.0 for dos, everything in its current state works fine, basically I have the program load, and at some point a user can hit L to bring up the SNIP 2 part, where they are brought up with a list of choices, these choices are actual files that are set to open when they pick it. Right now I have 1 to 10(0).
I load the program, I hit open 1, and it loads my barrens.zon file, draws it to the screen, looks great. I can hit L again to bring up my load screen and pick option 2, it loads the duskwood.zon file, draws it, everything fine.
Now my question is this, I currently have the program hardcoded with each file I want to use, which atm is about 10, but i'd like add more and not have to modify the program each time. Ultimately I'd like it to read one central index file that I could modify, and have the program then read that file, and put out a menu based on that file, with cases for the switch command, and also load the proper file, I have no idea how to do something like that so figured I'd post and see if anyone had any examples or help they could assist me with.
Heres some samples of the code I'm using, I know its messy, I haven't "seriously" coded in probably 4-5 yrs and this is just something I'm playing with, can probably tell from the mix of C and C++.
Code:
#define MAPFILE "barrens.zon"
#define MAPFILE2 "duskwood.zon"
Code:
cprintf(" 1 - The Barrens");
cprintf(" 2 - Duskwood");
choose = getch();
choose = tolower(choose);
switch (choose)
{
case 'q': break;
case '1': zone =1; read_map(); break;
case '2': zone =2; read_map(); break;
Code:
void read_map(void)
{
ifstream gamemap;
if(zone == 1)
gamemap.open(MAPFILE);
else if (zone == 2)
gamemap.open(MAPFILE2);
else if (zone == 3)
gamemap.open(MAPFILE3);
else if (zone == 4)
gamemap.open(MAPFILE4);
else if (zone == 5)
gamemap.open(MAPFILE5);
else if (zone == 6)
gamemap.open(MAPFILE6);
else if (zone == 7)
gamemap.open(MAPFILE7);
else if (zone == 8)
gamemap.open(MAPFILE8);
else if (zone == 9)
gamemap.open(MAPFILE9);
else if (zone == 10)
gamemap.open(MAPFILE10);
if(gamemap.fail())
{
cerr<<endl<<"***** Error Opening BARRENS.ZON *****"<<endl;
kbhit();
}
gamemap.getline(mapfile.zonename,20);
gamemap.getline(mapfile.mapline_x1,80);
gamemap.getline(mapfile.mapline_x2,80);
gamemap.getline(mapfile.mapline_x3,80);
gamemap.getline(mapfile.mapline_x4,80);
gamemap.getline(mapfile.mapline_x5,80);
gamemap.getline(mapfile.mapline_x6,80);
gamemap.getline(mapfile.mapline_x7,80);
gamemap.getline(mapfile.mapline_x8,80);
gamemap.getline(mapfile.mapline_x9,80);
gamemap.getline(mapfile.mapline_x10,80);
gamemap.getline(mapfile.mapline_x11,80);
gamemap.getline(mapfile.mapline_x12,80);
gamemap.getline(mapfile.mapline_x13,80);
gamemap.getline(mapfile.mapline_x14,80);
gamemap.getline(mapfile.mapline_x15,80);
gamemap.getline(mapfile.mapline_x16,80);
gamemap.getline(mapfile.mapline_x17,80);
gamemap.getline(mapfile.mapline_x18,80);
gamemap.getline(mapfile.mapline_x19,80);
gamemap.getline(mapfile.mapline_x20,80);
gamemap.getline(mapfile.mapline_x21,80);
gamemap.getline(mapfile.mapline_x22,80);
gamemap.getline(mapfile.mapline_x23,80);
gamemap.getline(mapfile.mapline_x24,80);
gamemap.getline(mapfile.mapline_x25,80);
gamemap.close();
return;
}