Continuing to refactor code to make room for larger features. Currently, attacking doesn't work
This commit is contained in:
parent
c49fdb8169
commit
bf151a928a
2
game.cpp
2
game.cpp
|
@ -151,5 +151,5 @@ void Game::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode)
|
||||||
if (sym == SDLK_a) data.set_mode(MODE_ATTACK);
|
if (sym == SDLK_a) data.set_mode(MODE_ATTACK);
|
||||||
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
|
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
|
||||||
if (sym == SDLK_b) data.set_mode(MODE_BUILD);
|
if (sym == SDLK_b) data.set_mode(MODE_BUILD);
|
||||||
if (sym == SDLK_s) data.set_mode(MODE_SELECT);
|
if (sym == SDLK_s || sym == SDLK_ESCAPE) data.set_mode(MODE_SELECT);
|
||||||
}
|
}
|
||||||
|
|
35
gamedata.cpp
35
gamedata.cpp
|
@ -42,19 +42,18 @@ Vertex* GameData::get_current_vertex(bool only_mine) const
|
||||||
|
|
||||||
void GameData::toggle_turn()
|
void GameData::toggle_turn()
|
||||||
{
|
{
|
||||||
if (!turn->has_played())
|
if (!turn->has_played()) turn->set_played();
|
||||||
{
|
|
||||||
set_mode(MODE_BUILD);
|
|
||||||
turn->set_played();
|
|
||||||
}
|
|
||||||
else set_mode(MODE_SELECT);
|
|
||||||
|
|
||||||
if (!endgame())
|
if (!endgame())
|
||||||
{
|
{
|
||||||
if (turn == &player1) turn = &player2;
|
if (turn == &player1) turn = &player2;
|
||||||
else if (turn == &player2) turn = &player1;
|
else if (turn == &player2) turn = &player1;
|
||||||
|
|
||||||
|
if (!turn->has_played()) mode = MODE_BUILD;
|
||||||
|
else mode = MODE_SELECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,12 +66,12 @@ void GameData::handle_click(int x, int y)
|
||||||
|
|
||||||
if (mode == MODE_SELECT)
|
if (mode == MODE_SELECT)
|
||||||
{
|
{
|
||||||
if (point_in_vertex(x, y, 0)) select_vertex(x, y);
|
// select_vertex handles making sure a point exists at (x,y)
|
||||||
|
select_vertex(x, y);
|
||||||
}
|
}
|
||||||
else if (mode == MODE_BUILD)
|
else if (mode == MODE_BUILD)
|
||||||
{
|
{
|
||||||
if (point_in_vertex(x, y, 0)) select_vertex(x, y, true);
|
add_vertex(x, y, 0, r, colour);
|
||||||
else add_vertex(x, y, 0, r, colour);
|
|
||||||
}
|
}
|
||||||
else if (mode == MODE_ATTACK)
|
else if (mode == MODE_ATTACK)
|
||||||
{
|
{
|
||||||
|
@ -116,11 +115,18 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// really, we shouldn't be able to get here. return false just in case
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same here - just a logic check
|
||||||
if (current->colour != turn->get_colour()) return false;
|
if (current->colour != turn->get_colour()) return false;
|
||||||
|
|
||||||
|
// This is the range check...
|
||||||
|
if (MathUtils::distance(current->x, current->y, 0, x, y, 0) > get_range())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (Graph::add_vertex(x, y, z, r, colour, 10, current))
|
if (Graph::add_vertex(x, y, z, r, colour, 10, current))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -191,9 +197,16 @@ float GameData::calculate_strength_r(Vertex* node, unsigned int depth, list<Vert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Mode GameData::set_mode(Mode m)
|
// This class contains logic checks to keep the mode aligned with
|
||||||
|
// what is reasonable. Special cases inside the GameData class should just
|
||||||
|
// do mode = MODE_<whatever>
|
||||||
|
void GameData::set_mode(Mode m)
|
||||||
{
|
{
|
||||||
mode = m;
|
// Stay in MODE_SELECT (or maybe MODE_BUILD) when current is null
|
||||||
|
if (current == NULL) return;
|
||||||
|
|
||||||
|
// The other modes all require current to match the player
|
||||||
|
if (current->colour == turn->get_colour()) mode = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class GameData : public Graph
|
||||||
bool add_vertex(int x, int y, int z, int r, int colour);
|
bool add_vertex(int x, int y, int z, int r, int colour);
|
||||||
|
|
||||||
Mode get_mode() const { return mode; }
|
Mode get_mode() const { return mode; }
|
||||||
Mode set_mode(Mode m);
|
void set_mode(Mode m);
|
||||||
|
|
||||||
// returns the move/attack range for the specified node
|
// returns the move/attack range for the specified node
|
||||||
// (or the selected node if node == NULL)
|
// (or the selected node if node == NULL)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user