Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <stdlib.h>
- #include <Windows.h>
- #include <iomanip>
- #include <math.h>
- #include <conio.h>
- //TECLAS DE MOVIMIENTO
- #define ARRIBA 72
- #define IZQUIERDA 75
- #define DERECHA 77
- #define ABAJO 80
- #define ye1 9
- #define ye2 34
- //FILAS Y COLUMNAS
- #define FILA 45
- #define COLUMNA 80
- //USO POSTERIOR PARA UNA ACCIÓN CONCRETA
- #define ENTER 13
- using namespace std;
- using namespace System;
- //VARIABLES GLOBALES
- int nivel; //PARA POSTERIOR CAMBIO DE NIVEL DESPUÉS DE COMER TODOS LOS BLOQUES
- int mapa[FILA][COLUMNA]; //MATRIZ PRINCIPAL QUE DEFINE
- int puntaje = 0;
- int vidas = 7;
- //
- // CARGAR MATRICES DE DIBUJO DE LOS NUMEROS GRANDES
- //
- int ***numeros;
- void rellenarMatrizNumeros(int ***numeros, int n[5][6], int cod)
- {
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < 6; ++j)
- {
- numeros[cod][i][j] = n[i][j];
- }
- }
- }
- void cargarNumeros()
- {
- numeros = new int**[10];
- for (int k = 0; k < 10; ++k)
- {
- numeros[k] = new int*[5];
- for (int i = 0; i < 5; ++i)
- {
- numeros[k][i] = new int[6];
- }
- }
- int n_0[5][6] = { { 0,1,1,1,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 } };
- int n_1[5][6] = { { 0,1,1,0,0,0 },
- { 0,1,1,0,0,0 },
- { 0,1,1,0,0,0 },
- { 0,1,1,0,0,0 },
- { 0,1,1,0,0,0 } };
- int n_2[5][6] = { { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,1,0,0,0,0 },
- { 0,1,1,1,1,0 } };
- int n_3[5][6] = { { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,1,1,1,1,0 } };
- int n_4[5][6] = { { 0,1,0,0,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,0,0,0,1,0 } };
- int n_5[5][6] = { { 0,1,1,1,1,0 },
- { 0,1,0,0,0,0 },
- { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,1,1,1,1,0 } };
- int n_6[5][6] = { { 0,1,1,1,1,0 },
- { 0,1,0,0,0,0 },
- { 0,1,1,1,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 } };
- int n_7[5][6] = { { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,0,0,0,1,0 } };
- int n_8[5][6] = { { 0,1,1,1,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 } };
- int n_9[5][6] = { { 0,1,1,1,1,0 },
- { 0,1,0,0,1,0 },
- { 0,1,1,1,1,0 },
- { 0,0,0,0,1,0 },
- { 0,0,0,0,1,0 } };
- rellenarMatrizNumeros(numeros, n_0, 0);
- rellenarMatrizNumeros(numeros, n_1, 1);
- rellenarMatrizNumeros(numeros, n_2, 2);
- rellenarMatrizNumeros(numeros, n_3, 3);
- rellenarMatrizNumeros(numeros, n_4, 4);
- rellenarMatrizNumeros(numeros, n_5, 5);
- rellenarMatrizNumeros(numeros, n_6, 6);
- rellenarMatrizNumeros(numeros, n_7, 7);
- rellenarMatrizNumeros(numeros, n_8, 8);
- rellenarMatrizNumeros(numeros, n_9, 9);
- }
- // ************************************************
- /* MATRICES DEL PERSONAJE*/
- int **personaje;
- void cargarPersonaje()
- {
- personaje = new int*[3];
- for (int i = 0; i < 3; ++i)
- {
- personaje[i] = new int[3];
- }
- }
- int personajeArriba[3][3] = { { 0,1,0 },
- { 2,4,3 },
- { 5,4,5 } };
- int personajeAbajo[3][3] = { { 5,4,5 },
- { 3,4,2 },
- { 0,1,0 } };
- int personajeIzquierda[3][3] = { { 0,2,6 },
- { 1,4,4 },
- { 0,3,6 } };
- int personajeDerecha[3][3] = { { 6,3,0 },
- { 4,4,1 },
- { 6,2,0 } };
- void copiarPersonajeArriba()
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- personaje[i][j] = personajeArriba[i][j];
- }
- }
- }
- void copiarPersonajeAbajo()
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- personaje[i][j] = personajeAbajo[i][j];
- }
- }
- }
- void copiarPersonajeIzquierda()
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- personaje[i][j] = personajeIzquierda[i][j];
- }
- }
- }
- void copiarPersonajeDerecha()
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- personaje[i][j] = personajeDerecha[i][j];
- }
- }
- }
- //MAPA 1// es necesario para el cambio de nivel
- }
- //FUNCION PARA COLOREAR MAPA
- void imprimemapa()
- {
- for (int f = 0; f < FILA; f++)
- {
- for (int c = 0; c < COLUMNA; c++)
- {
- Console::SetCursorPosition(c, f); //posiciona el cursor en un punto determinado x y
- if (mapa[f][c] == 1)
- {
- Console::ForegroundColor = ConsoleColor::Red;
- cout << char(219);
- }
- if (mapa[f][c] == 2)
- {
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << char(219);
- }
- if (mapa[f][c] == 3)
- {
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << char(219);
- }
- if (mapa[f][c] == 4)
- {
- Console::ForegroundColor = ConsoleColor::Green;
- cout << char(219);
- }
- if (mapa[f][c] == 5)
- {
- Console::ForegroundColor = ConsoleColor::DarkMagenta;
- cout << char(219);
- }
- if (mapa[f][c] == 6)
- {
- Console::ForegroundColor = ConsoleColor::White;
- cout << char(219);
- }
- if (mapa[f][c] == 7)
- {
- Console::ForegroundColor = ConsoleColor::Magenta;
- cout << char(219);
- }
- if (mapa[f][c] == 8)
- {
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << char(219);
- }
- if (mapa[f][c] == 9)
- {
- Console::ForegroundColor = ConsoleColor::DarkCyan;
- cout << char(219);
- }
- }
- }
- }
- //MAPA 2// es necesario para el cambio de nivel
- }
- //MAPA 3// es necesario para el cambio de nivel
- }
- //MAPA 4// es necesario para el cambio de nivel
- }
- //MAPA 5// es necesario para el cambio de nivel
- }
- //FUNCION PARA MANIPULAR COORDENADAS DE CONSOLA
- void gotoxy(int x, int y)
- {
- HANDLE hcon;
- hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD Posicion;
- Posicion.X = x;
- Posicion.Y = y;
- SetConsoleCursorPosition(hcon, Posicion);
- }
- //FUNCION PARA IMPRESION DE LA NAVE EN EL MAPA (NO SE MUEVE TODAVIA)
- /*void navecita()
- {
- Console::ForegroundColor = ConsoleColor::DarkGreen;
- int x = 39, y = 22;
- gotoxy(x, y);
- cout << " ";
- gotoxy(x, y + 1);
- cout << " " << char(223) << char(223);
- Console::CursorVisible = false;
- }*/
- //FUNCION PARA MOVER NAVECITA (AUN ESTA EN DESARROLLO) NO PRESIONAR FLECHAS
- bool hayComida()
- {
- for (int i = 0; i < FILA; ++i)
- {
- for (int j = 0; j < COLUMNA; ++j)
- {
- if (mapa[i][j] == 7)
- {
- return true;
- }
- }
- }
- return false;
- }
- void mostrarVidas()
- {
- Console::ForegroundColor = ConsoleColor::Yellow;
- string aux = to_string(vidas);
- for (int k = 0; k < aux.size(); ++k)
- {
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < 6; ++j)
- {
- Console::SetCursorPosition(j + 5 * k + 73, i + 39);
- if ((int)numeros[aux.at(k) - 48][i][j])
- {
- cout << char(219);
- }
- else
- {
- cout << " ";
- }
- }
- }
- }
- }
- void dibujarNumero()
- {
- Console::ForegroundColor = ConsoleColor::Yellow;
- string aux = to_string(puntaje);
- for (int k = 0; k < aux.size(); ++k)
- {
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < 6; ++j)
- {
- Console::SetCursorPosition(j + 5 * k + 3, i + 1);
- if ((int)numeros[aux.at(k) - 48][i][j])
- {
- cout << char(219);
- }
- else
- {
- cout << " ";
- }
- }
- }
- }
- }
- void dibujarPersonaje(int &x, int &y, char &c)
- {
- Console::ForegroundColor = ConsoleColor::Cyan;
- switch (c)
- {
- case ARRIBA:
- {
- copiarPersonajeArriba();
- break;
- }
- case ABAJO:
- {
- copiarPersonajeAbajo();
- break;
- }
- case IZQUIERDA:
- {
- copiarPersonajeIzquierda();
- break;
- }
- case DERECHA:
- {
- copiarPersonajeDerecha();
- break;
- }
- }
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- Console::SetCursorPosition(x + j, y + i);
- if (personaje[i][j] == 0)
- {
- cout << " ";
- }
- else if (personaje[i][j] == 1)
- {
- cout << char(158);
- }
- else if (personaje[i][j] == 2)
- {
- cout << char(47);
- }
- else if (personaje[i][j] == 3)
- {
- cout << char(92);
- }
- else if (personaje[i][j] == 4)
- {
- cout << char(219);
- }
- else if (personaje[i][j] == 5)
- {
- cout << char(186);
- }
- else if (personaje[i][j] == 6)
- {
- cout << char(205);
- }
- }
- }
- }
- void borrarPersonaje(int &x, int &y)
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- Console::SetCursorPosition(x + j, y + i);
- cout << " ";
- }
- }
- }
- bool estaEnComida(int &x, int &y)
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- if (mapa[i + y][j + x] == 7)
- {
- return true;
- }
- }
- }
- return false;
- }
- void moverPersonaje(int &x, int &y, char &c)
- {
- switch (c)
- {
- case ARRIBA:
- {
- if (mapa[y - 1][x] != 1)
- {
- borrarPersonaje(x, y);
- --y;
- dibujarPersonaje(x, y, c);
- }
- break;
- }
- case ABAJO:
- {
- if (mapa[y + 3][x] != 1)
- {
- borrarPersonaje(x, y);
- ++y;
- dibujarPersonaje(x, y, c);
- }
- break;
- }
- case IZQUIERDA:
- {
- if (mapa[y][x - 1] != 1)
- {
- borrarPersonaje(x, y);
- --x;
- dibujarPersonaje(x, y, c);
- }
- break;
- }
- case DERECHA:
- {
- if (mapa[y][x + 3] != 1)
- {
- borrarPersonaje(x, y);
- ++x;
- dibujarPersonaje(x, y, c);
- }
- break;
- }
- }
- if (estaEnComida(x, y))
- {
- puntaje += 50;
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- mapa[i + y][j + x] = 0;
- }
- }
- dibujarNumero();
- }
- }
- void dibujarEnemigos(int &xe1, int &xe2)
- {
- Console::ForegroundColor = ConsoleColor::Green;
- Console::SetCursorPosition(xe1, ye1);
- cout << char(219) << char(219) << char(219);
- Console::SetCursorPosition(xe1, ye1 + 1);
- cout << char(219) << char(219) << char(219);
- Console::SetCursorPosition(xe1, ye1 + 2);
- cout << " " << char(219) << " ";
- Console::SetCursorPosition(xe2, ye2);
- cout << " " << char(219) << " ";
- Console::SetCursorPosition(xe2, ye2 + 2);
- cout << char(219) << char(219) << char(219);
- Console::SetCursorPosition(xe2, ye2 + 1);
- cout << char(219) << char(219) << char(219);
- }
- void borrarEnemigos(int &xe1, int &xe2)
- {
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- Console::SetCursorPosition(xe1 + j, ye1 + i);
- cout << " ";
- Console::SetCursorPosition(xe2 + j, ye2 + i);
- cout << " ";
- }
- }
- }
- void moverEnemigos(int &xe1, int &xe2)
- {
- static int dx1 = 1;
- static int dx2 = -1;
- if (xe1 + dx1 + 2 > 60 || xe1 + dx1 < 14)
- {
- dx1 *= -1;
- }
- if (xe2 + dx2 + 2 > 60 || xe2 + dx2 < 14)
- {
- dx2 *= -1;
- }
- borrarEnemigos(xe1, xe2);
- xe1 += dx1;
- xe2 += dx2;
- dibujarEnemigos(xe1, xe2);
- }
- void movimiento()
- {
- int x = 40, y = 22;
- int xe1 = 31;
- int xe2 = 20;
- char c = ARRIBA;
- dibujarNumero();
- dibujarPersonaje(x, y, c);
- mostrarVidas();
- do
- {
- moverEnemigos(xe1, xe2);
- for (int i = 0; i < 10000000; ++i);
- if (_kbhit())
- {
- c = getch();
- moverPersonaje(x, y, c);
- }
- } while (hayComida());
- }
- void enemigo()
- {
- }
- //FUNCION PRINCIPAL DONDE SE LLAMAN A LOS MAPAS
- //PRESIONAR ENTER PARA CAMBIAR DE MAPA, NO PRESIONAR FLECHAS
- int main()
- {
- //Console::SetWindowSize(80, 45); //tamaño de consola
- Console::CursorVisible = false;
- cargarNumeros();
- cargarPersonaje();
- puntaje = 0;
- vidas = 6;
- copianivel();
- imprimemapa();
- movimiento();
- //enemigo();
- system("cls");
- copianivel2();
- imprimemapa();
- movimiento();
- system("cls");
- copianivel3();
- imprimemapa();
- movimiento();
- system("cls");
- copianivel4();
- imprimemapa();
- movimiento();
- system("cls");
- copianivel5();
- imprimemapa();
- movimiento();
- _getch();
- return 0;
- }
- /*_getch();
- Console::Clear();
- copianivel2();
- imprimemapa();
- navecita();
- _getch();
- Console::Clear();
- copianivel3();
- imprimemapa();
- navecita();
- _getch();
- Console::Clear();
- copianivel4();
- imprimemapa();
- navecita();
- _getch();
- Console::Clear();
- copianivel5();
- imprimemapa();
- navecita();
- _getch();
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement