Word Search, Browse Matrix

1

Good afternoon I'm programming a soup of letters in c ++ that shows on the screen the matrix with all the letters. I must be able to go through the matrix with the arrow keys and by pressing enter on a letter that is between the accepted ones, change it until all the letters of the word are completed.

They recommended me to do it with sprites with two matrices.

The problem I have is that I can not go through the matrix and change the colors of the letters I select with enter.

I made a matrix with the letters and another with the same dimensions to go through it.

If someone can help me to effectively tour the matrix, thank you very much.

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <ctype.h>
#include <string.h>
char sop[10][10]={{'M','M','L','E','E','N','A','E','V','E'},
                  {'E','R','H','O','N','G','O','S','T','R'},
                  {'X','X','O','T','I','R','R','A','C','A'},
                  {'I','S','A','P','P','O','T','A','P','S'},
                  {'C','C','M','L','A','A','I','Z','O','T'},
                  {'O','A','A','U','A','N','U','L','P','U'},
                  {'S','O','M','B','R','E','R','O','M','P'},
                  {'C','N','E','A','R','R','I','I','O','O'},
                  {'W','O','J','E','N','O','C','P','Z','E'},
                  {'A','A','Z','A','A','L','N','Y','T','D'}};

char moverFlechas[10][10];
int x = 1;
int y = 1;

void main()
{
int myChar;
    int f,c,i;
    textbackground(BLACK);
    textcolor(WHITE);
    for(f=0;f<10;f++)
    {
        for(c=0;c<10;c++)
            {
                gotoxy((c+3)*2,(f+1)*2);cprintf("%c",sop[f][c]);
            }
    }

  do {
  myChar = getch();

  if (myChar == 224) {
        myChar = getch();
    } else {
            if (myChar == 72) {
            cprintf("Up Arrow");
            y=y-1;
            cprintf("x %c",moverFlechas[x][y]);
        } else if (myChar == 80) {
            cprintf("Down Arrow");
            y=y+1;
            cprintf("x %c",moverFlechas[x][y]);
        } else if (myChar == 75) {
            cprintf("Left Arrow");
            x=x-1;
            cprintf("x %c",moverFlechas[x][y]);
        } else if (myChar == 77) {
            cprintf("Right Arrow");
            x=x+1;
            cprintf("x %c",moverFlechas[x][y]);
        }

    }
  } while (myChar != 27);  //13 es enter

}
    
asked by raintrooper 06.11.2017 в 00:45
source

1 answer

0

The term sprites in this context as an array defined for the possible color patterns that you will display on the screen. Based on your description there are two possible patterns. One corresponds to the letters that have not been selected. Another pattern will correspond to the letter selected with Enter .

The strategy will be to have defined, in some part of the program, the corresponding actions (for each pattern) for textcolor() and textbackground () 'for each of the patterns.

Let's assume that the patterns you have identified as 0 and 1 , then, the simplest case to print the characters using this pattern will be:

if(patron == 0)  /* me gusta ser verboso */
{
    textbackground(BLACK);
    textcolor(WHITE);
    putchar(sop[fila][columna]);
}
else
{
    textbackground(BLACK);
    textcolor(RED);
    putchar(sop[fila][columna]);
}

That's from the sprites. Now, you will need a matrix where you keep track of which pattern corresponds to each character, the same size as sop[][] . Suppose that only the characters of the word HONGO have been selected, and you want to show those letters in RED, then what you will have (at that moment) in this arrangement sop_sprite_reg[][] will be the following:

sop_sprite_reg[10][10]={{ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  1,  1,  1,  1,  1,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  }};

If now the user chooses the characters of the word LEE then the arrangement will change to the following:

sop_sprite_reg[10][10]={{ 0,  0,  1,  1,  1,  0,  0,  0,  0,  0  },
                        { 0,  0,  1,  1,  1,  1,  1,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
                        { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0  }};
    
answered by 07.11.2017 / 06:24
source