diff options
| -rw-r--r-- | backend/Dungeon.cpp | 44 | ||||
| -rw-r--r-- | backend/Dungeon.h | 7 | ||||
| -rw-r--r-- | frontend/Player.cpp | 4 | ||||
| -rw-r--r-- | frontend/Player.h | 1 | ||||
| -rw-r--r-- | frontend/main.cpp | 2 | 
5 files changed, 46 insertions, 12 deletions
| diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp index d4df1ef..b1e89ba 100644 --- a/backend/Dungeon.cpp +++ b/backend/Dungeon.cpp @@ -1,17 +1,41 @@  #include "Location.h"  #include "Dungeon.h"  #include "RNG.h" +#include "backend/ListIterator.h" +#include "print.h" -void Dungeon::update() { -	// TODO: iterators are broken (!????) -	// for (Location * location : this->locations) { -	// 	for (Enemy * enemy : location->get_enemies()) { -	// 		if (RNG::get().rand_double() < 0.5) continue; -	// 		Direction direction = random_direction(*location); -	// 		// location->remove_enemy(enemy); // TODO: this breaks the for loop -	// 		location->get_exit(direction)->add_enemy(enemy); -	// 	} -	// } +void Dungeon::update(Location * player_location) { +	this->player_location = player_location; + +	ListRange<Enemy *> enemies = player_location->get_enemies(); + +	if (enemies.size() > 0) +		this->update_attacks(enemies); +	else +		this->update_movement(); +} + +void Dungeon::update_attacks(ListRange<Enemy *> & enemies) { +	printf("TODO: de vijanden vallen aan!\n"); +} + +void Dungeon::update_movement() { +	bool moved = false; +	for (Location * location : this->locations) { +		for (Enemy * enemy : location->get_enemies()) { +			if (RNG::get().rand_double() < 0.5) continue; + +			if (!moved) +				lprtf(":: De vijanden bewegen ::\n"); +			Direction direction = random_direction(*location); +			location->remove_enemy(enemy); +			Location * new_location = location->get_exit(direction); +			new_location->add_enemy(enemy); +			if (player_location == new_location) +				lprtf("%s komt de huidige locatie binnen\n", enemy->get_name().c_str()); +			moved = true; +		} +	}  }  void Dungeon::add_location(Location * location) { diff --git a/backend/Dungeon.h b/backend/Dungeon.h index be8b52e..1eaa970 100644 --- a/backend/Dungeon.h +++ b/backend/Dungeon.h @@ -2,6 +2,7 @@  #include "Location.h"  #include "PtrList.h" +#include "backend/ListIterator.h"  class Dungeon {  public: @@ -9,12 +10,16 @@ public:  	virtual ~Dungeon() = default;  public: -	void update(); +	void update(Location * player_location);  	void add_location(Location *);  	Location * get_start_location();  private:  	PtrList<Location> locations; +	Location * player_location = nullptr; +private: +	void update_attacks(ListRange<Enemy *> & enemies); +	void update_movement();  }; diff --git a/frontend/Player.cpp b/frontend/Player.cpp index fde85e6..85c4fff 100644 --- a/frontend/Player.cpp +++ b/frontend/Player.cpp @@ -66,3 +66,7 @@ void Player::take_damage(unsigned int dmg) {  	}  } +Location & Player::get_location() const { +	return this->location; +} + diff --git a/frontend/Player.h b/frontend/Player.h index c01c86a..249a129 100644 --- a/frontend/Player.h +++ b/frontend/Player.h @@ -43,6 +43,7 @@ public:  	void take_damage(unsigned int dmg);  	float get_attack() const;  	unsigned get_health() const; +	Location & get_location() const;  private:  	void cmdset_default(); diff --git a/frontend/main.cpp b/frontend/main.cpp index e513c12..780a649 100644 --- a/frontend/main.cpp +++ b/frontend/main.cpp @@ -43,7 +43,7 @@ FollowupAction game_main() {  		switch (action) {  			case NONE: break;  			case UPDATE: { -				dungeon->update(); +				dungeon->update(&player.get_location());  				break;  			}  			default: return action; |