diff --git a/gamecore.cpp b/gamecore.cpp index 08035dd..79c519d 100644 --- a/gamecore.cpp +++ b/gamecore.cpp @@ -3,7 +3,6 @@ #include "debug.h" #include -int GameCore::MAX_MOVE_DISTANCE = 100; int GameCore::NODE_RADIUS = 12; GameCore::GameCore() @@ -22,7 +21,7 @@ int GameCore::execute() while(SDL_PollEvent(&event)) handle_event(&event); // iterate(); - renderer.render(data, MAX_MOVE_DISTANCE); + renderer.render(data); } cleanup(); @@ -54,15 +53,6 @@ void GameCore::on_exit() void GameCore::on_lbutton_down(int x, int y) { - Vertex* cv = data.get_current_vertex(); - if (cv != NULL && - (MathUtils::distance(cv->x, cv->y, x, y) - > MAX_MOVE_DISTANCE)) - { - data.select_vertex(x, y); - return; - } - data.do_vertex(x, y, NODE_RADIUS); } @@ -76,4 +66,6 @@ void GameCore::on_rbutton_down(int mX, int mY) void GameCore::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode) { if (sym == SDLK_q && mod & KMOD_CTRL) is_running = false; + if (sym == SDLK_a) data.set_mode(MODE_ATTACK); + if (sym == SDLK_m) data.set_mode(MODE_MOVE); } diff --git a/gamedata.cpp b/gamedata.cpp index ae8d95a..8357431 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -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& visited); Vertex* current; Turn player; + Mode mode; bool player1_played; bool player2_played;