Thanks! Glad to know I figured it out on my own.
Heres another snippet for you guys to look at.
This one prints a box around the name of the room in my game. It will eventually be modified to display the room desc, the typical north, south, east, ect, current mobs in the area, ect. It calculates the "middle" of a string and places it in the "middle" of an 80 character box of stars.
I doubt it's the most efficient way of going about it, but I'm just curious if I'm on the right track to solving my various programming problems, or if I'm still including a lot of "Fluff" in my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
[
/**
Places the room name inside of a bar, and places the string in the middle.
@param curr_room = The Input of the room_name from an array in the room class.
@param length_variable = during runtime allows for an extra space to be added to the second
line of " " characters to ensure the edges line up properly.
*/
void Player_Interface::display_room(string curr_room, int length_variable)
{
int room_length; //length of room name
int half_room_length; //half of room name
const int HALF = 2; // Eliminates magic number of 2
const int IN_OUT_STAR = 2; //Accounts for stars on outer edges of display
const int STAR_LENGTH = (80 - IN_OUT_STAR);// width of display box minus the inner and outer stars
int first_space_print; // how many spaces to print before string
room_length = curr_room.length(); //calculates length of string
half_room_length = room_length / HALF; //calculates midpoint of string
first_space_print = (STAR_LENGTH / HALF) - half_room_length; // calculates
//how many spaces to
// print before printing string
int remainder = STAR_LENGTH - first_space_print - room_length - length_variable;
// How many spaces to print after string
cout << "*******************************************************************************" << endl;
cout << "*";
for (int i = 0; i < first_space_print; i++)
{
cout << " ";
}
cout << curr_room;
for (int x = 0; x < remainder; x++)
{
cout << " ";
}
cout << "*" << endl;
cout << "*******************************************************************************" << endl;
}
|
My longterm goal is to be able to program my own mudcode base, but I know I've got a lot to learn until then, but if you know of any good resources/tutorials for the design process of text based RPG's that would be awesome as well. I still have troubles deciding where to include my attack function, do I put it in with my character, the monsters, a seperate combat class, does it even matter, and I would love to find some resources of such to look into.
Thanks much!