summaryrefslogtreecommitdiffstats
path: root/Game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Game.cpp')
-rw-r--r--Game.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/Game.cpp b/Game.cpp
index 2a45e46..2357845 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -3,7 +3,7 @@
Game::Game(int width, int height, PlayerNumber num):
m_Field(width, height)
{
- //m_vPlayers.resize(num); // is it possible to resize it without trying to fill it? (i.e. fill with null pointers)
+ //m_vPlayers.resize(num); // is it possible to resize it without trying to fill it? (i.e. fill with null pointers)
for(PlayerNumber i = 0; i<num; ++i)
{
int x = (int)(width * (0.5 + 0.3*cosf(2*M_PI*(float)i/num+M_PI)));
@@ -16,7 +16,7 @@ Game::Game(int width, int height, PlayerNumber num):
} else {
velocity = VelocityVector(1,0);
}
- } else {
+ } else {
if (y-height/2 >= 0) {
velocity = VelocityVector(0,-1);
} else {
@@ -32,7 +32,7 @@ Game::Game(int width, int height, PlayerNumber num):
Game::~Game(void)
{
- // ~m_Field; ? same for each player ?
+ // ~m_Field; ? same for each player ?
// apparently not needed since we contain the object and not a pointer to it, right?
}
@@ -66,14 +66,22 @@ void Game::resumeGame() {
// main function to be called within glut loop
void Game::updateGame(uint timeElapsedMs) {
- std::vector<Coordinates> path;
- std::vector< std::vector<Coordinates> > secondPassPath;
+ /* // ask the AI if they wanna change something?
+ for(std::vector<Player>::iterator player = m_vPlayers.begin(); player != m_vPlayers.end(); ++player) {
+ if (player->getController()) {
+ player->getController()->think();
+ }
+ }*/
+
+ // move everyone and update cells
+ std::vector<Coordinates> path;
+ std::vector< std::vector<Coordinates> > secondPassPath;
for(std::vector<Player>::iterator player = m_vPlayers.begin(); player != m_vPlayers.end(); ++player) {
if (player->isAlive()) {
path = player->move();
- secondPassPath.push_back(path);
+ secondPassPath.push_back(path);
for(std::vector<Coordinates>::iterator coord = path.begin(); coord != path.end(); ++coord) {
try {
@@ -96,6 +104,7 @@ void Game::updateGame(uint timeElapsedMs) {
}
}
+ // second pass to cleanup PLAYER_JUST_MOVED cells
for(std::vector< std::vector<Coordinates> >::iterator it = secondPassPath.begin(); it != secondPassPath.end(); ++it) {
for(std::vector<Coordinates>::iterator coord = it->begin(); coord != it->end(); ++coord) {
try {
@@ -108,5 +117,5 @@ void Game::updateGame(uint timeElapsedMs) {
}
} catch (std::exception out_of_bounds) {} // don't do anything
}
- }
+ }
}