From 7fd7f9077090df743fcd43935f9231cd0fe77200 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 1 Jul 2011 14:39:45 -0400 Subject: [PATCH] Fixed the selection bugs --- gamedata.cpp | 10 ++++++---- gamedata.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gamedata.cpp b/gamedata.cpp index 1feca5f..7ed9109 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -72,10 +72,11 @@ void GameData::handle_click(int x, int y) else if (mode == MODE_BUILD) { if (point_in_vertex(x, y, 0)) select_vertex(x, y, true); - if (!point_in_vertex(x, y, 0)) add_vertex(x, y, 0, r, colour); + else add_vertex(x, y, 0, r, colour); } else if (mode == MODE_ATTACK) { + if (select_vertex(x, y, true)) return; Vertex* v = vertex_at(x, y, 0); if (v == NULL) return; if (v->colour != colour) attack_vertex(v); @@ -83,18 +84,19 @@ void GameData::handle_click(int x, int y) } -void GameData::select_vertex(int x, int y, bool only_mine) +bool GameData::select_vertex(int x, int y, bool only_mine) { Vertex * v = vertex_at(x, y, 0); - if (v == NULL) return; + if (v == NULL) return false; if (only_mine && v->colour == turn->get_colour()) { current = v; - return; + return true; } current = v; + return true; } diff --git a/gamedata.h b/gamedata.h index 846608a..a80143b 100644 --- a/gamedata.h +++ b/gamedata.h @@ -32,7 +32,7 @@ class GameData : public Graph // select or add vertex, as appropriate void handle_click(int x, int y); - void select_vertex(int x, int y, bool only_mine = false); + bool select_vertex(int x, int y, bool only_mine = false); void attack_vertex(Vertex* target); bool add_vertex(int x, int y, int z, int r, int colour);