From 8ad4ec0672ae6aaa7bf8c7c03e396b9851851694 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sun, 3 Jul 2011 15:48:06 -0400 Subject: [PATCH] Added some basic differences between vertex types --- game.cpp | 65 +++++++++++++++++++++++++++++++++++++++++----------- gamedata.cpp | 37 ++++++++++++++++++++++++++++-- gamedata.h | 1 + 3 files changed, 88 insertions(+), 15 deletions(-) diff --git a/game.cpp b/game.cpp index bfe7aaa..7093212 100644 --- a/game.cpp +++ b/game.cpp @@ -148,7 +148,9 @@ void Game::render() DrawUtils::draw_line(display, 150, display->h - 100, 150, display->h, 2, 0x000000); - if (data.get_current_vertex() != NULL) + if (data.get_current_vertex() != NULL && + dynamic_cast(data.get_current_vertex())->player == + data.get_turn()) { for (list::iterator cursor = buttons.begin(); cursor != buttons.end(); cursor++) @@ -242,24 +244,61 @@ void Game::handle_button_press(ButtonAction action) void Game::draw_stats(Vertex* v) { - int num_lines = 4; - int x = 20; - int y = display->h - 76; + int line_num = 0; + int line_height = 14; + int x = 10; + int y = display->h - 95; + int adj_y = y; - DrawUtils::draw_text(display, "player:", x, y, font); - DrawUtils::draw_text(display, dynamic_cast(v)->player->get_name(), x + 50, y, font); + DrawUtils::draw_text(display, "player:", x, adj_y, font); + DrawUtils::draw_text(display, + dynamic_cast(v)->player->get_name(), + x + 50, adj_y, font); - DrawUtils::draw_text(display, "atk:", x, y + 14, font); - DrawUtils::draw_text(display, itos(data.calculate_strength(v)), - x + 50, y + 14, font); + line_num++; + adj_y = y + line_num * line_height; + DrawUtils::draw_text(display, "type:", x, adj_y, font); + VertexType vtype = dynamic_cast(v)->type; + string type; + switch(vtype) + { + case VERTEX_ATTACKER: + type = "attacker"; + break; + case VERTEX_DEFENDER: + type = "defender"; + break; + case VERTEX_PRODUCER: + type = "producer"; + break; + } + DrawUtils::draw_text(display, type, x + 50, adj_y, font); - DrawUtils::draw_text(display, "armor:", x, y + 28, font); + line_num++; + adj_y = y + line_num * line_height; + DrawUtils::draw_text(display, "atk:", x, adj_y, font); + DrawUtils::draw_text(display, itos(data.calculate_attack(v)), + x + 50, adj_y, font); + + line_num++; + adj_y = y + line_num * line_height; + DrawUtils::draw_text(display, "armor:", x, adj_y, font); DrawUtils::draw_text(display, itos(data.calculate_armor(v)), - x + 50, y + 28, font); + x + 50, adj_y, font); - DrawUtils::draw_text(display, "hp:", x, y + 42, font); - DrawUtils::draw_text(display, itos(v->score), x + 50, y + 42, font); + line_num++; + adj_y = y + line_num * line_height; + DrawUtils::draw_text(display, "hp:", x, adj_y, font); + DrawUtils::draw_text(display, itos(v->score), x + 50, adj_y, font); + if (vtype == VERTEX_PRODUCER) + { + line_num++; + adj_y = y + line_num * line_height; + + DrawUtils::draw_text(display, "energy:", x, adj_y, font); + DrawUtils::draw_text(display, "25", x + 50, adj_y, font); + } } diff --git a/gamedata.cpp b/gamedata.cpp index 48e7ba2..ddb9159 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -191,12 +191,45 @@ 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); - float armor = str / 10; + float armor; + + switch(dynamic_cast(node)->type) + { + case VERTEX_ATTACKER: + armor = str / 10; + break; + case VERTEX_DEFENDER: + armor = str / 5; + break; + case VERTEX_PRODUCER: + armor = str / 40; + break; + } + if (armor < 1) armor = 1; return armor; } +float GameData::calculate_attack(Vertex* node) +{ + float attack = calculate_strength(node); + + switch (dynamic_cast(node)->type) + { + case VERTEX_ATTACKER: + attack *= 1.5; + break; + case VERTEX_DEFENDER: + attack /= 0.75; + break; + case VERTEX_PRODUCER: + attack = 0; + break; + } +} + + float GameData::calculate_strength(Vertex* node) { list visited; @@ -297,7 +330,7 @@ int GameData::get_range(Vertex* node) void GameData::attack_vertex(Vertex* target) { - float atk = calculate_strength(current); + float atk = calculate_attack(current); float armor = calculate_armor(target); int damage = (int)(atk / armor); target->score -= damage; diff --git a/gamedata.h b/gamedata.h index 5b543e3..0ea9dda 100644 --- a/gamedata.h +++ b/gamedata.h @@ -54,6 +54,7 @@ class GameData : public Graph // check for (and set, if needed) winner bool endgame(); Player* get_turn() const { return turn; } + float calculate_attack(Vertex* node); float calculate_strength(Vertex* node); float calculate_armor(Vertex* node);