treewars/graph.h

62 lines
1.0 KiB
C
Raw Normal View History

/* Represents an undirected graph.
* Also contains the vertex and edge classes
* vertexes know their center point on the SDL Surface -
* bad decoupling maybe, but not too bad, all things considered
*/
#ifndef _GRAPH_H_
#define _GRAPH_H_
#include <list>
using std::list;
class Vertex
{
public:
Vertex(int x, int y)
{ this->x = x; this->y = y; }
int x;
int y;
int x_min;
int x_max;
int y_min;
int y_max;
static float distance(Vertex a, Vertex b);
};
struct Edge
{
Vertex* a;
Vertex* b;
};
class Graph
{
public:
Graph();
~Graph();
bool vertex_present(int x, int y, int size);
list<Vertex*> get_vertices() { return vertices; }
list<Edge> get_edges() { return edges; }
void do_vertex(int x, int y, int size);
Vertex* get_current_vertex() { return current_vertex; }
static int MAX_MOVE_DISTANCE;
private:
void add_vertex(int x, int y, int size);
void select_vertex(int x, int y);
Vertex* current_vertex;
list<Vertex*> vertices;
list<Edge> edges;
};
#endif