Good evening, I am programming a soup of letters in c ++ with intermediate code or three addresses and then pass it to the GUI TASM assembly. What the program should do is print a one-dimensional array with the letters, and move around the array with the arrows and when you press enter on a letter, if it is one of the accepted ones, change it.
In intermediate code I can not use the coordinates (x, y) as in a two-dimensional matrix, in this case it is done by the formula f (x, y) = x + Zy; where "x" is the column, "y" is the row and "Z" is the width of the matrix.
My doubt arises, how to implement the functionality of going through the array and being an accepted letter change it color. My theory is to have three arrays, one to show the letters, another with the values of the colors and a last one with the positions that are accepted. Currently I change the colors based on an array that already has the values of colors changed.
If someone can help me, specifically to be able to go through the array and change the colors if it is accepted, very grateful
#include <windows.h>
#include <stdio.h>
#include <conio.h>
void gotoxy(int column, int line);
void drawStaticSprite(int sprite[][10]);
void drawStaticSprite3Dir();
int sleepTime = 100;
int x = 0;
int y = 0;
char sop3dir2[100]= {'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'};
int Colores1[100] = {15,14,14,14,14,14,14,14,14,14,
15,14,15,15,15,15,15,15,14,14,
15,14,14,14,14,14,14,14,14,14,
15,14,14,14,14,14,14,14,14,14,
15,14,14,14,14,14,14,14,14,14,
15,14,14,14,14,14,14,14,14,14,
15,15,15,15,15,15,15,15,14,14,
14,14,14,14,14,14,14,14,14,14,
14,14,14,14,14,14,14,14,14,14,
14,14,14,14,14,14,14,14,14,14};
int main(int argc, char** argv) {
int myChar;
drawStaticSprite3Dir();
do {
myChar = getch();
if (myChar == 224)
{
myChar = getch();
}
else
{
if (myChar == 72)//Fecla Arriba
{
y=y-1;
}
else if (myChar == 80)//Fecla Abajo
{
y=y+1;
}
else if (myChar == 75)//Flecha Izquierda
{
x=x-1;
}
else if (myChar == 77)//Flecha Derecha
{
x=x+1;
}
else if (myChar == 13) //Si es enter grabar posicion
{
//colores(y,x);
}
}
} while (myChar != 27);
getch();
return 0;
}
void drawStaticSprite3Dir() {
int startX;
int startY;
int x;
int y;
int t1;
int t2;
startX = 0;
startY = 0;
x = 0;
l5:
if (x < 10) goto l0;
goto l1;
l0:
y = 0;
l4:
if (y < 10) goto l2;
goto l3;
l2:
t1 = startY + y;
t2 = startX + x;
gotoxy( t2,t1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Colores1[x +
(10*y)]);
printf("%c", putchar(sop3dir2[x+(10*y)]));
y = y + 1;
goto l4;
l3:
x = x + 1;
goto l5;
l1:
return;
}
void gotoxy( int column, int line ) {
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE ),coord);
}