Thread: My color's are not working propertly =[

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    15

    Unhappy My color's are not working propertly =[

    The colors are wrong =/...can't find any solution..can anyone please help out ?? And if you need all my code, is in here [ Save and Load game....Issue. ] i just add the colors...

    Any help would be appreciated

    Functions.c
    Code:
    #include "config.h"
    #include "functions.h"
    #include "data.h"
    #include "constants.h"
    
    
    int empezar()
    {
    
    
         IniciarTablero(TableroJ1,AGUA); // Poner todas las casillas con el símbolo de agua (^).
         DibujarTablero(TableroJ1); // Dibujar el tablero.
    
    
       /* Colocar los barcos en las posiciones deseadas */
       strcpy(frase,"[Casillas del AirCraft Carrier (5 casillas)]\n");
       printf("%s",frase);
       PedirCasilla(AIRCRAFTCARRIER);
       strcpy(frase,"[Casillas del BattleShip (4 casillas)]\n\0");
       printf("%s",frase);
       PedirCasilla(BATTLESHIP);
       strcpy(frase,"[Casillas del Submarine (3 casillas)]\n");
       printf("%s",frase);
       PedirCasilla(SUBMARINE);
       strcpy(frase,"[Casillas del Cruiser (3 casillas)]\n");
       printf("%s",frase);
       PedirCasilla(CRUISER);
       strcpy(frase,"[Casillas del Destroyer (2 casillas)]\n");
       printf("%s",frase);
       PedirCasilla(DESTROYER);
       printf("     Su tablero ha sido creado.\n");
       Sleep(1000);
    
       system("cls");
       printf("Creando tablero de la maquina...");
       IniciarTablero(Aux,OCULTA); // Poner todas las casillas con el símobolo de casilla oculta(O).
       IniciarTableroJ2(); // Generar aleaoriamente el tablero del oponente.
       GenerarLista();
       system("cls");
       printf("\n\n\n\n\n\n                              Vamos al mambo!\n");
       Sleep(2000);
    
       /* Iniciar la batalla */
       while (1)
       {
          TurnoJ1(); // Turno del jugador
          if (tocadosJ1 == 17) // Si se han destruído todos los barcos
          {                // del oponente se gana y acaba el juego.
             system("cls");
             printf(" GANASTE\n");
             return 0;
          }
    
          TurnoJ2(); // Turno del oponente.
          if (tocadosJ1 == 17) // Si se han destruído todos los barcos
          {                // del jugador se pierde y acaba el juego.
             system("cls");
             printf(" PERDISTE\n");
             return 0;
          }
       }
    }
    
    
    
    /* Inicia el tablero */
    void IniciarTablero(char Tablero[10][10],char simbolo)
    {
       int i,j;
    
       for(i=0;i<10;i++)
       {
          for (j=0;j<10;j++)
             Tablero[i][j]=simbolo;
       }
    }
    
    /* Función que genera el tablero del oponente aleatoriamente */
    void IniciarTableroJ2()
    {
    
       Casilla aleatoria;
       char pos,posicion[2]={'v','h'};
       int i;
    
       IniciarTablero(TableroJ2,AGUA); // Primero se rellena el tablero con el símoblo de agua (^).
       srand(time(NULL));
       for (i=0;i<5;i++)
       {
          do
          {
             aleatoria.letra=(rand()%10)+65; // Casilla
             aleatoria.numero=(rand()%10)+1; // Random.
             pos=posicion[rand()%2]; // Posición Random.
          }while(!VerificarCasilla(TableroJ2,aleatoria,Barcos[i],pos)); // Verificar si la casilla es válida.
          Almacenar(TableroJ2,Barcos[i],aleatoria,pos); // Se almacena el barco en el tablero.
       }
    }
    
    
    /* Dibujar el tablero */
    
    #define ks_LONGITUD_X_CASILLA "   " //SON 3 ESPACIOS
    #define kc_LONGITUD_Y_CASILLA 2
    
    #define kc_MITAD_CANTIDAD_CASILLAS 5
    
    #define ki_FONDO_AZUL_LETRA_AZUL 17
    
    #define ki_FONDO_CYAN_LETRA_CYAN 51
    
    #define ki_FONDO_ROJO_VINO 69
    /*
    The different color codes are
    
    0   BLACK
    1   BLUE
    2   GREEN
    3   CYAN
    4   RED
    5   MAGENTA
    6   BROWN
    7   LIGHTGRAY
    8   DARKGRAY
    9   LIGHTBLUE
    10  LIGHTGREEN
    11  LIGHTCYAN
    12  LIGHTRED
    13  LIGHTMAGENTA
    14  YELLOW
    15  WHITE
    */
    
    void _MarcosLaterales(HANDLE  hConsole){
        SetConsoleTextAttribute(hConsole, ki_FONDO_ROJO_VINO);
        printf("   ");
    }
    
    
    void _MarcosLogitudinales(HANDLE  hConsole){
        int i;
        _MarcosLaterales(hConsole);
        for(i=0;i<kc_MITAD_CANTIDAD_CASILLAS*2;i++){
            printf(ks_LONGITUD_X_CASILLA);
        }
        _MarcosLaterales(hConsole);
    }
    
    
    void gotoxy2( int column, int line )
      {
      COORD coord;
      coord.X = column;
      coord.Y = line;
      SetConsoleCursorPosition(
        GetStdHandle( STD_OUTPUT_HANDLE ),
        coord
        );
      }
    
    void _ImprimirFichas(char Tablero[10][10]){
    
        HANDLE  hConsole;
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        int i,j;
        for(i=0;i<10;i++)
            for(j=0;j<10;j++){
                gotoxy2(4+j*3,21-i*kc_LONGITUD_Y_CASILLA);
                if(Tablero[j][i]=='0'){
                    SetConsoleTextAttribute(hConsole,ki_FONDO_CYAN_LETRA_CYAN);
                    printf("%c ",Tablero[j][i]);
                }else{
                    SetConsoleTextAttribute(hConsole,FONDO_ROJO_LETRA_ROJA);
                    printf("%c ",Tablero[j][i]);
    
                    //ki_FONDO_CYAN_LETRA_CYAN
                }
            }
    }
    
    
    
    
    void DibujarTablero(char Tablero[10][10])
    {
    
       int i,j,letra=65;
    
       system("cls");
    
    
        HANDLE  hConsole;
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        int k,L;
        gotoxy2(0,0);
        printf("BattleSHIP:\n\n");
    
        /**< Dibujando el Tablero */
        _MarcosLogitudinales( hConsole);
        printf("\n");
    
        for(k=0;k<kc_MITAD_CANTIDAD_CASILLAS*2;k++){
            for(i=0;i<kc_LONGITUD_Y_CASILLA;i++){
                _MarcosLaterales(hConsole);
                for(j=0;j<kc_MITAD_CANTIDAD_CASILLAS*2;j++){
                    SetConsoleTextAttribute(hConsole, ki_FONDO_CYAN_LETRA_CYAN);
                    printf(ks_LONGITUD_X_CASILLA);
                }
                _MarcosLaterales(hConsole);
                printf("\n");
            }
    
        }
    
        _MarcosLogitudinales( hConsole);
    
        printf("\n\n");
    
        SetConsoleTextAttribute(hConsole, FONDO_NEGRO_LETRA_GRIS);
    
    
        _ImprimirFichas(Tablero);
    
    //    printf("        1 2 3 4 5 6 7 8 9 10\n\n");
    //    for (i=0;i<10;i++,letra++)
    //    {
    //       printf("     %c  ",letra);
    //       for (j=0;j<10;j++)
    //         printf("%c ",Tablero[i][j]);
    //       printf("\n\n");
    //    }
    //    printf("%s",frase);
    
    gotoxy2(0,30);
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /* Función que pide una casilla a partir de la cual se introduce */
    /* un barco determinado en posición vertical u horizontal */
    void PedirCasilla(int barco)
    {
       Casilla cas;
       char posicion;
       int valida;
    
       do {
          valida=0;
          fflush(stdin);
          printf("Letra: ");
          scanf("%c",&cas.letra);
          cas.letra=toupper(cas.letra);
          if (cas.letra < 65 || cas.letra > 74) // Verificar si la letra pertenece al rango válido.
             valida++;
          printf("Numero: ");
          scanf("%d",&cas.numero);
          if (cas.numero < 1 || cas.numero > 10) // Verificar si el número pertenece al rango válido.
             valida++;
          printf("Vertical u horizontal (v/h): ");
          fflush(stdin);
          scanf("%c",&posicion);
          if (posicion != 'v' && posicion != 'h') // Verificar si la posición es válida.
             valida++;
          if (!VerificarCasilla(TableroJ1,cas,barco,posicion))
             valida++;
          if (valida > 0) // Si falla algún parámetro anterior
          {            // se muestra un mensaje de error.
             printf("Casilla no valida o posicion no valida\n");
             Sleep(1000);
          }
          DibujarTablero(TableroJ1);
       }while(valida > 0); // Se vuelven a pedir los parámetros hasta que sean correctos.
       Almacenar(TableroJ1,barco,cas,posicion); // Almacenar el barco en le tablero
       strcpy(frase,"\0");
       DibujarTablero(TableroJ1); // Dibujar el tablero
    }
    
    /* Función que verifica si la casilla inroducida es correcta */
    int VerificarCasilla(char Tablero[10][10],Casilla cas,int barco,char posicion)
    {
       int fila,columna,i,cont=0,tope;
    
       fila=cas.letra-65;
       columna=cas.numero-1;
       if (Tablero[fila][columna] != AGUA) // Si la casilla está ocupada.
          return 0;
       if (posicion == 'h') // Si la posición es horizontal, se verifica si
       {                // el barco cabe en la fila a partir de esa casilla.
          tope=columna+barco;
          for (i=columna;i<10 && i<tope;i++)
          {
             if (Tablero[fila][i] == AGUA) // Contar las casillas libres que tiene
                cont++;                 // la casilla elegida a partir de esta.
             else
                return 0;
          }
          if (cont < barco) // Si las casillas libres son insuficientes, la casilla no vale.
             return 0;
          return 1;
       }
       else // Mismo método que el anterior pero en vertical.
       {
          tope=fila+barco;
          for (i=fila;i<10 && i<tope;i++)
          {
             if (Tablero[i][columna] == AGUA)
                cont++;
             else
                return 0;
          }
          if (cont < barco)
             return 0;
          return 1;
       }
    }
    
    void Almacenar(char Tablero[10][10],int barco,Casilla cas,char posicion)
    {
       int i,fila,columna,tope;
       char tipo;
       int aux1=0;
    
       fila=cas.letra-65;
       columna=cas.numero-1;
       switch(barco) // Colocar una letra según el barco.
       {
          case AIRCRAFTCARRIER:
             tipo='A';
             break;
          case BATTLESHIP:
             tipo='B';
             break;
          case SUBMARINE:
             if (aux1 == 0)
             {
                tipo='S';
                aux1++;
             }
             else
                tipo='C';
             break;
          case DESTROYER:
             tipo='D';
             break;
       }
    
       /* Almacenar el barco según la posición y la casilla */
       if (posicion == 'h')
       {
          tope=columna+barco;
          for (i=columna;i<tope;i++)
             Tablero[fila][i]=tipo;
       }
       else
       {
          tope=fila+barco;
          for (i=fila;i<tope;i++)
             Tablero[i][columna]=tipo;
       }
    }
    
    /* Función turno del jugador */
    void TurnoJ1()
    {
       Casilla cas;
       int valida,fila,columna, tocadosJ1=0;
    
       strcpy(frase,"[Tu turno]\n");
       DibujarTablero(Aux);
       do {
          valida=0;
          fflush(stdin);
          printf("Letra: ");
          scanf("%c",&cas.letra);
          cas.letra=toupper(cas.letra);
          if (cas.letra < 65 || cas.letra > 74) // Verificar si la letra pertenece al rango válido
             valida++;
          printf("Numero: ");
          scanf("%d",&cas.numero);
          if (cas.numero < 1 || cas.numero > 10) // Verificar si el número pertenece al rango válido.
             valida++;
          fila=cas.letra-65;
          columna=cas.numero-1;
          if (Aux[fila][columna] != OCULTA) // Verificar si la casilla ya está "tocada".
             valida++;
          if (valida > 0) // Si falla algún parámetro anterior
          {            // se muestra un mensaje de error.
             printf("Casilla no valida\n");
             Sleep(1000);
          }
          DibujarTablero(Aux); // Se refresca" la pantalla.
       }while(valida > 0);
       Aux[fila][columna]=AtacarCasilla(TableroJ2,cas); // Comprobar la casilla.
       if (Aux[fila][columna] == HERIDO) // Si se ha tocado un barco oponente.
       {
          strcpy(frase,"[Tocado]\n");
          tocadosJ1++;
       }
       else // Si ha caído en agua.
          strcpy(frase,"[Agua]\n");
       DibujarTablero(Aux); // Dibujar el tablero
       system("pause");
    }
    
    /* Función turno del oponente */
    void TurnoJ2()
    {
       Casilla cas;
       int fila,columna, contador=0, tocadosJ2=0;
    
       strcpy(frase,"[Turno de tu oponente]\n");
       DibujarTablero(TableroJ1);
       cas=Lista[contador++];
       fila=cas.letra-65;
       columna=cas.numero-1;
       TableroJ1[fila][columna]=AtacarCasilla(TableroJ1,cas); // Comprobar la casilla.
       if (TableroJ1[fila][columna] == HERIDO) // Si se ha tocado un barco oponente.
       {
          strcpy(frase,"[Herido!]\n");
          tocadosJ2++;
       }
       else // Si ha caído en agua.
          strcpy(frase,"[Toco Agua!]\n");
       DibujarTablero(TableroJ1); // Dibujar el tablero
       system("pause");
    }
    
    /* Comprobamos la casilla para atacar */
    char AtacarCasilla(char Tablero[10][10],Casilla cas)
    {
       int fila,columna;
    
       fila=cas.letra-65;
       columna=cas.numero-1;
       if (Tablero[fila][columna] == 'P' || Tablero[fila][columna] == 'A' || Tablero[fila][columna] == 'S' || Tablero[fila][columna] == 'C' || Tablero[fila][columna] == 'D')
          return HERIDO; // Si se acierta.
       return AGUA;
    }
    
    /* Lista aleatoria de casillas */
    /* Ataque de la maquina */
    void GenerarLista()
    {
       int i,j,num;
       Casilla aux;
    
       for (i=0;i<100;i++)
       {
          for (j=1;j<11;j++)
          {
             Lista[i].letra=j+64; // Guarda todas las casillas
             Lista[i].numero=j;  // válidas en orden ascendente.
          }
       }
       srand(time(NULL));
       for (i=0;i<100;i++) // Desordenar las casillas.
       {
          num=rand()%100;
          aux=Lista[i];
          Lista[i]=Lista[num];
          Lista[num]=aux;
       }
    }
    Constants.h
    Code:
    #pragma once
    
    #define AGUA '0'
    #define HERIDO '*'
    #define OCULTA '#'
    #define AIRCRAFTCARRIER 5
    #define BATTLESHIP 4
    #define SUBMARINE 3
    #define CRUISER 3
    #define DESTROYER 2
    
    
    enum ColoresWindowsh{
        FONDO_GRIS_LETRA_GRIS=119,
        FONDO_GRIS_LETRA_NEGRA=112,
        FONDO_ROJO_LETRA_ROJA=204,
        FONDO_ROJO_LETRA_NEGRA=192,
        FONDO_AMARI_LETRA_AMARI=238,
        FONDO_AMARI_LETRA_NEGRA=224,
        FONDO_NEGRO_LETRA_GRIS=7,
    
    };

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is what I know about Windows colors. It starts with 0x so it's a hex number. Then it has two values after that

    0=Black, 1=Dark Blue, 2=Dark Green, etc. Which are all for the background color.

    Followed by a second value, which is the color of the text (foreground). Same values: 0=Black, 1=Dark Blue, 2=Dark Green, etc.

    Here's a program snippet that displays all the colors, for the first four backgrounds.
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    void design(void);
    
    int main() {
       design();
    
       return 0;
    }
    
    
    void design(void) {
       
       HANDLE hConsole;
       hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
       SetConsoleTextAttribute(hConsole, 0x00); printf("color=0x00\n");   //Black
       SetConsoleTextAttribute(hConsole, 0x01); printf("color=0x01\n");   //Dark Blue
       SetConsoleTextAttribute(hConsole, 0x02); printf("color=0x02\n");   //Dark Green
       SetConsoleTextAttribute(hConsole, 0x03); printf("color=0x03\n");   //Dark Cyan
       SetConsoleTextAttribute(hConsole, 0x04); printf("color=0x04\n");   //Dark Red
       SetConsoleTextAttribute(hConsole, 0x05); printf("color=0x05\n");   //Dark Magenta
       SetConsoleTextAttribute(hConsole, 0x06); printf("color=0x06\n");   //Dark Yellow
       SetConsoleTextAttribute(hConsole, 0x07); printf("color=0x07\n");   //Dark White
       SetConsoleTextAttribute(hConsole, 0x08); printf("color=0x08\n");   //Grey
       SetConsoleTextAttribute(hConsole, 0x09); printf("color=0x09\n");   //Blue
       SetConsoleTextAttribute(hConsole, 0x0A); printf("color=0x0A\n");   //Green
       SetConsoleTextAttribute(hConsole, 0x0B); printf("color=0x0B\n");   //Cyan
       SetConsoleTextAttribute(hConsole, 0x0C); printf("color=0x0C\n");   //Red
       SetConsoleTextAttribute(hConsole, 0x0D); printf("color=0x0D\n");   //Magenta  
       SetConsoleTextAttribute(hConsole, 0x0E); printf("color=0x0E\n");   //Yellow
       SetConsoleTextAttribute(hConsole, 0x0F); printf("color=0x0F\n\n");   //White
    
    
       SetConsoleTextAttribute(hConsole, 0x10); printf("color=0x10\n");   //Black
       SetConsoleTextAttribute(hConsole, 0x11); printf("color=0x11\n");   //Dark Blue
       SetConsoleTextAttribute(hConsole, 0x12); printf("color=0x12\n");   //Dark Green
       SetConsoleTextAttribute(hConsole, 0x13); printf("color=0x13\n");   //Dark Cyan
       SetConsoleTextAttribute(hConsole, 0x14); printf("color=0x14\n");   //Dark Red
       SetConsoleTextAttribute(hConsole, 0x15); printf("color=0x15\n");   //Dark Magenta
       SetConsoleTextAttribute(hConsole, 0x16); printf("color=0x16\n");   //Dark Yellow
       SetConsoleTextAttribute(hConsole, 0x17); printf("color=0x17\n");   //Dark White
       SetConsoleTextAttribute(hConsole, 0x18); printf("color=0x18\n");   //Grey
       SetConsoleTextAttribute(hConsole, 0x19); printf("color=0x19\n");   //Blue
       SetConsoleTextAttribute(hConsole, 0x1A); printf("color=0x1A\n");   //Green
       SetConsoleTextAttribute(hConsole, 0x1B); printf("color=0x1B\n");   //Cyan
       SetConsoleTextAttribute(hConsole, 0x1C); printf("color=0x1C\n");   //Red
       SetConsoleTextAttribute(hConsole, 0x1D); printf("color=0x1D\n");   //Magenta  
       SetConsoleTextAttribute(hConsole, 0x1E); printf("color=0x1E\n");   //Yellow
       SetConsoleTextAttribute(hConsole, 0x1F); printf("color=0x1F\n\n");   //White
    
       SetConsoleTextAttribute(hConsole, 0x20); printf("color=0x20\n");   //Black
       SetConsoleTextAttribute(hConsole, 0x21); printf("color=0x21\n");   //Dark Blue
       SetConsoleTextAttribute(hConsole, 0x22); printf("color=0x22\n");   //Dark Green
       SetConsoleTextAttribute(hConsole, 0x23); printf("color=0x23\n");   //Dark Cyan
       SetConsoleTextAttribute(hConsole, 0x24); printf("color=0x24\n");   //Dark Red
       SetConsoleTextAttribute(hConsole, 0x25); printf("color=0x25\n");   //Dark Magenta
       SetConsoleTextAttribute(hConsole, 0x26); printf("color=0x26\n");   //Dark Yellow
       SetConsoleTextAttribute(hConsole, 0x27); printf("color=0x27\n");   //Dark White
       SetConsoleTextAttribute(hConsole, 0x28); printf("color=0x28\n");   //Grey
       SetConsoleTextAttribute(hConsole, 0x29); printf("color=0x29\n");   //Blue
       SetConsoleTextAttribute(hConsole, 0x2A); printf("color=0x2A\n");   //Green
       SetConsoleTextAttribute(hConsole, 0x2B); printf("color=0x2B\n");   //Cyan
       SetConsoleTextAttribute(hConsole, 0x2C); printf("color=0x2C\n");   //Red
       SetConsoleTextAttribute(hConsole, 0x2D); printf("color=0x2D\n");   //Magenta  
       SetConsoleTextAttribute(hConsole, 0x2E); printf("color=0x2E\n");   //Yellow
       SetConsoleTextAttribute(hConsole, 0x2F); printf("color=0x2F\n\n");   //White
    
       SetConsoleTextAttribute(hConsole, 0x30); printf("color=0x30\n");   //Black
       SetConsoleTextAttribute(hConsole, 0x31); printf("color=0x31\n");   //Dark Blue
       SetConsoleTextAttribute(hConsole, 0x32); printf("color=0x32\n");   //Dark Green
       SetConsoleTextAttribute(hConsole, 0x33); printf("color=0x33\n");   //Dark Cyan
       SetConsoleTextAttribute(hConsole, 0x34); printf("color=0x34\n");   //Dark Red
       SetConsoleTextAttribute(hConsole, 0x35); printf("color=0x35\n");   //Dark Magenta
       SetConsoleTextAttribute(hConsole, 0x36); printf("color=0x36\n");   //Dark Yellow
       SetConsoleTextAttribute(hConsole, 0x37); printf("color=0x37\n");   //Dark White
       SetConsoleTextAttribute(hConsole, 0x38); printf("color=0x38\n");   //Grey
       SetConsoleTextAttribute(hConsole, 0x39); printf("color=0x39\n");   //Blue
       SetConsoleTextAttribute(hConsole, 0x3A); printf("color=0x3A\n");   //Green
       SetConsoleTextAttribute(hConsole, 0x3B); printf("color=0x3B\n");   //Cyan
       SetConsoleTextAttribute(hConsole, 0x3C); printf("color=0x3C\n");   //Red
       SetConsoleTextAttribute(hConsole, 0x3D); printf("color=0x3D\n");   //Magenta  
       SetConsoleTextAttribute(hConsole, 0x3E); printf("color=0x3E\n");   //Yellow
       SetConsoleTextAttribute(hConsole, 0x3F); printf("color=0x3F\n");   //White
    
    }
    Last edited by Adak; 11-30-2013 at 08:35 PM.

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    15
    Hey man, Thanks for the response. But i am talking about talking about the way the colors are presented in my game, if you run the game, you can see they are not working propertly and i don't know why =[

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    It would be better if you could construct a minimal example that demonstrates the problem you're having. For example, if I look at the code I can see some nonstandard function calls that would make it difficult to run. For example this line will launch a shell and look for a program called "pause":

    Code:
    system("pause");
    Which will not work on any systems which don't have such a command installed. I think it's only on Windows systems, but I'm not sure. Also fflush(stdin) will probably result in undefined behaviour. Nromally you only flush stdout, flushing stdin doesn't have any obvious purpose.

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    "The colors are wrong" is not a very good explanation.
    What's wrong with them?
    What OS are you using? (Obviously it's windows, but is it XP, 7, or 8?)

    @c99tut,
    This is a windows-specific question since it's about the console colors.

    @adak,
    Here's an expanded version of your color display.

    Code:
    #include <windows.h>
    #include <stdio.h>
     
    int main() {
        int b, f;
        CONSOLE_SCREEN_BUFFER_INFO scrbuf;
        HANDLE con = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(con, &scrbuf); // save current colors
        for (b = 0; b < 16; b++) {
            for (f = 0; f < 16; f++) {
                SetConsoleTextAttribute(con, (b<<4)|f);
                printf("%X%X ", b, f);
            }
            putchar('\n');
        }
        SetConsoleTextAttribute(con, scrbuf.wAttributes); // reset original colors
        return 0;
    }
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    582
    Are the colours not changing at all? If so, check the return from SetConsoleTextAttribute amd see of there was an error.

    If they've changed to the wrong colours then that suggests that you have the wrong values (or they were once right but msvc changed the numbering). Could you tell us what is 'wrong' with them then? A screenshot of the bad output maybe, with a description of what it's supposed to look like.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by johndoe1336 View Post
    Hey man, Thanks for the response. But i am talking about talking about the way the colors are presented in my game, if you run the game, you can see they are not working propertly and i don't know why =[
    I can't help you with your program, since I don't understand your language. You speak English, and this is an English speaking programming forum. Have you considered translating it into English?

    The color program I posted, works perfectly well. I checked it before I posted it. Run it yourself to confirm it works correctly.

    @oogabooga
    He doesn't understand simple hex apparently. You think he's going to understand bit shifting?

    I don't.

  8. #8
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,784
    Does Windows "console" even have colours? I thought it needed ANSI.sys (or the modern equivalent) for colours to work.

    Edit: According to oog's post it does, so ignore this

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Hodor View Post
    Does Windows "console" even have colours? I thought it needed ANSI.sys (or the modern equivalent) for colours to work.

    Edit: According to oog's post it does, so ignore this
    Not only does it have background and foreground colors, but it also has some textures you can do. All in the console. Just a tiny sample of the colors (which are the same as DOS, btw):

    My color's are not working propertly =[-consolecolors-jpg

  10. #10
    Registered User
    Join Date
    Nov 2013
    Posts
    15
    Hey, if you run the code you can see what the problem is, I want to change the edges and put them in specific color and put the center of the dash of another color in specific, the problem is that is not working and the colors are showing wrong or not showing at all.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by johndoe1336 View Post
    Hey, if you run the code you can see what the problem is, I want to change the edges and put them in specific color and put the center of the dash of another color in specific, the problem is that is not working and the colors are showing wrong or not showing at all.
    There are two problems with your suggestion:

    1) Your program is in a language I don't speak, so I can't debug it, and I'm not going to run it, either.

    2) You have not used the color code I gave you, which obviously works.

    Do you like being stubborn?

  12. #12
    Registered User
    Join Date
    Nov 2013
    Posts
    15
    Ahhh well my main language is Spanish, sry =/....and i will try the color code you gave me, i'll let you know in a few, thanks

  13. #13
    Registered User
    Join Date
    Nov 2013
    Posts
    15
    Can't

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Color not working when using an mouse event.
    By h3ro in forum C# Programming
    Replies: 2
    Last Post: 01-18-2011, 08:54 PM
  2. Class not working.. color...
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2006, 07:48 AM
  3. static text color/background color
    By braindude in forum C++ Programming
    Replies: 1
    Last Post: 07-06-2003, 05:58 AM
  4. Replies: 5
    Last Post: 03-28-2003, 06:20 AM
  5. CEditView Background Color & Font Color :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 05-30-2002, 09:44 AM