Static side of charcter wall

This is a discussion on Static side of charcter wall within the C++ Programming forums, part of the General Programming Boards category; I think I asked somethign similar to this before but i haven't figured it out yet. I made a nice ...

  1. #1
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148

    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, 04:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21