More implementation for attacking

This commit is contained in:
Anna Rose 2011-06-24 12:18:52 -04:00
parent 931ced321a
commit e51a328641
4 changed files with 44 additions and 20 deletions

View File

@ -32,7 +32,7 @@ void GameData::do_vertex(int x, int y, int r)
{ {
if (current != NULL && if (current != NULL &&
(MathUtils::distance(current->x, current->y, x, y) (MathUtils::distance(current->x, current->y, x, y)
> get_move_radius())) > get_range()))
{ {
select_vertex(x, y); select_vertex(x, y);
return; return;
@ -122,26 +122,20 @@ float GameData::calculate_strength(Vertex* node)
float GameData::calculate_strength_r(Vertex* node, unsigned int depth, list<Vertex*>& visited) float GameData::calculate_strength_r(Vertex* node, unsigned int depth, list<Vertex*>& visited)
{ {
// Find which vertices we need to visit from here // Find which vertices we need to visit from here
list<Edge> es = get_vertex_edges(node); list<Vertex*> neighbors = get_neighbors(node);
list<Vertex*> to_visit; list<Vertex*> to_visit;
visited.push_back(node); visited.push_back(node);
for (list<Edge>::iterator cursor = es.begin(); cursor != es.end(); for (list<Vertex*>::iterator cursor = neighbors.begin();
cursor++) cursor != neighbors.end(); cursor++)
{ {
Edge e = *cursor; Vertex* v = *cursor;
// if this is true, we haven't visited the vertex on the other end of // if this is true, we haven't visited the vertex on the other end of
// this edge yet // this edge yet
if (e.a == node && if (find(visited.begin(), visited.end(), v) == visited.end())
find(visited.begin(), visited.end(), e.b) == visited.end())
{ {
to_visit.push_back(e.b); to_visit.push_back(v);
}
else if (e.b == node &&
find(visited.begin(), visited.end(), e.a) == visited.end())
{
to_visit.push_back(e.a);
} }
} }
@ -169,8 +163,20 @@ float GameData::calculate_strength_r(Vertex* node, unsigned int depth, list<Vert
} }
int GameData::get_move_radius(Vertex* node) int GameData::get_range(Vertex* node)
{ {
if (current == NULL) return 0; if (node == NULL) node = current;
else return 100;
if (node == NULL) return 0;
else if (mode == MODE_MOVE) return 100;
else if (mode == MODE_ATTACK)
{
}
}
void GameData::attack_vertex(Vertex* target)
{
} }

View File

@ -25,15 +25,16 @@ class GameData : public Graph
// select or add vertex, as appropriate // select or add vertex, as appropriate
void do_vertex(int x, int y, int r); void do_vertex(int x, int y, int r);
void select_vertex(int x, int y); void select_vertex(int x, int y);
void attack_vertex(Vertex* target);
bool add_vertex(int x, int y, int r, int colour); bool add_vertex(int x, int y, int r, int colour);
Mode get_mode() const { return mode; } Mode get_mode() const { return mode; }
Mode set_mode(Mode m) { mode = m; } Mode set_mode(Mode m) { mode = m; }
// returns the move/attack radius (based on mode) for the specified node // returns the move/attack range for the specified node
// (or the selected node if node == NULL) // (or the selected node if node == NULL)
int get_move_radius(Vertex* node = NULL); int get_range(Vertex* node = NULL);
private: private:
float calculate_strength(Vertex* node); float calculate_strength(Vertex* node);

View File

@ -138,7 +138,7 @@ list<Vertex*> Graph::get_colour(int colour)
} }
list<Edge> Graph::get_vertex_edges(Vertex* v) list<Edge> Graph::get_edges(Vertex* v)
{ {
list<Edge> answer; list<Edge> answer;
@ -151,3 +151,19 @@ list<Edge> Graph::get_vertex_edges(Vertex* v)
return answer; return answer;
} }
list<Vertex*> Graph::get_neighbors(Vertex* v)
{
list<Vertex*> answer;
for (list<Edge>::iterator cursor = edges.begin();
cursor != edges.end(); cursor++)
{
Edge e = *cursor;
if (e.a == v) answer.push_back(e.b);
else if (e.b == v) answer.push_back(e.a);
}
return answer;
}

View File

@ -49,7 +49,8 @@ class Graph
list<Vertex*> get_vertices() const { return vertices; } list<Vertex*> get_vertices() const { return vertices; }
list<Edge> get_edges() const { return edges; } list<Edge> get_edges() const { return edges; }
list<Vertex*> get_colour(int colour); list<Vertex*> get_colour(int colour);
list<Edge> get_vertex_edges(Vertex* v); list<Edge> get_edges(Vertex* v);
list<Vertex*> get_neighbors(Vertex* v);
bool point_in_vertex(int x, int y, int size); bool point_in_vertex(int x, int y, int size);
Vertex * vertex_at(int x, int y); Vertex * vertex_at(int x, int y);