Code for some of the basic game design - selecting existing nodes, limiting edge distance
This commit is contained in:
33
graph.cpp
33
graph.cpp
@ -11,7 +11,7 @@ using std::cerr;
|
||||
|
||||
Graph::Graph()
|
||||
{
|
||||
last_vertex = NULL;
|
||||
current_vertex = NULL;
|
||||
}
|
||||
|
||||
Graph::~Graph()
|
||||
@ -54,6 +54,29 @@ bool Graph::vertex_present(int x, int y, int size)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Graph::do_vertex(int x, int y, int size)
|
||||
{
|
||||
if (vertex_present(x, y, size)) select_vertex(x, y);
|
||||
else add_vertex(x, y, size);
|
||||
}
|
||||
|
||||
|
||||
void Graph::select_vertex(int x, int y)
|
||||
{
|
||||
for (list<Vertex*>::iterator cursor = vertices.begin();
|
||||
cursor != vertices.end(); cursor++)
|
||||
{
|
||||
Vertex* v = *cursor;
|
||||
if (x >= v->x_min && x <= v->x_max && y >= v->y_min && y <= v->y_max)
|
||||
{
|
||||
current_vertex = v;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Graph::add_vertex(int x, int y, int size)
|
||||
{
|
||||
Vertex* v = new Vertex();
|
||||
@ -69,17 +92,17 @@ void Graph::add_vertex(int x, int y, int size)
|
||||
|
||||
vertices.push_back(v);
|
||||
|
||||
if (last_vertex == NULL)
|
||||
if (current_vertex == NULL)
|
||||
{
|
||||
last_vertex = v;
|
||||
current_vertex = v;
|
||||
return;
|
||||
}
|
||||
|
||||
Edge e;
|
||||
e.a = last_vertex;
|
||||
e.a = current_vertex;
|
||||
e.b = v;
|
||||
edges.push_back(e);
|
||||
last_vertex = v;
|
||||
current_vertex = v;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user