-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapa.cpp
127 lines (105 loc) · 2.07 KB
/
mapa.cpp
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
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <stdlib.h>
#include "mapa.h"
Mapa::Mapa()
{
setTam(10 + (rand() % 10));
setNome("Mundo random");
casas = new Casa[getTam() * getTam()];
CriaMuro();
GeraSaida();
GeraEntrada();
}
Mapa::Mapa(std::string nome, int tam)
{
setNome(nome);
setTam(tam);
casas = new Casa[tam *tam];
CriaMuro();
GeraSaida();
GeraEntrada();
}
void Mapa::GeraSaida()
{
int ind = 1 + ( rand() % (getTam() - 3));
Posicao saida(ind, getTam() - 1);
setPosSaida(saida);
int x = getPosSaida().getX();
int y = getPosSaida().getY();
int pos = ind * getTam() + (getTam() - 1);
getCasa()[pos].setSprite(SAIDA_SPRITE);
getCasa()[pos].setTipo(SAIDA_TIPO);
}
void Mapa::GeraEntrada()
{
int ind = 1 + ( rand() % (getTam() - 3));
Posicao entrada(ind, 0);
setPosEntrada(entrada);
int x = getPosEntrada().getX();
int y = getPosEntrada().getY();
int pos = ind * getTam() + 0;
getCasa()[pos].setSprite(ENTRADA_SPRITE);
getCasa()[pos].setTipo(ENTRADA_TIPO);
}
void Mapa::CriaMuro()
{
for (int j = 0; j < tam; j++)
{
// Primeira linha
getCasa()[j].setSprite(MURO_SPRITE);
getCasa()[j].setTipo(MURO_TIPO);
// Última linha
getCasa()[(tam - 1) * tam + j].setSprite(MURO_SPRITE);
getCasa()[(tam - 1) * tam + j].setTipo(MURO_TIPO);
// Coluna direita
getCasa()[tam * j + (tam - 1)].setSprite(MURO_SPRITE);
getCasa()[tam * j + (tam - 1)].setTipo(MURO_TIPO);
// Coluna esquerda
getCasa()[tam * j ].setSprite(MURO_SPRITE);
getCasa()[tam * j ].setTipo(MURO_TIPO);
}
}
bool Mapa::CheckSaida(Posicao posHeroi)
{
if (posHeroi.Compara(posSaida))
{
return true;
}
}
/* Get's e set's */
std::string Mapa::getNome()
{
return this->nome;
}
void Mapa::setNome(std::string nome)
{
this->nome = nome;
}
int Mapa::getTam()
{
return tam;
}
void Mapa::setTam(int tam)
{
this->tam = tam;
}
Casa * Mapa::getCasa()
{
return casas;
}
Posicao Mapa::getPosSaida()
{
return this->posSaida;
}
void Mapa::setPosSaida(Posicao pos)
{
this->posSaida = pos;
}
Posicao Mapa::getPosEntrada()
{
return posEntrada;
}
void Mapa::setPosEntrada(Posicao pos)
{
this->posEntrada = pos;
}