Untitled
taller semana 13unknown
plain_text
3 years ago
8.5 kB
14
Indexable
#include <iostream> #include <conio.h> using namespace std; using namespace System; #define DERECHA 77 #define IZQUIERDA 75 #define ARRIBA 72 #define ABAJO 80 struct Kubo { int fil = 3, col = 3; int cuerpo[3][3] = { {1,1,1}, {1,0,1}, {1,1,1} }; void dibujar(int pos_x,int pos_y) { for (int j = 0; j < fil; j++) { for (int i = 0; i < col; i++) { switch (cuerpo[j][i]) { case 0: Console::SetCursorPosition(pos_x+i, pos_y+j); cout << " "; break; case 1: Console::SetCursorPosition(pos_x+i, pos_y+j); Console::ForegroundColor = ConsoleColor::DarkBlue; cout << char(219); Console::ForegroundColor = ConsoleColor::Black; break; } } cout << endl; } } void borrar(int pos_x, int pos_y) { for (int j = 0; j < fil; j++) { for (int i = 0; i < col; i++) { Console::SetCursorPosition(pos_x + i, pos_y + j); Console::ForegroundColor = ConsoleColor::Black; cout << " "; } } } }; struct Mapa { int fil = 25, col = 80; int mapa1[25][80] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,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,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,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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,3,0,0,0,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,1}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; void dibujar(int pos_x, int pos_y) { for (int j = 0; j < fil; j++) { for (int i = 0; i < col; i++) { switch (mapa1[j][i]) { case 0: Console::SetCursorPosition(pos_x + i, pos_y + j); Console::ForegroundColor = ConsoleColor::Black; cout << " "; break; case 1: Console::SetCursorPosition(pos_x + i, pos_y + j); Console::ForegroundColor = ConsoleColor::Red; cout << char(219); break; case 3: Console::SetCursorPosition(pos_x + i, pos_y + j); Console::ForegroundColor = ConsoleColor::Green; cout << char(219); break; case 4: Console::SetCursorPosition(pos_x + i, pos_y + j); Console::ForegroundColor = ConsoleColor::Yellow; cout << char(219); break; } } cout << endl; } } }; int main() { Console::CursorVisible = false; char tecla; int pos_x = 1; int pos_y = 1; Kubo* kubo1 = new Kubo[1]; //kubo1[0].dibujar(); Mapa* arrMapas = new Mapa[1]; //Pintamos el mapa arrMapas[0].dibujar(0,0); //Pintamos la posicion inicial del jugador kubo1[0].dibujar(pos_x,pos_y); while (true) { if (kbhit()) { tecla = getch(); //DERECHA = char(77) if (tecla == DERECHA || tecla == IZQUIERDA || tecla == ARRIBA || tecla == ABAJO) { kubo1[0].borrar(pos_x, pos_y); if (tecla == DERECHA && arrMapas[0].mapa1[pos_y][pos_x + 3]!=1 && arrMapas[0].mapa1[pos_y+1][pos_x + 3] != 1 && arrMapas[0].mapa1[pos_y+2][pos_x + 3] != 1 && arrMapas[0].mapa1[pos_y][pos_x + 3] != 4 && arrMapas[0].mapa1[pos_y + 1][pos_x + 3] != 4 && arrMapas[0].mapa1[pos_y + 2][pos_x + 3] != 4) { if (arrMapas[0].mapa1[pos_y][pos_x + 3] == 3 || arrMapas[0].mapa1[pos_y + 1][pos_x + 3] == 3 || arrMapas[0].mapa1[pos_y + 2][pos_x + 3] == 3) { Console::Clear(); Console::SetCursorPosition(10, 4); Console::ForegroundColor = ConsoleColor::White; cout << "FELICIDADES, GANASTE!!!!!!"; break; } pos_x++; } if (tecla == IZQUIERDA && arrMapas[0].mapa1[pos_y][pos_x - 1] != 1 && arrMapas[0].mapa1[pos_y+1][pos_x - 1] != 1 && arrMapas[0].mapa1[pos_y+2][pos_x - 1] != 1 && arrMapas[0].mapa1[pos_y][pos_x - 1] != 4 && arrMapas[0].mapa1[pos_y + 1][pos_x - 1] != 4 && arrMapas[0].mapa1[pos_y + 2][pos_x - 1] != 4) { pos_x--; } if (tecla == ARRIBA && arrMapas[0].mapa1[pos_y-1][pos_x] != 1 && arrMapas[0].mapa1[pos_y - 1][pos_x+1] != 1 && arrMapas[0].mapa1[pos_y - 1][pos_x+2] != 1 && arrMapas[0].mapa1[pos_y - 1][pos_x] != 4 && arrMapas[0].mapa1[pos_y - 1][pos_x + 1] != 4 && arrMapas[0].mapa1[pos_y - 1][pos_x + 2] != 4) { pos_y--; } if (tecla == ABAJO && arrMapas[0].mapa1[pos_y+3][pos_x]!=1 && arrMapas[0].mapa1[pos_y + 3][pos_x+1] != 1 && arrMapas[0].mapa1[pos_y + 3][pos_x+2] != 1 && arrMapas[0].mapa1[pos_y + 3][pos_x] != 4 && arrMapas[0].mapa1[pos_y + 3][pos_x + 1] != 4 && arrMapas[0].mapa1[pos_y + 3][pos_x + 2] != 4) { pos_y++; } } kubo1[0].dibujar(pos_x, pos_y); } } cout << "Salimos del while"; getch(); return 0; }
Editor is loading...