From 306f3d0c170a0ba4ddaa1d480ad368b72e8f9312 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 1 Jul 2011 23:24:41 -0400 Subject: [PATCH] Start using dynamic_casts where appropriate, cleaned up some bugs --- game.cpp | 1 + gamedata.cpp | 16 +++++----------- gamedata.h | 2 +- graph.cpp | 2 ++ graph.h | 1 + 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/game.cpp b/game.cpp index 87691bf..8629824 100644 --- a/game.cpp +++ b/game.cpp @@ -122,6 +122,7 @@ void Game::draw_stats(Vertex* v) int y = display->h - (num_lines * 14) - 20; DrawUtils::draw_text(display, "player:", x, y, font); + DrawUtils::draw_text(display, dynamic_cast(v)->player->get_name(), x + 50, y, font); DrawUtils::draw_text(display, "str:", x, y + 14, font); DrawUtils::draw_text(display, itos(data.calculate_strength(v)), diff --git a/gamedata.cpp b/gamedata.cpp index 718ddc3..b687142 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -41,7 +41,7 @@ Vertex* GameData::get_current_vertex(bool only_mine) const if (only_mine) { if (current != NULL && - current->colour == turn->get_colour()) return current; + dynamic_cast(current)->player == turn) return current; return NULL; } @@ -93,23 +93,17 @@ void GameData::handle_click(int x, int y) else if (mode == MODE_ATTACK) { Vertex* v = vertex_at(x, y, 0); - if (v == NULL || v->colour == turn->get_colour()) return; + if (v == NULL || dynamic_cast(v)->player == turn) return; if (v->colour != colour) attack_vertex(v); } } -bool GameData::select_vertex(int x, int y, bool only_mine) +bool GameData::select_vertex(int x, int y) { Vertex * v = vertex_at(x, y, 0); if (v == NULL) return false; - if (only_mine && v->colour == turn->get_colour()) - { - current = v; - return true; - } - current = v; return true; } @@ -141,7 +135,7 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour) } // same here - just a logic check - if (current->colour != turn->get_colour()) + if (dynamic_cast(current)->player != turn) { delete v; return false; @@ -243,7 +237,7 @@ void GameData::set_mode(Mode m) if (current == NULL) return; // The other modes all require current to match the player - if (current->colour == turn->get_colour()) mode = m; + if (dynamic_cast(current)->player == turn) mode = m; } diff --git a/gamedata.h b/gamedata.h index 132fe9d..93057ec 100644 --- a/gamedata.h +++ b/gamedata.h @@ -35,7 +35,7 @@ class GameData : public Graph // select or add vertex, as appropriate void handle_click(int x, int y); - bool select_vertex(int x, int y, bool only_mine = false); + bool select_vertex(int x, int y); void attack_vertex(Vertex* target); bool add_vertex(int x, int y, int z, int r, int colour); diff --git a/graph.cpp b/graph.cpp index 31f3b43..25b2dda 100644 --- a/graph.cpp +++ b/graph.cpp @@ -7,6 +7,8 @@ using std::list; +Vertex::~Vertex() {} + Graph::Graph(bool planar) { this->planar = planar; diff --git a/graph.h b/graph.h index 50c93f6..59a7da3 100644 --- a/graph.h +++ b/graph.h @@ -25,6 +25,7 @@ class Vertex { public: Vertex(int x, int y, int z, int r, int colour = 0, int score = 0); + virtual ~Vertex(); int x; int y;