Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- using namespace System;
- #define ARRIBA 72
- #define IZQUIERDA 75
- #define DERECHA 77
- #define ABAJO 80
- #define ESC 27
- #define ENTER 13
- #define CF 20
- #define CC 23
- int mapa[CF][CC];
- int backcolor = 0;
- int dir = 0;
- int anteriorpx, anteriorpy;
- int pxm = 8, pym = 10;
- int dx = 1, dy = 1;
- void gotoXY(int x, int y)
- {
- HANDLE ventana;
- ventana = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD punto;
- punto.X = x;
- punto.Y = y;
- SetConsoleCursorPosition(ventana, punto);
- }
- void cargarMapa()
- {
- int matTemporal[CF][CC] = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,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,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,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,0,0 } };
- for (int i = 0; i < CF; i++)
- {
- for (int j = 0; j < CC; j++)
- {
- mapa[i][j] = matTemporal[i][j];
- }
- }
- }
- void pintarMapa()
- {
- for (int i = 0; i < CF; i++) {
- for (int j = 0; j < CC; j++)
- {
- gotoXY(j, i);
- switch (mapa[i][j])
- {
- case 0:
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << (char)225;
- break;
- case 1:
- Console::ForegroundColor = ConsoleColor(2);
- cout << (char)0;
- break;
- }
- }
- }
- }
- void teclear() {
- gotoXY(pym, pxm); cout << "*";
- if (kbhit()) {
- char tecla = getch();
- switch (tecla) {
- case ARRIBA:
- if (mapa[pxm][pym] == 1)
- {
- gotoXY(pym, pxm); cout << "*";
- Sleep(70);
- gotoXY(pym, pxm); cout << " ";
- pxm--;
- }
- else
- {
- gotoXY(pym, pxm); cout << (char)225;
- pym = 10; pxm = 8;
- gotoXY(pym, pxm); cout << "*";
- }
- break;
- case ABAJO:
- if (mapa[pxm][pym] == 1)
- {
- gotoXY(pym, pxm); cout << "*";
- Sleep(70);
- gotoXY(pym, pxm); cout << " ";
- pxm++;
- }
- else
- {
- gotoXY(pym, pxm); cout << (char)225;
- pym = 10; pxm = 8;
- gotoXY(pym, pxm); cout << "*";
- }
- break;
- case DERECHA:
- if (mapa[pxm][pym] == 1)
- {
- gotoXY(pym, pxm); cout << "*";
- Sleep(70);
- gotoXY(pym, pxm); cout << " ";
- pym++;
- }
- else
- {
- gotoXY(pym, pxm); cout << (char)225;
- pym = 10; pxm = 8;
- gotoXY(pym, pxm); cout << "*";
- }
- break;
- case IZQUIERDA:
- if (mapa[pxm][pym] == 1)
- {
- gotoXY(pym, pxm); cout << "*";
- Sleep(70);
- gotoXY(pym, pxm); cout << " ";
- pym--;
- }
- else
- {
- gotoXY(pym, pxm); cout << (char)225;
- pym = 10; pxm = 8;
- gotoXY(pym, pxm); cout << "*";
- }
- break;
- }
- }
- }
- void desplazar_movil_y_enemigo(int x, int y)
- {
- int dy = -1;
- do {
- gotoXY(x, y); cout << "#";
- Sleep(70);
- gotoXY(x, y); cout << " ";
- //ubicar el movil
- teclear();
- if (y < 4) dy = 1;
- if (y > 7) dy = -1;
- y += dy;
- } while (1);
- }
- void main()
- {
- cargarMapa();
- pintarMapa();
- desplazar_movil_y_enemigo(19,8);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement