From 7744bad7c79645f10ed72dcef9d79aacfbc3a6e0 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sun, 3 Jul 2011 10:38:56 -0400 Subject: [PATCH] Implemented node movement --- gamedata.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gamedata.cpp b/gamedata.cpp index 356537f..98fa5df 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -82,20 +82,33 @@ void GameData::handle_click(int x, int y) int colour; colour = turn->get_colour(); - if (mode == MODE_SELECT) + Vertex* v = vertex_at(x, y, 0); + + // fixme - energy expenditure should happen in each of these cases except + // MODE_SELECT + switch (mode) { + case MODE_SELECT: // select_vertex handles making sure a point exists at (x,y) select_vertex(x, y); - } - else if (mode == MODE_BUILD) - { + break; + case MODE_BUILD: add_vertex(x, y, 0, r, colour); - } - else if (mode == MODE_ATTACK) - { - Vertex* v = vertex_at(x, y, 0); + break; + case MODE_ATTACK: if (v == NULL || dynamic_cast(v)->player == turn) return; if (v->colour != colour) attack_vertex(v); + break; + case MODE_MOVE: + if (current == NULL) return; + if (MathUtils::distance(current->x, current->y, current->z, x, y, 0) + <= get_range()) + { + current->x = x; + current->y = y; + toggle_turn(); + } + break; } }