Xavistian

Ejericio 3

Jun 25th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. // ConsoleApplication2.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace System;
  8.  
  9. void genera_y_muestra_matriz(int matriz[20][20])
  10. {
  11.     Console::BackgroundColor = ConsoleColor::White;
  12.     Console::ForegroundColor = ConsoleColor::Black;
  13.     for (int i = 0; i < 20; i++)
  14.     {
  15.         for (int j = 0; j < 20; j++)
  16.         {
  17.             if (matriz[i][j]==0)cout << ' '; else cout << (char)219;
  18.         }cout << endl;
  19.     }
  20. }
  21. void desplazar_movil(int matriz[20][20])
  22. {
  23.     int ex = 11, ey = 3, dex = 1, dey=1;
  24.     int px = 15, py = 8;
  25.     int key;
  26.     Console::SetCursorPosition(ex, ey);
  27.     cout << (char)1;
  28.     Console::SetCursorPosition(px, py);
  29.     Console::ForegroundColor = ConsoleColor::Gray;
  30.     cout << (char)219;
  31.     Console::SetCursorPosition(px - 1, py + 1);
  32.     cout << (char)219 << (char)219 << (char)219;
  33.     while (1)
  34.     {
  35.         if (kbhit())
  36.         {
  37.             Console::ForegroundColor = ConsoleColor::Gray;
  38.             key = _getch();
  39.             if (key = 224)
  40.             {
  41.                 key = _getch();
  42.                 Console::SetCursorPosition(px, py);
  43.                 cout << ' ';
  44.                 Console::SetCursorPosition(px - 1, py + 1);
  45.                 cout << (char)32 << (char)32 << (char)32;
  46.                 switch (key)
  47.                 {
  48.                 case 72:if (py-1>0)py--;break;
  49.                 case 75:if (px-2>0)px--;break;
  50.                 case 77:if (px+2<19)px++;break;
  51.                 case 80:if (py+2<19)py++;break;
  52.                 }
  53.             }
  54.             Console::SetCursorPosition(px, py);
  55.             cout << (char)219;
  56.             Console::SetCursorPosition(px - 1, py + 1);
  57.             cout << (char)219 << (char)219 << (char)219;
  58.         }
  59.         _sleep(50);
  60.         Console::SetCursorPosition(ex, ey);
  61.         Console::ForegroundColor = ConsoleColor::Black;
  62.         cout << ' ';
  63.         if (ex == 18 || ex == 1)dex *= -1;
  64.         ex += dex;
  65.         if (ey == 1 || ey == 18)dey *= -1;
  66.         ey += dey;
  67.         Console::SetCursorPosition(ex, ey);
  68.         cout << (char)1;
  69.         if (ex == px&&ey == py || ex == px - 1 && ey == py + 1 || ex == px&&ey == py + 1 || ex == px + 1 && ey == py +1) {
  70.             Console::SetCursorPosition(px, py);
  71.             cout << ' ';
  72.             Console::SetCursorPosition(px - 1, py + 1);
  73.             cout << (char)32 << (char)32 << (char)32;
  74.             px = 15; py = 8;
  75.             Console::ForegroundColor = ConsoleColor::Gray;
  76.             Console::SetCursorPosition(px, py);
  77.             cout << (char)219;
  78.             Console::SetCursorPosition(px - 1, py + 1);
  79.             cout << (char)219 << (char)219 << (char)219;
  80.         }
  81.        
  82.     }
  83. }
  84. int main()
  85. {
  86.     int matriz[20][20] = {
  87.         {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
  88.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  89.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  90.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  91.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  92.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  93.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  94.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  95.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  96.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  97.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  98.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  99.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  100.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  101.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  102.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  103.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  104.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  105.         {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
  106.         {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
  107.     };
  108.     genera_y_muestra_matriz(matriz);
  109.     desplazar_movil(matriz);
  110.     _getch();
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment