Xavistian

Ejercicio examen final juego

Jun 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. // ConsoleApplication7.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_y_muestra_matriz(int Matriz[20][23])
  10. {
  11.     Console::BackgroundColor = ConsoleColor::White;
  12.     Console::ForegroundColor = ConsoleColor::DarkGray;
  13.     for (int i = 0; i < 20; i++)
  14.     {
  15.         for (int j = 0; j < 23; j++)
  16.         {
  17.             if (Matriz[i][j] == 1) cout << (char)219; else cout << ' ';
  18.         }cout << endl;
  19.     }
  20. }
  21.  
  22. void desplazar_movil(int Matriz[20][23])
  23. {
  24.     int ey=1, ex=11, dex=1;
  25.     int py = 9, px = 15;
  26.     int key;
  27.     while (1)
  28.     {
  29.         if (kbhit())
  30.         {
  31.             key = _getch();
  32.             if (key == 224)
  33.             {
  34.                 Console::SetCursorPosition(px, py);
  35.                 cout << ' ';
  36.                 key = _getch();
  37.                 switch (key)
  38.                 {
  39.                 case 72:if (py - 1 < 0) { px = 15; py = 9;} else py--;break;
  40.                 case 75:if (px -1<0) { px = 15; py = 9; } else px--;break;
  41.                 case 77:if (px+1>22) { px = 15; py = 9; }else px++;break;
  42.                 case 80:if(py+1>19) { px = 15; py = 9; } else py++;break;
  43.                 }
  44.  
  45.             }Console::SetCursorPosition(px, py); cout << '*';
  46.         }
  47.         _sleep(20);
  48.         Console::SetCursorPosition(ex, ey);
  49.         cout << ' ';
  50.         if (ex == 22 || ex == 0)
  51.             dex *= -1;
  52.         ex += dex;
  53.         Console::SetCursorPosition(ex, ey);
  54.         cout << (char)1;
  55.         if (ex == px&&ey == py) { px = 15; py = 9; }
  56.        
  57.  
  58.     }
  59. }
  60. int main()
  61. {
  62.     int Matriz[20][23] = {
  63.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  64.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  65.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  66.     { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },
  67.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  68.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  69.     { 0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0 },
  70.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  71.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  72.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  73.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  74.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  75.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  76.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  77.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  78.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  79.     { 0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0 },
  80.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  81.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  82.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, };
  83.     genera_y_muestra_matriz(Matriz);
  84.     desplazar_movil(Matriz);
  85.     _getch();
  86.     return 0;
  87. }
Add Comment
Please, Sign In to add comment