Xavistian

Juego

Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. // ConsoleApplication6.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_muestra_matrix(int Matriz[][23])
  10. {
  11.     for (int i = 0; i < 20; i++)
  12.     {
  13.         for (int j = 0;j < 23; j++)
  14.         {
  15.             switch (Matriz[i][j])
  16.             {
  17.             case 0:Console::BackgroundColor = ConsoleColor::DarkRed;
  18.                 Console::ForegroundColor = ConsoleColor::White;
  19.                 cout << (char)22;break;
  20.             case 1:
  21.                
  22.                 Console::BackgroundColor = ConsoleColor::White;
  23.                 Console::ForegroundColor = ConsoleColor::Black;
  24.                 cout << (char)219;break;
  25.             }
  26.         }cout << endl;
  27.     }
  28. }
  29. void desplazar_movil_y_enemigo(int Matrix[][23], int my, int mx)
  30. {
  31.     int tecla, my, mx;
  32.     int my = 8; mx = 10;
  33.     int ex = 19, ey = 6, dey = 1;
  34.     Console::SetCursorPosition(ex, ey);
  35.     Console::BackgroundColor = ConsoleColor::Black;
  36.     cout << (char)1;
  37.     while (1)
  38.     {
  39.         if (kbhit())
  40.         {
  41.             tecla = _getch();
  42.             if (tecla == 224)
  43.             {
  44.                 Console::SetCursorPosition(mx, my);
  45.                 cout << " ";
  46.                 tecla = _getch();
  47.                 switch (tecla)
  48.                 {
  49.                 case 77:mx++; if (Matrix[my][mx] == 0)
  50.                     Console::SetCursorPosition(mx, my);break;
  51.                 case 75:mx--; if (Matrix[my][mx]==0)
  52.                     Console::SetCursorPosition(mx, my);break;
  53.                 case 72:my--; if (Matrix[my][mx] == 0)
  54.                     Console::SetCursorPosition(mx, my);break;
  55.                 case 80:my++; if (Matrix[my][mx] == 0)
  56.                     Console::SetCursorPosition(mx, my);break;
  57.                 }
  58.             }Console::SetCursorPosition(mx, my);cout << '*';
  59.         }
  60.         _sleep(75);
  61.         Console::SetCursorPosition(ex, ey);
  62.         cout << ' ';
  63.         if (ey == 3 || ey == 8)
  64.             dey *= -1;
  65.         ey += dey;
  66.         Console::SetCursorPosition(ex, ey);
  67.         cout << (char)1;
  68.     }
  69.  
  70. }
  71. int main()
  72. {
  73.     int Matrix[20][23]=
  74.     {
  75.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  76.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  77.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  78.     { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },
  79.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  80.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  81.     { 0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0 },
  82.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  83.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  84.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  85.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  86.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  87.     { 0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0 },
  88.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  89.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  90.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  91.     { 0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0 },
  92.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  93.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  94.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },};
  95.     genera_muestra_matrix(Matrix);
  96.     desplazar_movil_y_enemigo(Matrix, 8,10);
  97.     return 0;
  98. }
Add Comment
Please, Sign In to add comment