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_matriz(int m1[20][23])
- {
- int xx=0, yy=0;
- Console::BackgroundColor = ConsoleColor::Black;
- for (int f = 0;f < 20;f++)
- {
- Console::SetCursorPosition(xx, yy);
- for (int c = 0;c < 23;c++)
- {
- switch (m1[f][c])
- {
- case 1:
- Console::BackgroundColor = ConsoleColor::DarkRed;
- cout << char(32);
- ;break;
- case 0:
- Console::BackgroundColor = ConsoleColor::DarkGray;
- cout << char(32);
- ;break;
- }
- }
- yy++;
- }
- }
- void dezpazar_movil(int m1[20][23])
- {
- int rx = 15;
- int ry = 9;
- int tecla;
- int ex=11;
- int ey=1;
- int edelx=1;
- while (1)
- {
- Console::SetCursorPosition(rx, ry);
- cout << "*";
- if (kbhit())
- {
- tecla = _getch();
- if (tecla == 224)
- {
- Console::SetCursorPosition(rx, ry);
- Console::BackgroundColor = ConsoleColor::DarkGray;
- cout << " ";
- tecla = _getch();
- switch (tecla)
- {
- case 72:ry--;
- if (ry < 0)
- {
- rx = 15;
- ry = 9;
- };break;
- case 75:rx--;
- if (rx < 0)
- {
- rx = 15;
- ry = 9;
- };break;
- case 77:rx++;
- if (rx > 22)
- {
- rx = 15;
- ry = 9;
- };break;
- case 80:ry++;
- if (ry > 19)
- {
- rx = 15;
- ry = 9;
- };break;
- }
- Console::SetCursorPosition(rx, ry);
- Console::BackgroundColor = ConsoleColor::DarkGray;
- cout << "*";
- }
- }
- _sleep(50);
- Console::BackgroundColor = ConsoleColor::DarkGray;
- Console::SetCursorPosition(ex, ey);
- Console::ForegroundColor = ConsoleColor::Black;
- cout << char(1);
- Console::BackgroundColor = ConsoleColor::DarkGray;
- Console::SetCursorPosition(ex, ey);
- cout << " ";
- if (ex == 0)edelx = 1;
- if (ex == 22)edelx = -1;
- ex = ex + edelx;
- Console::SetCursorPosition(ex, ey);
- cout << char(1);
- if (rx == ex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