Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- void genera_y_muestra_mapa(int m1[20][20])
- {
- int xx, yy;
- for (int f = 0;f < 20;f++)
- {
- Console::SetCursorPosition(xx, yy);
- for (int c = 0;c < 20;c++)
- {
- switch (m1[f][c])
- {
- case 0:Console::BackgroundColor = ConsoleColor::White;
- cout << " ";
- break;
- case 1:Console::BackgroundColor = ConsoleColor::Black;
- cout << " ";
- break;
- }
- }
- yy++;
- }
- }
- void dezplazar_movil(int m1[20][20])
- {
- int px = 15, py = 9;
- int ex = 11, ey = 4, delex = 1;
- int tecla;
- Console::ForegroundColor = ConsoleColor::Gray;
- Console::SetCursorPosition(px, py);
- cout << char(177);
- Console::SetCursorPosition(px - 1, py + 1);
- cout << char(177) << char(177) << char(177);
- while (1)
- {
- if (kbhit())
- {
- tecla = _getch();
- Console::BackgroundColor = ConsoleColor::White;
- Console::SetCursorPosition(px, py);
- cout << char(32);
- Console::SetCursorPosition(px - 1, py + 1);
- cout << char(32) << char(32) << char(32);
- if (tecla == 224)
- {
- tecla = _getch();
- switch (tecla)
- {
- case 72:
- if (m1[py - 1][px] == 1)
- {
- px = 15;
- py = 9;
- }
- else
- py--;
- break;
- case 75:
- if (m1[py][px - 2] == 1)
- {
- px = 15;
- py = 9;
- }
- else
- px--;
- break;
- case 77:
- if (m1[py][px + 2] == 1)
- {
- px = 15;
- py = 9;
- }
- else
- px++;
- break;
- case 80:
- if (m1[py + 2][px] == 1)
- {
- px = 15;
- py = 9;
- }
- else
- py++;
- break;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- Console::SetCursorPosition(px, py);
- cout << char(177);
- Console::SetCursorPosition(px - 1, py + 1);
- cout << char(177) << char(177) << char(177);
- }
- }
- /*--------------------------------------------------*/
- Console::BackgroundColor = ConsoleColor::White;
- Console::SetCursorPosition(px, py);
- cout << char(32);
- Console::SetCursorPosition(px - 1, py + 1);
- cout << char(32) << char(32) << char(32);
- if ((px == ex && py == ey) || (px - 1 == ex && py + 1 == ey) || (px + 1 == ex && py + 1 == ey))
- {
- px = 15;
- py = 9;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- Console::SetCursorPosition(px, py);
- cout << char(177);
- Console::SetCursorPosition(px - 1, py + 1);
- cout << char(177) << char(177) << char(177);
- _sleep(50);
- /*--------------------------------------------------*/
- Console::ForegroundColor = ConsoleColor::Black;
- Console::SetCursorPosition(ex, ey);
- cout << char(1);
- Console::ForegroundColor = ConsoleColor::White;
- Console::SetCursorPosition(ex, ey);
- cout << char(32);
- if (ex == 1) delex = 1;
- if (ex == 18) delex = -1;
- ex = ex + delex;
- Console::ForegroundColor = ConsoleColor::Black;
- Console::SetCursorPosition(ex, ey);
- cout << char(1);
- }
- }
- int main()
- {
- int m1[20][20] =
- {
- {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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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,1},
- {1,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}
- };
- genera_y_muestra_mapa(m1);
- dezplazar_movil(m1);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement