Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <conio.h>
- #include <iostream>
- #include "CJugador.h"
- using namespace std;
- using namespace System;
- // CJugador.h
- #pragma once
- #include "stdafx.h"
- class CJugador
- {
- private:
- int x, y, dx, col;
- char car;
- public:
- CJugador(int _x, int _y, int _col, int _dx, char _car);
- int getx();
- void setdx(int _dx);
- void Mostrar();
- void Ocultar();
- void Mover();
- ~CJugador();
- };
- // CJugador.cpp
- #include "stdafx.h"
- void CJugador::Mostrar()
- {
- Console::ForegroundColor = (ConsoleColor)col;
- Console::SetCursorPosition(x, y);
- cout << car;
- }
- void CJugador::Ocultar()
- {
- Console::SetCursorPosition(x, y);
- cout << ' ';
- }
- void CJugador::Mover()
- {
- x += dx;
- }
- CJugador::CJugador(int _x, int _y, int _dx, int _col, char _car)
- {
- x = _x; y = _y; dx = _dx; col = _col; car = _car;
- }
- void CJugador::setdx(int _dx) { dx = _dx; };
- int CJugador::getx() { return x; }
- CJugador::~CJugador()
- {}
- // Main.cpp
- #include "stdafx.h"
- int main()
- {
- Console::WindowHeight = 50;
- Console::WindowWidth = 100;
- Random x;
- CJugador ** Arreglo = new CJugador *[3];
- for (int i = 0; i < 3; i++)
- Arreglo[i] = new CJugador(5, 5 + 5 * i, x.Next(1, 14), x.Next(1, 4), (char)62 + i);
- /*CJugador*obj1 = new CJugador(5, 5, x.Next(1, 14), x.Next(1, 4), '@');
- CJugador*obj2 = new CJugador(5, 5, x.Next(1, 14), x.Next(1, 4), '*');
- CJugador*obj3 = new CJugador(5, 5, x.Next(1, 14), x.Next(1, 4), '#');*/
- bool jugar = true;
- for (int i = 0; i < 16; i++)
- {
- Console::SetCursorPosition(74, i);
- cout << '|';
- }
- for (int i = 0; i < 3; i++)
- Arreglo[i]->Mostrar();
- while (jugar)
- {
- _sleep(300);
- for (int i = 0; i < 3; i++)
- Arreglo[i]->Ocultar();
- for (int i = 0; i < 3; i++)
- Arreglo[i]->Mover();
- for (int i=0; i<3;i++)
- if (Arreglo[i]->getx()>=74)
- {
- jugar = false;
- Arreglo[i]->setdx(0);
- Arreglo[i]->Mostrar();
- }
- for (int i = 0; i < 3; i++)
- Arreglo[i]->Mostrar();
- }
- Console::SetCursorPosition(35, 20);
- cout << "Fin del juego";
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment