Commit 87b85944 authored by Stuart John Watson's avatar Stuart John Watson

Changed the game's Entity Vector to use smart pointers

This fixs the polymorphism issue which prevented turn from working.

 	modified:   src/entity/vision/alive/mob/mob.h
 	modified:   src/game/game.cpp
 	modified:   src/game/game.h
parent 89551e86
......@@ -14,16 +14,16 @@ protected:
class RandomMove: public Mob {
public:
RandomMove(Dungeon &,int,int,int);
protected:
void turn();
protected:
std::default_random_engine generator;
};
class BasicSolver: public Mob {
public:
BasicSolver(Dungeon &,int,int);
protected:
void turn();
protected:
void findSolution();
std::stack<std::tuple<int,int>> trail;
};
......
......@@ -6,6 +6,7 @@
#include <libconfig.h++>
#include <chrono>
#include <memory>
Game::Game(){
}
......@@ -64,7 +65,8 @@ void Game::loop(){
mobx = x_dist(generator);
moby = y_dist(generator);
}
entities.emplace_back( RandomMove( levels.back(), mobx, moby, milliseconds_since_epoch) );
std::shared_ptr<RandomMove> r(new RandomMove( levels.back(), mobx, moby, milliseconds_since_epoch));
entities.emplace_back( r );
}
int scale = wa.width/levels.back().getWidth();
......@@ -82,7 +84,7 @@ void Game::loop(){
theHero->turn();
// Now all the other Entities take turns but none extra for now
for(int _nMob = 0; _nMob < entities.size(); _nMob++){
entities[_nMob].turn();
entities[_nMob]->turn();
}
......@@ -90,7 +92,7 @@ void Game::loop(){
theHero->draw(dpy,double_buffer,gc,scale);
for(int _nMob = 0; _nMob < entities.size(); _nMob++){
entities[_nMob].draw(dpy,double_buffer,gc,scale);
entities[_nMob]->draw(dpy,double_buffer,gc,scale);
}
......
......@@ -10,6 +10,7 @@
#include "../entity/vision/alive/mob/mob.h"
#include <vector>
#include <memory>
class Game {
......@@ -19,7 +20,7 @@ class Game {
void loop();
protected:
std::vector<Dungeon> levels;
std::vector<Mob> entities;
std::vector<std::shared_ptr<Entities>> entities;
Hero *theHero;
int dungeonLevel;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment