-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphMap.hpp
More file actions
147 lines (119 loc) · 2.7 KB
/
GraphMap.hpp
File metadata and controls
147 lines (119 loc) · 2.7 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* GraphMap.hpp
*
* Created on: Mar 7, 2014
* Author: stolee
*/
#ifndef GRAPHMAP_HPP_
#define GRAPHMAP_HPP_
#include <stdio.h>
#define SPECIAL_HERO_SPAWN 1
#define SPECIAL_ENEMY_SPAWN 2
#define SPECIAL_EATABLE_SPAWN 4
#define SPECIAL_POWERUP_SPAWN 8
class GameManager;
class Melee;
/**
* The Graph class contains a simple data structure for reading from a (directed) graph.
*
* It is limited to only storing out-edges and out-degree information.
*
* This graph is also used to store the 2D map.
*/
class GraphMap
{
/**
* Give GameManager special privileges to access protected members of GraphMap.
*/
friend class GameManager;
friend class Melee;
protected:
int num_vertices;
int* vertex_x;
int* vertex_y;
int** xy_vertex;
int* out_degrees;
int** out_edges;
bool toroidal;
void initGraph( int w, int h );
void addEdge( int x, int y, int a, int b );
int w;
int h;
int size_special;
int num_special;
int* special_vertices;
int* special_types;
int size_actors;
int num_actors;
int* actor_positions;
int* actor_types;
int delay_hero;
int delay_eatable;
int delay_powerup;
int delay_enemy;
/**
* Modify the actors, used by GameManager
*/
int addActor( int type, int x, int y );
bool moveActor( int actor, int x, int y, bool force );
int setActorType( int i, int type );
/**
* Special positions, used by GameManager.
*/
int getNumSpecial();
int getSpecialType( int i );
int** map_chars;
int getMapChar( int x, int y );
public:
GraphMap(const GraphMap& map);
/**
* Load a graph from a file, using the game-board format.
*/
GraphMap( FILE* f );
/**
* Destructor
*/
virtual ~GraphMap();
/**
* Returns the number of vertices in the graph.
*/
int getNumVertices();
/**
* Returns the number of out-neighbors for the position (x,y)
*/
int getNumNeighbors( int x, int y );
/**
* Assigns the value of the ith neighbor of (x,y) to (a,b).
*/
void getNeighbor( int x, int y, int i, int& a, int& b );
/**
* Returns the number of actors in the map.
*
* All actors are stored in an array, and this gives the length of the array.
*/
int getNumActors();
/**
* Returns the type int for the ith actor.
*/
int getActorType( int i );
/**
* Given an actor index i, assigns (x,y) to be the position.
*/
void getActorPosition( int i, int& x, int& y );
inline int getWidth()
{
return this->w;
}
inline int getHeight()
{
return this->h;
}
int getVertex( int x, int y );
void getPosition( int v, int& x, int& y );
int getDelayHero();
int getDelayEnemy();
int getDelayEatable();
int getDelayPowerup();
void print();
};
#endif /* GRAPH_HPP_ */