AgustinMayta

Ejercicio 2 hoja2

Jun 22nd, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace System;
  5. using namespace std;
  6. void genera_y_muestra_matriz(int m1[20][23])
  7. {
  8.     int xx=0, yy=0;
  9.     Console::BackgroundColor = ConsoleColor::Black;
  10.     for (int f = 0;f < 20;f++)
  11.     {
  12.         Console::SetCursorPosition(xx, yy);
  13.         for (int c = 0;c < 23;c++)
  14.         {
  15.             switch (m1[f][c])
  16.             {
  17.             case 1:
  18.                 Console::BackgroundColor = ConsoleColor::DarkRed;
  19.                 cout << char(32);
  20.                 ;break;
  21.             case 0:
  22.                 Console::BackgroundColor = ConsoleColor::DarkGray;
  23.                 cout << char(32);
  24.                 ;break;
  25.             }
  26.        
  27.         }
  28.         yy++;
  29.     }
  30. }
  31. void dezpazar_movil(int m1[20][23])
  32. {
  33.     int rx = 15;
  34.     int ry = 9;
  35.     int tecla;
  36.  
  37.     int ex=11;
  38.     int ey=1;
  39.     int edelx=1;
  40.  
  41.     while (1)
  42.     {
  43.         Console::SetCursorPosition(rx, ry);
  44.         cout << "*";
  45.         if (kbhit())
  46.         {
  47.             tecla = _getch();
  48.             if (tecla == 224)
  49.             {
  50.                 Console::SetCursorPosition(rx, ry);
  51.                 Console::BackgroundColor = ConsoleColor::DarkGray;
  52.                 cout << " ";
  53.                 tecla = _getch();
  54.                 switch (tecla)
  55.                 {
  56.                 case 72:ry--;
  57.                     if (ry < 0)
  58.                     {
  59.                         rx = 15;
  60.                         ry = 9;
  61.                     };break;
  62.                 case 75:rx--;
  63.                     if (rx < 0)
  64.                     {
  65.                         rx = 15;
  66.                         ry = 9;
  67.                     };break;
  68.                 case 77:rx++;
  69.                     if (rx > 22)
  70.                     {
  71.                         rx = 15;
  72.                         ry = 9;
  73.                     };break;
  74.                 case 80:ry++;
  75.                     if (ry > 19)
  76.                     {
  77.                         rx = 15;
  78.                         ry = 9;
  79.                     };break;
  80.                 }
  81.                 Console::SetCursorPosition(rx, ry);
  82.                 Console::BackgroundColor = ConsoleColor::DarkGray;
  83.                 cout << "*";
  84.             }
  85.         }
  86.  
  87.            
  88.         _sleep(50);
  89.         Console::BackgroundColor = ConsoleColor::DarkGray;
  90.         Console::SetCursorPosition(ex, ey);
  91.         Console::ForegroundColor = ConsoleColor::Black;
  92.         cout << char(1);
  93.  
  94.         Console::BackgroundColor = ConsoleColor::DarkGray;
  95.         Console::SetCursorPosition(ex, ey);
  96.         cout << " ";
  97.  
  98.         if (ex == 0)edelx = 1;
  99.         if (ex == 22)edelx = -1;
  100.         ex = ex + edelx;
  101.  
  102.         Console::SetCursorPosition(ex, ey);
  103.         cout << char(1);
  104.  
  105.         if (rx == ex&&ry == ey)
  106.         {
  107.             rx = 15;
  108.             ry = 9;
  109.         }
  110.     }
  111. }
  112. int main()
  113. {
  114.     int mapa1[20][23] =
  115.     {
  116.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  117.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  118.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  119.         {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  120.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  121.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  122.         {0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0},
  123.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  124.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  125.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  126.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  127.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  128.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  129.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  130.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  131.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
  132.         {0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  133.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  134.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  135.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  136.     };
  137.     genera_y_muestra_matriz(mapa1);
  138.     dezpazar_movil(mapa1);
  139.     _getch();
  140.     return 0;
  141. }
Add Comment
Please, Sign In to add comment