Let gamedata store information about whether we are attacking or moving

This commit is contained in:
2011-06-24 12:02:53 -04:00
parent a71ab74a9c
commit 931ced321a
3 changed files with 39 additions and 17 deletions

View File

@ -15,6 +15,7 @@ GameData::GameData()
{
current = NULL;
player = PLAYER1;
mode = MODE_MOVE;
}
GameData::~GameData() { }
@ -23,17 +24,29 @@ void GameData::toggle_turn()
{
if (player == PLAYER1) player = PLAYER2;
else if (player == PLAYER2) player = PLAYER1;
mode = MODE_MOVE;
}
void GameData::do_vertex(int x, int y, int r)
{
int colour;
if (player == PLAYER1) colour = PLAYER1_COLOUR;
if (player == PLAYER2) colour = PLAYER2_COLOUR;
if (current != NULL &&
(MathUtils::distance(current->x, current->y, x, y)
> get_move_radius()))
{
select_vertex(x, y);
return;
}
if (point_in_vertex(x, y, r)) select_vertex(x, y);
else add_vertex(x, y, r, colour);
if (mode == MODE_MOVE)
{
int colour;
if (player == PLAYER1) colour = PLAYER1_COLOUR;
if (player == PLAYER2) colour = PLAYER2_COLOUR;
if (point_in_vertex(x, y, r)) select_vertex(x, y);
else add_vertex(x, y, r, colour);
}
}
@ -57,6 +70,8 @@ void GameData::select_vertex(int x, int y)
bool GameData::add_vertex(int x, int y, int r, int colour)
{
if (mode == MODE_ATTACK) return false;
// this is the special case for adding the first vertex for each player
if (current == NULL)
{
@ -152,3 +167,10 @@ float GameData::calculate_strength_r(Vertex* node, unsigned int depth, list<Vert
return modscore;
}
int GameData::get_move_radius(Vertex* node)
{
if (current == NULL) return 0;
else return 100;
}