Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- void genera_y_muestra_matriz(int matriz[20][20])
- {
- Console::BackgroundColor = ConsoleColor::White;
- Console::ForegroundColor = ConsoleColor::Black;
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 20; j++)
- {
- if (matriz[i][j]==0)cout << ' '; else cout << (char)219;
- }cout << endl;
- }
- }
- void desplazar_movil(int matriz[20][20])
- {
- int ex = 11, ey = 3, dex = 1, dey=1;
- int px = 15, py = 8;
- int key;
- Console::SetCursorPosition(ex, ey);
- cout << (char)1;
- Console::SetCursorPosition(px, py);
- Console::ForegroundColor = ConsoleColor::Gray;
- cout << (char)219;
- Console::SetCursorPosition(px - 1, py + 1);
- cout << (char)219 << (char)219 << (char)219;
- while (1)
- {
- if (kbhit())
- {
- Console::ForegroundColor = ConsoleColor::Gray;
- key = _getch();
- if (key = 224)
- {
- key = _getch();
- Console::SetCursorPosition(px, py);
- cout << ' ';
- Console::SetCursorPosition(px - 1, py + 1);
- cout << (char)32 << (char)32 << (char)32;
- switch (key)
- {
- case 72:if (py-1>0)py--;break;
- case 75:if (px-2>0)px--;break;
- case 77:if (px+2<19)px++;break;
- case 80:if (py+2<19)py++;break;
- }
- }
- Console::SetCursorPosition(px, py);
- cout << (char)219;
- Console::SetCursorPosition(px - 1, py + 1);
- cout << (char)219 << (char)219 << (char)219;
- }
- _sleep(50);
- Console::SetCursorPosition(ex, ey);
- Console::ForegroundColor = ConsoleColor::Black;
- cout << ' ';
- if (ex == 18 || ex == 1)dex *= -1;
- ex += dex;
- if (ey == 1 || ey == 18)dey *= -1;
- ey += dey;
- Console::SetCursorPosition(ex, ey);
- cout << (char)1;
- if (ex == px&&ey == py || ex == px - 1 && ey == py + 1 || ex == px&&ey == py + 1 || ex == px + 1 && ey == py +1) {
- Console::SetCursorPosition(px, py);
- cout << ' ';
- Console::SetCursorPosition(px - 1, py + 1);
- cout << (char)32 << (char)32 << (char)32;
- px = 15; py = 8;
- Console::ForegroundColor = ConsoleColor::Gray;
- Console::SetCursorPosition(px, py);
- cout << (char)219;
- Console::SetCursorPosition(px - 1, py + 1);
- cout << (char)219 << (char)219 << (char)219;
- }
- }
- }
- int main()
- {
- int matriz[20][20] = {
- {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
- {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
- };
- genera_y_muestra_matriz(matriz);
- desplazar_movil(matriz);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment