Added player names and some debug stuff

This commit is contained in:
2011-07-01 20:00:19 -04:00
parent bf151a928a
commit e221f1990c
6 changed files with 57 additions and 28 deletions

View File

@ -13,13 +13,14 @@ int GameData::PLAYER2_COLOUR = 0x090c7a;
int GameData::BASE_BUILD_RADIUS = 75;
int GameData::NODE_RADIUS = 10;
GameData::GameData()
: Graph(true)
{
current = NULL;
mode = MODE_BUILD;
player1 = Player(PLAYER1_COLOUR);
player2 = Player(PLAYER2_COLOUR);
player1 = Player("player 1", PLAYER1_COLOUR);
player2 = Player("player 2", PLAYER2_COLOUR);
turn = &player1;
}
@ -30,7 +31,7 @@ Vertex* GameData::get_current_vertex(bool only_mine) const
{
if (only_mine)
{
if (current != NULL &&
if (current != NULL &&
current->colour == turn->get_colour()) return current;
return NULL;
@ -40,6 +41,13 @@ Vertex* GameData::get_current_vertex(bool only_mine) const
}
void GameData::clear_current_vertex()
{
mode = MODE_SELECT;
current = NULL;
}
void GameData::toggle_turn()
{
if (!turn->has_played()) turn->set_played();
@ -75,9 +83,8 @@ void GameData::handle_click(int x, int y)
}
else if (mode == MODE_ATTACK)
{
if (select_vertex(x, y, true)) return;
Vertex* v = vertex_at(x, y, 0);
if (v == NULL) return;
if (v == NULL || v->colour == turn->get_colour()) return;
if (v->colour != colour) attack_vertex(v);
}
}
@ -141,6 +148,13 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
}
float GameData::calculate_armor(Vertex* node)
{
float str = calculate_strength(node);
return str / 10;
}
float GameData::calculate_strength(Vertex* node)
{
list<Vertex*> visited;
@ -204,7 +218,7 @@ void GameData::set_mode(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;
}
@ -238,18 +252,17 @@ int GameData::get_range(Vertex* node)
void GameData::attack_vertex(Vertex* target)
{
float atk_str = calculate_strength(current);
float def_str = calculate_strength(target);
float armor = def_str / 10; // how much energy it takes to deal 1 damage
float atk = calculate_strength(current);
float armor = calculate_armor(current);
int damage = (int)(atk_str / armor);
int damage = (int)(atk / armor);
target->score -= damage;
if (target->score <= 0) remove_vertex(target);
#ifdef DEBUG
fprintf(stderr, "debug: GameData::attack_vertex(): atk_str=%.2f, def_str=%.2f, armor=%.2f, damage=%d\n", atk_str, def_str, armor, damage);
fprintf(stderr, "debug: GameData::attack_vertex(): atk=%.2f, armor=%.2f, armor=%.2f, damage=%d\n", atk, armor, damage);
#endif
toggle_turn();