Thread: Static side of charcter wall

  1. #1

    Static side of charcter wall

    I think I asked somethign similar to this before but i haven't figured it out yet.

    I made a nice little menu(well... i think so) for my game and in the message section it displays last monster fought money gained and skill gained but when it displays the name it moves part of the wall so it doesn't look like a normal box any more.

    Is there anyway to make it static so it doesn't move when the text within gets too big?

    Code:
    cout<<"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
    cout<<endl;
    cout<<"ºNAME:"<<user.name<<"       ºLVL:"<<user.skill<<"     ºMESSAGES:                             º";
    cout<<endl;
    cout<<"ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹";
    cout<<endl;
    cout<<"º                º          º"<<"LAST FIGHT:"<<m.monname<<"                           º";
    cout<<endl;
    cout<<"º                º          º                                      º";
    cout<<endl; 
    cout<<"º                º          º                                      º";
    cout<<endl;
    cout<<"º                º          º                                      º";
    cout<<endl;
    cout<<"º                º          º                                      º";
    cout<<endl;
    cout<<"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";

  2. #2
    Registered User Nippashish's Avatar
    Join Date
    Sep 2002
    Posts
    34
    Well, I found a rather ugly solution to your problem, there's probably a better, more readable, way though.

    However, it should do what you want, the boxes will stay the same size as long as there is enough room in them for the text you try and put there. (If you try and put more chars then the box has room for it will screw up the formating).

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    #define WIDTH(w, info) cout << setw(w) << setfill(' ') << setiosflags(ios::left) << info
    
    void printMenu(char *playerName, int playerLevel, char *lastFight, char *message);
    
    int main()
    {
    	printMenu("Bob", 50, "The Monster", "This is a message");
    	return 0;
    }
    
    void printMenu(char *playerName, int playerLevel, char *lastFight, char *message)
    {
    
    	cout << " ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»" << endl;	// top line
    	cout << " ºNAME:"; WIDTH(11, playerName); cout << "º";	// 'name' box
    	cout << "LVL:"; WIDTH(6, playerLevel); cout << "º";	// 'level' box
    	cout << "MESSAGES:"; WIDTH(29, message); cout << "º" << endl;	// 'message' box
    	cout << " ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹" << endl;	// dividing line
    	WIDTH(18, " º"); WIDTH(11, "º"); cout << "ºLAST FIGHT:"; WIDTH(27, lastFight); cout << "º" << endl;	// 'last fight' box
    	WIDTH(18, " º"); WIDTH(11, "º"); WIDTH(39, "º"); cout << "º" <<endl;	// empty space
    	WIDTH(18, " º"); WIDTH(11, "º"); WIDTH(39, "º"); cout << "º" <<endl;	// empty space
    	WIDTH(18, " º"); WIDTH(11, "º"); WIDTH(39, "º"); cout << "º" <<endl;	// empty space
    	WIDTH(18, " º"); WIDTH(11, "º"); WIDTH(39, "º"); cout << "º" <<endl;	// empty space
    	cout << " ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ" << endl;	// bottom line
    }
    I tried to keep one line of printed text on one line of code. The WIDTH macro is there to keep the lines from becoming insanely long.

    On the bright side though, you never actualy have to touch that code unless you want to change the way the menu is built, you can just call the 'printMenu' function.
    Last edited by Nippashish; 12-15-2002 at 11:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 04:03 PM