Start using dynamic_casts where appropriate, cleaned up some bugs
This commit is contained in:
parent
2bdc7e0e59
commit
306f3d0c17
1
game.cpp
1
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<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)),
|
||||
|
|
16
gamedata.cpp
16
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<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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
using std::list;
|
||||
|
||||
Vertex::~Vertex() {}
|
||||
|
||||
Graph::Graph(bool planar)
|
||||
{
|
||||
this->planar = planar;
|
||||
|
|
Loading…
Reference in New Issue
Block a user