Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.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][23])
- {
- Console::BackgroundColor = ConsoleColor::White;
- Console::ForegroundColor = ConsoleColor::DarkGray;
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 23; j++)
- {
- if (Matriz[i][j] == 1) cout << (char)219; else cout << ' ';
- }cout << endl;
- }
- }
- void desplazar_movil(int Matriz[20][23])
- {
- int ey=1, ex=11, dex=1;
- int py = 9, px = 15;
- int key;
- while (1)
- {
- if (kbhit())
- {
- key = _getch();
- if (key == 224)
- {
- Console::SetCursorPosition(px, py);
- cout << ' ';
- key = _getch();
- switch (key)
- {
- case 72:if (py - 1 < 0) { px = 15; py = 9;} else py--;break;
- case 75:if (px -1<0) { px = 15; py = 9; } else px--;break;
- case 77:if (px+1>22) { px = 15; py = 9; }else px++;break;
- case 80:if(py+1>19) { px = 15; py = 9; } else py++;break;
- }
- }Console::SetCursorPosition(px, py); cout << '*';
- }
- _sleep(20);
- Console::SetCursorPosition(ex, ey);
- cout << ' ';
- if (ex == 22 || ex == 0)
- dex *= -1;
- ex += dex;
- Console::SetCursorPosition(ex, ey);
- cout << (char)1;
- if (ex == px&&ey == py) { px = 15; py = 9; }
- }
- }
- int main()
- {
- int Matriz[20][23] = {
- { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,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,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,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
- { 0,0,0,0,0,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,0 }, };
- genera_y_muestra_matriz(Matriz);
- desplazar_movil(Matriz);
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment