Start using dynamic_casts where appropriate, cleaned up some bugs

This commit is contained in:
Anna Rose 2011-07-01 23:24:41 -04:00
parent 2bdc7e0e59
commit 306f3d0c17
5 changed files with 10 additions and 12 deletions

View File

@ -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<GameVertex*>(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)),

View File

@ -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<GameVertex*>(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<GameVertex*>(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<GameVertex*>(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<GameVertex*>(current)->player == turn) mode = m;
}

View File

@ -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);

View File

@ -7,6 +7,8 @@
using std::list;
Vertex::~Vertex() {}
Graph::Graph(bool planar)
{
this->planar = planar;

View File

@ -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;