treewars/graph.h

59 lines
1.1 KiB
C++

/* 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, int r, int colour = 0x000000);
int x;
int y;
int r;
int colour;
};
struct Edge
{
Vertex* a;
Vertex* b;
};
class Graph
{
public:
Graph();
~Graph();
bool vertex_present(int x, int y, int size);
list<Vertex*> get_vertices() const { return vertices; }
list<Edge> get_edges() const { return edges; }
void select_vertex(int x, int y);
void do_vertex(int x, int y, int r, int colour);
Vertex* get_current_vertex() const { return current_vertex; }
void clear_current_vertex() { current_vertex = NULL; }
private:
void add_vertex(int x, int y, int r, int colour);
bool vertex_would_overlap(int x, int y, int r);
bool crosses_edge(Edge e);
Vertex* current_vertex;
list<Vertex*> vertices;
list<Edge> edges;
};
#endif