summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2011-11-29 18:36:03 +0100
committerDominique Martinet <asmadeus@codewreck.org>2011-11-29 18:36:03 +0100
commitf8c3c5644223d810d3093d6dac600f19ea5f91c9 (patch)
tree8ebc9c4bc4783137ee0662a0557f74833a2dc380
parentd1cc077361eeec8395d362b32f8b8022204d6d7d (diff)
fixed keys on restart
-rw-r--r--AIController.cpp2
-rw-r--r--AIController.h1
-rw-r--r--Controller.cpp2
-rw-r--r--Controller.h1
-rw-r--r--Game.cpp39
-rw-r--r--KeyboardController.cpp4
-rw-r--r--KeyboardController.h2
7 files changed, 46 insertions, 5 deletions
diff --git a/AIController.cpp b/AIController.cpp
index d310fa0..1c0b51f 100644
--- a/AIController.cpp
+++ b/AIController.cpp
@@ -13,6 +13,8 @@ AIController::~AIController(void)
}
+void AIController::reset() {}
+
void AIController::think() {
Coordinates coord = m_player.getCoordinates();
VelocityVector velocity = m_player.getVelocity();
diff --git a/AIController.h b/AIController.h
index 35e3631..09e383f 100644
--- a/AIController.h
+++ b/AIController.h
@@ -19,6 +19,7 @@ public:
virtual ~AIController(void);
void think();
+ void reset();
private:
void turnRandom();
diff --git a/Controller.cpp b/Controller.cpp
index f3b4cb5..33729a1 100644
--- a/Controller.cpp
+++ b/Controller.cpp
@@ -13,5 +13,3 @@ Controller::~Controller(void)
Player& Controller::getPlayer() {
return(m_player);
}
-
-
diff --git a/Controller.h b/Controller.h
index 5f63d82..534db16 100644
--- a/Controller.h
+++ b/Controller.h
@@ -17,6 +17,7 @@ public:
* m_player directly in order to take decisions.
**/
virtual void think() = 0;
+ virtual void reset() = 0;
protected:
Player& m_player;
diff --git a/Game.cpp b/Game.cpp
index 47704d5..98f631d 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -61,12 +61,45 @@ void Game::init(int width, int height, PlayerNumber num) {
}
- m_gameStarted = true;
- m_gameRunning = true;
+
}
void Game::restart() {
- init(m_width, m_height, m_vPlayers.size());
+ m_Field.init(m_width, m_height);
+ PlayerNumber num = m_vPlayers.size();
+ for(PlayerNumber i = 0; i<num; ++i)
+ {
+ int x = (int)(m_width * (0.5f + 0.3f*cosf(2.f*M_PI*(float)i/num+M_PI)));
+ int y = (int)(m_height * (0.5f + 0.3f*sinf(2.f*M_PI*(float)i/num+M_PI)));
+
+ VelocityVector velocity;
+ if (abs(x-m_width/2) >= abs(y-m_height/2)) {
+ if (x-m_width/2 >= 0) {
+ velocity = VelocityVector(-1,0);
+ } else {
+ velocity = VelocityVector(1,0);
+ }
+ } else {
+ if (y-m_height/2 >= 0) {
+ velocity = VelocityVector(0,-1);
+ } else {
+ velocity = VelocityVector(0,1);
+ }
+ }
+
+ m_vPlayers[i].setCoordinates(Coordinates(x,y));
+ m_vPlayers[i].setVelocity(velocity);
+ m_vPlayers[i].setNumber(i);
+ m_vPlayers[i].revive();
+ m_Field.getCell(Coordinates(x,y)).setState(PLAYER);
+ m_Field.getCell(Coordinates(x,y)).setPlayer(&m_vPlayers[i]);
+
+ if (m_vPlayers[i].getController()) {
+ m_vPlayers[i].getController()->reset();
+ }
+ }
+ m_gameStarted = true;
+ m_gameRunning = true;
}
Player& Game::getPlayerByID(PlayerNumber id) {
diff --git a/KeyboardController.cpp b/KeyboardController.cpp
index 856be38..6ca5899 100644
--- a/KeyboardController.cpp
+++ b/KeyboardController.cpp
@@ -38,6 +38,10 @@ void KeyboardController::think()
m_nextMove = NO_MOVE;
}
+void KeyboardController::reset()
+{
+ m_nextMove = NO_MOVE;
+}
KeyboardController::~KeyboardController(void)
{
diff --git a/KeyboardController.h b/KeyboardController.h
index cdb296b..134c8f1 100644
--- a/KeyboardController.h
+++ b/KeyboardController.h
@@ -37,6 +37,8 @@ public:
public:
void PressKey(KeyCode key);
void think();
+ void reset();
+
private:
const uint m_leftKey;
const uint m_rightKey;