-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAliado.h
More file actions
117 lines (102 loc) · 2.69 KB
/
Copy pathAliado.h
File metadata and controls
117 lines (102 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef ALIADO_H
#define ALIADO_H
#include "Funciones.h"
#include <iostream>
class Aliado
{
private:
int x, y; // Coordenadas del aliado
static constexpr int ANCHO = 4;
static constexpr int ALTO = 4;
bool visible = true; // Indica si el aliado está visible
bool esAliadoDeVida; // Nuevo atributo para identificar el tipo de aliado
// Matriz que representa al aliado
const int aliado[4][4] = {
{1, 1, 1, 1},
{1, 2, 2, 1},
{2, 3, 3, 2},
{0, 1, 1, 0}
};
// Obtiene el color según el valor de la matriz
int obtenerColor(int valor) const
{
if (esAliadoDeVida) // Verifica si es el aliado de vida
{
switch (valor)
{
case 0: return 0;
case 1: return 4;
case 2: return 14;
case 3: return 12;
default: return 7;
}
}
else
{
switch (valor)
{
case 0: return 0;
case 1: return 2;
case 2: return 14;
case 3: return 10;
default: return 7;
}
}
}
public:
Aliado(int startX, int startY, bool esDeVida = false)
: x(startX), y(startY), esAliadoDeVida(esDeVida)
{
}
// Dibuja el aliado en la consola
void dibujar() const
{
if (!visible) return; // No dibujar si está oculto
for (int i = 0; i < ALTO; ++i)
{
for (int j = 0; j < ANCHO; ++j)
{
gotoxy(x + j, y + i);
int colorValor = obtenerColor(aliado[i][j]);
color(colorValor);
std::cout << CUBO;
}
}
color(7);
}
void ocultar()
{
borrar();
visible = false;
}
bool estaVisible() const { return visible; }
// Borra el aliado de la consola
void borrar() const
{
for (int i = 0; i < ALTO; ++i)
{
for (int j = 0; j < ANCHO; ++j)
{
gotoxy(x + j, y + i);
std::cout << ' ';
}
}
}
// Detecta colisión con el personaje
bool colisionaCon(int personajeX, int personajeY, int personajeAncho, int personajeAlto) const
{
return x < personajeX + personajeAncho &&
x + ANCHO > personajeX &&
y < personajeY + personajeAlto &&
y + ALTO > personajeY;
}
// Obtiene la posición X
int getX() const { return x; }
// Obtiene la posición Y
int getY() const { return y; }
// Obtiene el ancho
int getAncho() const { return ANCHO; }
// Obtiene el alto
int getAlto() const { return ALTO; }
};
#endif // ALIADO_H