I've removed all of the extra's I had in and exit conditions and funny messages and it is down to the bare bones code, still no joy.
Could any of you take a look at this and see what is going on? If there is a { or something missing it was missed when pasting the code in here. This runs and compiles on my system with no errors other than never being able to move to the correct room.
[edit]I just realized I am referencing the 'new room' incorrectly with the users 'movement input' but I am stumped still on how to transpose the input movement to the corresponding room ID/array element without kludging something hardcoded again. It's time for a break before my brain melts but I would love to see what you guys have to suggest for a possible fix.[/edit]
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
#define max_locations 5
#define max_directions 4
struct t_rooms {
int id_number;
char *roomname;
};
struct t_locationinfo
{
int location_id;
char *description;
t_rooms room_array[max_directions];
};
t_locationinfo main_locations[max_locations]=
{
{1, "At your ghetto crib, you see a sidewalk out front.", {
{2,"sidewalk"},
{0,""},
{0,""},
{0,""}},
},
{2, "Sidewalk, standing in front of yo crib. Places to go are back to yo crib, your car, smelly dumpster or the backlot.", {
{1,"apartment"},
{3,"dumpster"},
{4,"car"},
{5,"backlot"}}
},
{3, "At the smelly dumpster, you hear a bum jumping up and down inside. The sidwalk is to the south.",{
{2,"sidewalk"},
{0,""},
{0,""},
{0,""}},
},
{4, "Standing beside yo hooptie, what a nasty ride. You can go back to the sidewalk from here.",{
{2,"sidewalk"},
{0,""},
{0,""},
{0,""}},
},
{5, "The backlot, here is the vehicle graveyard at your apartments. You can go back to the sidewalk in front of yo crib.",{
{2,"sidewalk"},
{0,""},
{0,""},
{0,""}},
},
};
void paint_location(int location_index);
void paint_exits(int location_index);
void dot_progress();
int movement_input(int location_index, int movement_id);
int main(int argc, char *argv[])
{
char user_input = 'y';
//hard coded debug stage removed for clarity
// cout << endl<< endl << ("Exiting debug stage. ");
int location_index = 0;
int movement_id = 0;
system("cls");
while(location_index <= max_locations)
{
movement_id = 0;
paint_location(location_index);
paint_exits(location_index);
location_index= movement_input(location_index, movement_id);
}
//exit condition inactive for debugging
cout << endl << ("\nThank you for playing our game! So long, and thanks for all the fish.");
cout << endl << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
int movement_input(int location_index, int movement_id)
{
int temp=location_index;
int valid_exits = 0;
cout << endl << ("\nEnter the room number you would like to move to.");
cout << ("\nMove to room: ");
cin >> movement_id;
if(main_locations[location_index].room_array[movement_id].id_number > valid_exits)
{
cout << endl << ("\nThis is room number: ") << main_locations[location_index].room_array[movement_id].id_number;
cout << endl << ("\nThis is room name: ") << main_locations[location_index].room_array[movement_id].roomname;
cout << endl << endl;
system("pause");
return main_locations[location_index].room_array[movement_id].id_number;
}
else
{
cout << endl << ("\nThat is not a valid exit ID.");
return temp;
}
}
void paint_location(int location_index)
{
cout << endl << main_locations[location_index].description;
}
void paint_exits(int location_index)
{
if(main_locations[location_index].room_array[0].id_number > 0)
{
cout << endl << ("\nAvailable exits: ") << endl;
for(int direction_id=0;direction_id<4;direction_id++)
{
if(main_locations[location_index].room_array[direction_id].id_number > 0)
{
cout << endl;
cout << main_locations[location_index].room_array[direction_id].roomname << (", exit number: ");
cout << main_locations[location_index].room_array[direction_id].id_number;
}
}
}
else
{
cout << endl << ("I'm sorry but you are dead, you can't move if you dead");
}
return;
}
void dot_progress()
{
for(int i = 0;i < 5;i++)
{
for (int x = 0; x <= 10; x++) {
Sleep(300);
printf(".");
}
cout << ("\b");
cout << (" ");
for (int x = 0; x <= 10; x++)
{
Sleep(100);
int temp = 2;
while(temp>0)
{
cout << ("\b");
temp--;
}
cout << (" ");
}
cout << ("\b");
}
return;
}
This post has been edited by badjava: 12 January 2009 - 08:21 PM

New Topic/Question
Reply



MultiQuote




|