AgustinMayta

:(((((

Jun 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace System;
  5. using namespace std;
  6. struct posc
  7. {
  8.     int x;
  9.     int y;
  10.     int delx;
  11.     int dely;
  12. };
  13. void genera_muestra_matriz(int m1[20][23])
  14. {
  15.     int xx, yy;
  16.     Console::BackgroundColor = ConsoleColor::Black;
  17.     for (int f = 0; f < 20; f++)
  18.     {
  19.         Console::SetCursorPosition(xx, yy);
  20.         for(int c = 0; c < 23; c++)
  21.         {
  22.             switch (m1[f][c])
  23.             {
  24.             case 0:
  25.                 Console::ForegroundColor = ConsoleColor::DarkRed;
  26.                 cout << char(177);break;
  27.             case 1:
  28.                 Console::ForegroundColor = ConsoleColor::Gray;
  29.                 cout << char(219);break;
  30.             }
  31.         }
  32.     yy++;
  33.     }
  34. }
  35. void Dez_Player_Enem(int m1[20][23])
  36. {
  37.     int tecla;
  38.     posc * obj = new posc[2];
  39.     obj[0].x = 19;
  40.     obj[0].y = 4;
  41.     obj[0].dely = 1;
  42.  
  43.     obj[1].x = 10;
  44.     obj[1].y = 8;
  45.  
  46.     Console::BackgroundColor = ConsoleColor::Gray;
  47.     Console::SetCursorPosition(obj[0].x, obj[0].y);
  48.     cout << char(1);
  49.  
  50.     Console::SetCursorPosition(obj[1].x, obj[1].y);
  51.     Console::BackgroundColor = ConsoleColor::Gray;
  52.     cout << "*";
  53.     while (1)
  54.     {
  55.         _sleep(50);
  56.  
  57.         if (kbhit)
  58.         {
  59.             tecla = _getch();
  60.             if (tecla == 224)
  61.             {
  62.                 tecla = _getch();
  63.                 Console::SetCursorPosition(obj[1].x, obj[1].y);
  64.                 cout << " ";
  65.                 switch (tecla)
  66.                 {
  67.                 case 72: obj[1].y--;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
  68.                 case 75: obj[1].x--;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
  69.                 case 77: obj[1].x++;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
  70.                 case 80: obj[1].y++;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
  71.                 }
  72.                 Console::SetCursorPosition(obj[1].x, obj[1].y);
  73.                 Console::BackgroundColor = ConsoleColor::Gray;
  74.                 cout << "*";
  75.             }
  76.  
  77.         }
  78.        
  79.         Console::SetCursorPosition(obj[0].x, obj[0].y);
  80.         cout << " ";
  81.         if (obj[0].y == 3)
  82.             obj[0].dely = 1;
  83.         if (obj[0].y == 8)
  84.             obj[0].dely = -1;
  85.         obj[0].y = obj[0].y + obj[0].dely;
  86.         Console::SetCursorPosition(obj[0].x, obj[0].y);
  87.         cout << char(1);
  88.  
  89.        
  90.        
  91.     }
  92. }
  93. int main()
  94. {
  95.     int Mapa1[20][23]=
  96.     {
  97.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  98.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},   
  99.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},   
  100.         {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},   
  101.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},   
  102.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},   
  103.         {0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0},   
  104.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},   
  105.         {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},   
  106.         {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},   
  107.         {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},   
  108.         {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},   
  109.         {0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},   
  110.         {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},           
  111.         {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},           
  112.         {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},           
  113.         {0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},           
  114.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},                           
  115.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},                           
  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.     };
  118.     genera_muestra_matriz(Mapa1);
  119.     Dez_Player_Enem(Mapa1);
  120.     _getch();
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment