Advertisement
AgustinMayta

Clase casi final

Jun 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 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_mapa(int m1[20][20])
  7. {
  8.     int xx, yy;
  9.     for (int f = 0;f < 20;f++)
  10.     {
  11.         Console::SetCursorPosition(xx, yy);
  12.         for (int c = 0;c < 20;c++)
  13.         {
  14.             switch (m1[f][c])
  15.             {
  16.             case 0:Console::BackgroundColor = ConsoleColor::White;
  17.                 cout << " ";
  18.                 break;
  19.             case 1:Console::BackgroundColor = ConsoleColor::Black;
  20.                 cout << " ";
  21.                 break;
  22.             }
  23.         }
  24.         yy++;
  25.     }
  26. }
  27. void dezplazar_movil(int m1[20][20])
  28. {
  29.     int px = 15, py = 9;
  30.     int ex = 11, ey = 4, delex = 1;
  31.     int tecla;
  32.     Console::ForegroundColor = ConsoleColor::Gray;
  33.     Console::SetCursorPosition(px, py);
  34.     cout << char(177);
  35.     Console::SetCursorPosition(px - 1, py + 1);
  36.     cout << char(177) << char(177) << char(177);
  37.     while (1)
  38.     {
  39.         if (kbhit())
  40.         {
  41.             tecla = _getch();
  42.             Console::BackgroundColor = ConsoleColor::White;
  43.             Console::SetCursorPosition(px, py);
  44.             cout << char(32);
  45.             Console::SetCursorPosition(px - 1, py + 1);
  46.             cout << char(32) << char(32) << char(32);
  47.             if (tecla == 224)
  48.             {
  49.                 tecla = _getch();
  50.                 switch (tecla)
  51.                 {
  52.                 case 72:
  53.                     if (m1[py - 1][px] == 1)
  54.                     {
  55.                         px = 15;
  56.                         py = 9;
  57.                     }
  58.                     else
  59.                         py--;
  60.                     break;
  61.                 case 75:
  62.                     if (m1[py][px - 2] == 1)
  63.                     {
  64.                         px = 15;
  65.                         py = 9;
  66.                     }
  67.                     else
  68.                         px--;
  69.                     break;
  70.                 case 77:
  71.                     if (m1[py][px + 2] == 1)
  72.                     {
  73.                         px = 15;
  74.                         py = 9;
  75.                     }
  76.                     else
  77.                         px++;
  78.                     break;
  79.                 case 80:
  80.                     if (m1[py + 2][px] == 1)
  81.                     {
  82.                         px = 15;
  83.                         py = 9;
  84.                     }
  85.                     else
  86.                         py++;
  87.                     break;
  88.                 }
  89.                 Console::ForegroundColor = ConsoleColor::Gray;
  90.                 Console::SetCursorPosition(px, py);
  91.                 cout << char(177);
  92.                 Console::SetCursorPosition(px - 1, py + 1);
  93.                 cout << char(177) << char(177) << char(177);
  94.             }
  95.         }
  96.         /*--------------------------------------------------*/
  97.         Console::BackgroundColor = ConsoleColor::White;
  98.         Console::SetCursorPosition(px, py);
  99.         cout << char(32);
  100.         Console::SetCursorPosition(px - 1, py + 1);
  101.         cout << char(32) << char(32) << char(32);
  102.  
  103.         if ((px == ex && py == ey) || (px - 1 == ex && py + 1 == ey) || (px + 1 == ex && py + 1 == ey))
  104.         {
  105.             px = 15;
  106.             py = 9;
  107.         }
  108.         Console::ForegroundColor = ConsoleColor::Gray;
  109.         Console::SetCursorPosition(px, py);
  110.         cout << char(177);
  111.         Console::SetCursorPosition(px - 1, py + 1);
  112.         cout << char(177) << char(177) << char(177);
  113.         _sleep(50);
  114.         /*--------------------------------------------------*/
  115.         Console::ForegroundColor = ConsoleColor::Black;
  116.         Console::SetCursorPosition(ex, ey);
  117.         cout << char(1);
  118.  
  119.         Console::ForegroundColor = ConsoleColor::White;
  120.         Console::SetCursorPosition(ex, ey);
  121.         cout << char(32);
  122.         if (ex == 1) delex = 1;
  123.         if (ex == 18) delex = -1;
  124.         ex = ex + delex;
  125.  
  126.         Console::ForegroundColor = ConsoleColor::Black;
  127.         Console::SetCursorPosition(ex, ey);
  128.         cout << char(1);
  129.     }
  130. }
  131. int main()
  132. {
  133.     int m1[20][20] =
  134.     {
  135.         {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  136.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  137.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  138.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  139.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  140.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  141.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  142.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  143.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  144.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  145.  
  146.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  147.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  148.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  149.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  150.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  151.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  152.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  153.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  154.         {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  155.         {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
  156.     };
  157.     genera_y_muestra_mapa(m1);
  158.     dezplazar_movil(m1);
  159.     _getch();
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement