Xavistian

Untitled

Jun 4th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 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. void DibujaTablero(char Matriz[][5])
  9. {
  10.     Console::ForegroundColor= ConsoleColor::White;
  11.     Console::BackgroundColor = ConsoleColor::Black;
  12.     for (int i = 0; i < 5; i++)
  13.     {
  14.         for (int j = 0; j < 5; j++)
  15.         {
  16.             cout << Matriz[i][j];
  17.         }cout << endl;
  18.     }
  19. }
  20. void Juega(char Matriz[][5])
  21. {
  22.     int tecla;
  23.     int px, py;
  24.     px = 40; py = 20;
  25.     Console::SetCursorPosition(px, py);
  26.     while (1)
  27.     {
  28.         if (kbhit())
  29.         {
  30.             tecla = _getch();
  31.             if (tecla == 224)
  32.             {
  33.                 Console::SetCursorPosition(px, py);
  34.                 cout << " ";
  35.                 tecla = _getch();
  36.                 switch (tecla)
  37.                 {
  38.                 case 77: if (Matriz[py][px + 1] != 'M')px++; break;
  39.                 case 75: if (Matriz[py][px - 1] != 'M')px--; break;
  40.                 case 72: if (Matriz[py - 1][px] != 'M')py--; break;
  41.                 case 80: if (Matriz[py + 1][px] != 'M')py++; break;
  42.                 }
  43.             }Console::SetCursorPosition(px, py);
  44.             cout << "*";
  45.         }
  46.     }
  47. }
  48. int main()
  49. {
  50.     char Matriz[5][5] = { {'M','M','M','M','M'},{'M',' ',' ',' ','M'},{'M',' ',' ',' ','M'},{'M',' ',' ',' ','M'},{'M','M','M',' ','M'} };
  51.     DibujaTablero(Matriz);
  52.     Juega(Matriz);
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment