Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication8.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- struct Enemigos
- {
- int x;
- int y;
- int dex;
- };
- void DibujaMatriz(int matriz[20][20])
- {
- Console::BackgroundColor = ConsoleColor::White;
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 20; j++)
- {
- if (matriz[i][j] == 1)
- {
- Console::ForegroundColor=ConsoleColor::Black;
- cout << (char)219;
- }
- else cout << ' ';
- }cout << endl;
- }
- }
- void MoverEnemigoyMovil(int matriz[20][20])
- {
- Enemigos *enemigo = new Enemigos[3];
- enemigo[0].x = 3, enemigo[1].x = 3, enemigo[2].x = 3, enemigo[0].y = 5, enemigo[1].y = 10, enemigo[2].y = 15, enemigo[0].dex = 1, enemigo[1].dex = -1, enemigo[2].dex = 1;
- int px = 10, py = 18;
- int key;
- bool out = 1;
- Console::SetCursorPosition(px, py);
- cout << 'J';
- Console::SetCursorPosition(enemigo[0].x, enemigo[0].y);
- cout << '*';
- Console::SetCursorPosition(enemigo[1].x, enemigo[1].y);
- cout << '*';
- Console::SetCursorPosition(enemigo[2].x, enemigo[2].y);
- cout << '*';
- while (out == 1)
- {
- if (kbhit())
- {
- key = _getch();
- if (key == 224)
- {
- Console::SetCursorPosition(px, py);
- cout << ' ';
- key = _getch();
- switch (key)
- {
- case 72:if (matriz[py - 1][px] == 0 || matriz[py - 1][px] == 2)py--;break;
- case 75:if (matriz[py][px - 1] == 0 || matriz[py][px - 1] == 2)px--;break;
- case 77:if (matriz[py][px + 1] == 0 || matriz[py][px + 1] == 2)px++;break;
- case 80:if (matriz[py + 1][px] == 0 || matriz[py + 1][px] == 2)py++;break;
- }
- }Console::SetCursorPosition(px, py); cout << 'J';
- }
- _sleep(50);
- Console::SetCursorPosition(enemigo[0].x, enemigo[0].y);
- cout << ' ';
- Console::SetCursorPosition(enemigo[1].x, enemigo[1].y);
- cout << ' ';
- Console::SetCursorPosition(enemigo[2].x, enemigo[2].y);
- cout << ' ';
- if (enemigo[0].x == 1 || enemigo[0].x == 18) enemigo[0].dex *= -1;
- enemigo[0].x += enemigo[0].dex;
- if (enemigo[1].x == 1 || enemigo[1].x == 18) enemigo[1].dex *= -1;
- enemigo[1].x += enemigo[1].dex;
- if (enemigo[2].x == 1 || enemigo[2].x == 18) enemigo[2].dex *= -1;
- enemigo[2].x += enemigo[2].dex;
- Console::SetCursorPosition(enemigo[0].x, enemigo[0].y);
- cout << '*';
- Console::SetCursorPosition(enemigo[1].x, enemigo[1].y);
- cout << '*';
- Console::SetCursorPosition(enemigo[2].x, enemigo[2].y);
- cout << '*';
- if (enemigo[0].x == px&&enemigo[0].y == py || enemigo[1].x == px&&enemigo[1].y == py || enemigo[2].x == px&&enemigo[2].y == py)
- {
- px = 10;
- py = 18;
- Console::SetCursorPosition(px, py);
- cout << 'J';
- }
- if (matriz[py][px] == 2) out = 0;
- }
- Console::SetCursorPosition(2, 10);
- cout << "A WINNER IS YOU!";
- }
- int main()
- {
- int matriz[20][20] = {
- {1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- };
- DibujaMatriz(matriz);
- MoverEnemigoyMovil(matriz);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment