diff --git a/gamedata.cpp b/gamedata.cpp index 4c084d9..1e2c074 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -101,6 +101,16 @@ void GameData::handle_click(int x, int y) if (current == NULL) return; int dist = MathUtils::distance(current->x, current->y, current->z, x, y, 0); + + Vertex* temp = new Vertex(x, y, 0, NODE_RADIUS); + if (crosses_edge(current, temp) || + vertex_would_overlap(x, y, 0, NODE_RADIUS)) + { + delete temp; + return; + } + delete temp; + if (dist <= get_range()) { if (turn->spend_energy(dist)) diff --git a/graph.h b/graph.h index 6755451..d1de18f 100644 --- a/graph.h +++ b/graph.h @@ -42,10 +42,10 @@ class Graph protected: list vertices; + bool crosses_edge(Vertex* a, Vertex* b); + bool vertex_would_overlap(int x, int y, int z, int r); private: - bool vertex_would_overlap(int x, int y, int z, int r); - bool crosses_edge(Vertex* a, Vertex* b); bool planar; };