Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- int vidas = 3;
- int matrizInicio[20][75] = {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,1,0,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0,1,1,0,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- };
- void imprimirmatriz() {
- Console::Clear();
- for (int i = 0; i < 20; i++){
- for (int j = 0; j < 75; j++){
- if (matrizInicio[i][j] == 0) {
- cout << " ";
- }
- if (matrizInicio[i][j] == 1) {
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << char(219);
- }
- }
- cout << "\n";
- }
- }
- void dibujarJugado(int &x, int &y) {
- Console::SetCursorPosition(x, y);
- Console::ForegroundColor = ConsoleColor::Red;
- cout << char(12);
- }
- void EliminarJugador(int &x, int&y) {
- Console::SetCursorPosition(x, y);
- cout << " ";
- }
- void dibujarEnemigo(int &ex, int &ey) {
- Console::SetCursorPosition(ex, ey);
- Console::ForegroundColor = ConsoleColor::Green;
- cout << char(2);
- }
- void EliminarEnemigo(int &ex, int&ey) {
- Console::SetCursorPosition(ex, ey);
- cout << " ";
- }
- void moverEnemigo(int &ex, int &dx) {
- ex = ex + dx;
- if (ex == 6 || ex == 79) {
- dx *= -1;
- }
- }
- void dibujarBala(int xbala, int ybala) {
- Console::SetCursorPosition(xbala, ybala);
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << "*";
- }
- void eliminarBala(int xbala, int ybala) {
- Console::SetCursorPosition(xbala, ybala);
- cout << " ";
- }
- void hacerJugador( int &x , int &y, int &ex, int &ey, int &dx) {
- char tecla = -1;
- int xbala = 6, ybala = 5, dybala = 1;
- Random r;
- dibujarJugado(x, y);
- dibujarEnemigo(ex, ey);
- int disparar;
- while (true) {
- Console::SetCursorPosition(3, 1);//vidas
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << "Vidas: " << vidas ;
- if (ybala == 27) {
- disparar = r.Next(19, 66);
- }
- _sleep(40);
- EliminarEnemigo(ex, ey);
- eliminarBala(xbala, ybala);
- if (kbhit()) {
- tecla = getch();
- tecla = toupper(tecla);
- EliminarJugador(x, y);
- switch (tecla) {
- case 'W': y--; break;
- case 'S': y++; break;
- case 'A': x--; break;
- case 'D': x++; break;
- }
- dibujarJugado(x, y);
- }
- //Mover Bala
- if (ybala < 27) {
- ybala += dybala;
- }
- if (ex == disparar) {
- xbala = ex;
- ybala = ey + 1;
- Console::SetCursorPosition(xbala, ybala);
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << "*";
- }
- dibujarBala(xbala, ybala);
- moverEnemigo(ex, dx);
- dibujarEnemigo(ex, ey);
- if (xbala == x && ybala == y) {
- vidas--;
- }
- if (vidas == 0) {
- exit(0);
- }
- }
- }
- int main() {
- int x = 41, y =15; //jugador
- int ex = 6, ey = 5, dx=1; //enemigo
- Console::CursorVisible = false;
- while (1) {
- imprimirmatriz();
- hacerJugador(x, y, ex, ey, dx);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement