Thread: Specific Character Text Color

  1. #1
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050

    Specific Character Text Color

    I know how to change text color for statements and such, but is there a way you can have a spefic character be the same color through out your whole program? For example, I want 'X' to be BROWN throughout the whole entire program. The reason why I don't just set the text color everytime X is to be displayed is becuase it is uncertain when 'X' will be shown. Another example is that I want '*' to be YELLOW throughout the whole program, because that is the 'player' in the game. The 'player' moves are represented by a '*' character. I want the '*' to be YELLOW, but it would be very difficult (if not impossible?) to change the text color of the '*' because of how the player moves. The compiler I use is DevC++beta4.9.2, and I hope I've explaine my problem well enough that somebody can help me.



    I accidentally posted this thread in the C forum the first time...sorry to those that noticed

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    are you using he command prompt?

    >I accidentally posted this thread in the C forum the first time...sorry to those that noticed

    you can delete posts!

    edit it the click the delete checkbox and submit it.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Why not create your own class that you can use for output? Or even a function. You'd have to write it all out once, but afterwards you could use it like coloredTextOut("Hi please color me!");

    Inside the function you'd parse the string and do whatever you need to do the string, then call cout on it. You could re-use this function if you planned ahead and structured it to be easily adaptable to different situations.

  4. #4
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Thanks, that is exactly how I'll do it. Plus the way I've structured my program it will be very easy to implement it.

    And I'll go delete that thread right now, too.

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Well, nevermind this became a lot more difficult than I had predicted. I'm completely stuck on this one. I've been trying to think of many ways to implement this but none of them seem to work. The problem is that I need an array to do a certain function (changing the color of the text and outputting the text) but of course that doesn't work.

    Here is some of the code in my program for you to get an idea of what I'm trying to do.

    Code:
    void main()
    {
    
    Display()     /*displays grid without any markings
    ReDisplay()     puts the mared grid inside of the unmarked grid
                           basically it's to prevent flickering when user enters
                           fast */
    
    /*here is a few sample lines of ReDisplay() */
    
    
    Gotoxy_1();
          cout << " " << d_maze[0][0] << " " << d_maze[0][1] << " " << d_maze[0][2] << " "  << d_maze[0][3] << " " << d_maze[0][4] << " " << d_maze[0][5]
               << " " << d_maze[0][6] << " " << d_maze[0][7] << " " << d_maze[0][8] << " "  << d_maze[0][9] << " " << d_maze[0][10] << " " << d_maze[0][11];
    
    
    input()  //the user moves around the maze with a ' * '
    
    change() /* implementing the new marks in ReDisplay()
                       more of the maze is uncovered by the move of the
                       player so more ' X 's need to be shown and the ' * '
                       needs to be moved to it's new spot */
    /*this is a sample of the code for change()*/
    
    
    void show_1_0()
    {
    	d_maze[1][0] = '*';
    	d_maze[0][0] = ' ';
    	d_maze[0][1] = ' ';
                   d_maze[1][1] = 'X';
                   d_maze[2][0] = ' ';
                   d_maze[2][1] = ' ';
    }
    
    
    Putting_change() /* this is for deciding what should be marked in 
                                     ReDisplay() by looking at what change()  
                                     function should be put into ReDisplay() */
    
    /* here is a sample of Putting_change() */
    
    if(d_maze[1][0] == '*' && var_1 == 1)
           {
            do
             {
               if(move == 72)
                 {
                   show_0_0();
    	var_1 = 0;
                   break;
                  }
                if(move == 80)
                 {
                   show_2_0();
                   var_1 = 0;
                   break;
    	}
    	else
    	{
    	var_1 = 0;
    	break;
    	}
              }while(var_1 == 1);
            }
    
    
    Repeat() /* this is looping the program over again */
    
    }
    Sorry for the poor explaing of the program....I wasn't exactly sure on how to explain the program while showing you some code and keeping the code in pseudo. What I need is for whenever an X is shown I need it to be in a different color from the rest of what is displayed. Here is how I change colors > SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);

    Actually enough I think I might have figured out a way to do what I want to do. Either way, though, I'm still going to post this just in case I'm wrong.

  6. #6
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Yup, I found a way to do it. I guess all I needed to do was write things down and that would make things clearer for me lol. It doesn't matter to me, though, I got what I wanted out of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change text color in C
    By IndioDoido in forum C Programming
    Replies: 9
    Last Post: 04-15-2007, 05:54 AM
  2. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  3. MFC: Change the color of static text with button press?
    By BrianK in forum Windows Programming
    Replies: 2
    Last Post: 06-16-2004, 11:03 PM
  4. Text editor with font color
    By KingoftheWorld in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-15-2003, 01:45 PM
  5. Text Color
    By I Like Red in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2002, 05:33 PM