From cfe5666c04a99ded27f5ca585c521a425cd3e15b Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sun, 3 Jul 2011 17:45:11 -0400 Subject: [PATCH] Added End Turn button so we can do multiple actions per round - this will be limited by energy shortly --- game.cpp | 8 ++++++++ gamedata.cpp | 5 ++--- gamedata.h | 3 +-- menubutton.h | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/game.cpp b/game.cpp index 6266020..a8673db 100644 --- a/game.cpp +++ b/game.cpp @@ -58,6 +58,8 @@ bool Game::init() int col2 = 260; int col3 = 365; int col4 = 470; + int col5 = 575; + int col6 = 680; buttons.push_back(new MenuButton("Move", font, col1, row1, BUTTON_MOVE)); buttons.push_back(new MenuButton("Build", font, col1, row2, @@ -70,6 +72,8 @@ bool Game::init() BUTTON_BUILD_DEFENDER)); buttons.push_back(new MenuButton("Producer", font, col4, row1, BUTTON_BUILD_PRODUCER)); + buttons.push_back(new MenuButton("End Turn", font, col6, row2, + BUTTON_END_TURN)); return GameState::init(); @@ -236,6 +240,9 @@ void Game::handle_button_press(ButtonAction action) case BUTTON_BUILD_PRODUCER: data.set_build_type(VERTEX_PRODUCER); break; + case BUTTON_END_TURN: + data.toggle_turn(); + break; } } @@ -324,6 +331,7 @@ void Game::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode) else if (sym == SDLK_m) data.set_mode(MODE_MOVE); else if (sym == SDLK_b) data.set_mode(MODE_BUILD); else if (sym == SDLK_s || sym == SDLK_ESCAPE) data.set_mode(MODE_SELECT); + else if (sym == SDLK_e) data.toggle_turn(); #ifdef DEBUG if (sym == SDLK_d && mod & (KMOD_ALT | KMOD_CTRL)) print_debug_info(); diff --git a/gamedata.cpp b/gamedata.cpp index 972ecf2..ab9a856 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -105,7 +105,6 @@ void GameData::handle_click(int x, int y) { current->x = x; current->y = y; - toggle_turn(); } break; } @@ -162,7 +161,7 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour) if (Graph::add_vertex(v, current)) { - toggle_turn(); + mode = MODE_SELECT; return true; } @@ -225,7 +224,7 @@ void GameData::attack_vertex(GameVertex* target) fprintf(stderr, "debug: GameData::attack_vertex(): atk=%.2f, armor=%.2f, damage=%d\n", atk, armor, damage); #endif - toggle_turn(); + mode = MODE_SELECT; } diff --git a/gamedata.h b/gamedata.h index b917da5..be1f30c 100644 --- a/gamedata.h +++ b/gamedata.h @@ -21,8 +21,6 @@ class GameData : public Graph GameVertex* get_current_vertex(bool only_mine = false) const; void clear_current_vertex(); - void toggle_turn(); - // select or add vertex, as appropriate void handle_click(int x, int y); bool select_vertex(int x, int y); @@ -42,6 +40,7 @@ class GameData : public Graph // check for (and set, if needed) winner bool endgame(); + void toggle_turn(); Player* get_turn() const { return turn; } private: diff --git a/menubutton.h b/menubutton.h index 479dcf5..4d762f0 100644 --- a/menubutton.h +++ b/menubutton.h @@ -15,7 +15,7 @@ using std::string; // has me hard-pressed to figure out what it is. enum ButtonAction {BUTTON_BUILD=0x1, BUTTON_ATTACK=0x2, BUTTON_MOVE=0x4, BUTTON_BUILD_ATTACKER=0x8, BUTTON_BUILD_DEFENDER=0x10, - BUTTON_BUILD_PRODUCER=0x20}; + BUTTON_BUILD_PRODUCER=0x20, BUTTON_END_TURN=0x40}; class MenuButton {