summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2015-06-06 15:39:02 +0200
committerJustin Worthe <justin.worthe@gmail.com>2015-06-06 15:39:02 +0200
commit97d6287a0710ec59d746f6340a796bbe6c7c8aa2 (patch)
treed4dcca538ae99829b808e10261d4d430b4e29278
parent140b51f2bcd9c0aaa5b536d85702064a93530188 (diff)
Abstracted game objects into an entity base class
-rw-r--r--include/alien.h7
-rw-r--r--include/enemy_bullet.h7
-rw-r--r--include/game_entity.h13
-rw-r--r--include/game_state.h1
-rw-r--r--include/player_missile.h6
-rw-r--r--include/shield.h7
-rw-r--r--include/spaceship.h7
-rw-r--r--src/alien.cpp2
-rw-r--r--src/enemy_bullet.cpp2
-rw-r--r--src/game_entity.cpp5
-rw-r--r--src/game_state.cpp8
-rw-r--r--src/player_missile.cpp2
-rw-r--r--src/shield.cpp2
-rw-r--r--src/spacebot.cpp1
-rw-r--r--src/spaceship.cpp2
15 files changed, 52 insertions, 20 deletions
diff --git a/include/alien.h b/include/alien.h
index 2f7d596..5dda726 100644
--- a/include/alien.h
+++ b/include/alien.h
@@ -1,10 +1,11 @@
#pragma once
-class Alien {
+#include "game_entity.h"
+
+class Alien : public GameEntity
+{
public:
Alien(int x, int y);
const static char MAP_CHAR = 'x';
private:
- int x;
- int y;
};
diff --git a/include/enemy_bullet.h b/include/enemy_bullet.h
index db3fcf9..ff3b001 100644
--- a/include/enemy_bullet.h
+++ b/include/enemy_bullet.h
@@ -1,11 +1,12 @@
#pragma once
-class EnemyBullet {
+#include "game_entity.h"
+
+class EnemyBullet: public GameEntity
+{
public:
EnemyBullet(int x, int y);
const static char ALIEN_MAP_CHAR = '|';
const static char ENEMY_MISSILE_MAP_CHAR = 'i';
private:
- int x;
- int y;
};
diff --git a/include/game_entity.h b/include/game_entity.h
new file mode 100644
index 0000000..215333c
--- /dev/null
+++ b/include/game_entity.h
@@ -0,0 +1,13 @@
+#pragma once
+
+class GameEntity
+{
+public:
+ GameEntity(int x, int y);
+ int x() const {return _x;}
+ int y() const {return _y;}
+private:
+ int _x;
+ int _y;
+};
+
diff --git a/include/game_state.h b/include/game_state.h
index defe691..db20b84 100644
--- a/include/game_state.h
+++ b/include/game_state.h
@@ -12,6 +12,7 @@ class GameState
{
public:
GameState(std::string mapFilename);
+ void logState();
private:
std::vector<Alien> aliens;
std::vector<EnemyBullet> bullets;
diff --git a/include/player_missile.h b/include/player_missile.h
index 6f304df..c504a79 100644
--- a/include/player_missile.h
+++ b/include/player_missile.h
@@ -1,11 +1,11 @@
#pragma once
-class PlayerMissile
+#include "game_entity.h"
+
+class PlayerMissile: public GameEntity
{
public:
PlayerMissile(int x, int y);
const static char MAP_CHAR = '!';
private:
- int x;
- int y;
};
diff --git a/include/shield.h b/include/shield.h
index bd64e3e..be65be3 100644
--- a/include/shield.h
+++ b/include/shield.h
@@ -1,11 +1,12 @@
#pragma once
-class Shield {
+#include "game_entity.h"
+
+class Shield: public GameEntity
+{
public:
Shield(int x, int y);
const static char MAP_CHAR = '-';
private:
- int x;
- int y;
};
diff --git a/include/spaceship.h b/include/spaceship.h
index 5e6afd0..bd26b64 100644
--- a/include/spaceship.h
+++ b/include/spaceship.h
@@ -1,11 +1,12 @@
#pragma once
-class Spaceship {
+#include "game_entity.h"
+
+class Spaceship: public GameEntity
+{
public:
Spaceship(int x, int y);
const static char ENEMY_MAP_CHAR = 'V';
const static char PLAYER_MAP_CHAR = 'A';
private:
- int x;
- int y;
};
diff --git a/src/alien.cpp b/src/alien.cpp
index 2b222fd..3fa9b28 100644
--- a/src/alien.cpp
+++ b/src/alien.cpp
@@ -1,7 +1,7 @@
#include "alien.h"
Alien::Alien(int x, int y)
- :x(x), y(y)
+ :GameEntity(x, y)
{
}
diff --git a/src/enemy_bullet.cpp b/src/enemy_bullet.cpp
index 75e3e8b..6ae5066 100644
--- a/src/enemy_bullet.cpp
+++ b/src/enemy_bullet.cpp
@@ -1,6 +1,6 @@
#include "enemy_bullet.h"
EnemyBullet::EnemyBullet(int x, int y)
- :x(x), y(y)
+ :GameEntity(x, y)
{
}
diff --git a/src/game_entity.cpp b/src/game_entity.cpp
new file mode 100644
index 0000000..1b4e7e3
--- /dev/null
+++ b/src/game_entity.cpp
@@ -0,0 +1,5 @@
+#include "game_entity.h"
+
+GameEntity::GameEntity(int x, int y)
+ :_x(x), _y(y)
+{}
diff --git a/src/game_state.cpp b/src/game_state.cpp
index 340bcd3..2a9975e 100644
--- a/src/game_state.cpp
+++ b/src/game_state.cpp
@@ -50,3 +50,11 @@ GameState::GameState(std::string mapFilename)
}
}
}
+
+void GameState::logState()
+{
+ for (auto alien : aliens)
+ {
+ std::cout << "Alien (" << alien.x() << ", " << alien.y() << ")" << std::endl;
+ }
+}
diff --git a/src/player_missile.cpp b/src/player_missile.cpp
index b0dbdc2..a95e928 100644
--- a/src/player_missile.cpp
+++ b/src/player_missile.cpp
@@ -1,6 +1,6 @@
#include "player_missile.h"
PlayerMissile::PlayerMissile(int x, int y)
- :x(x), y(y)
+ :GameEntity(x, y)
{
}
diff --git a/src/shield.cpp b/src/shield.cpp
index b58714a..7457554 100644
--- a/src/shield.cpp
+++ b/src/shield.cpp
@@ -1,6 +1,6 @@
#include "shield.h"
Shield::Shield(int x, int y)
- :x(x), y(y)
+ :GameEntity(x, y)
{
}
diff --git a/src/spacebot.cpp b/src/spacebot.cpp
index f30bb34..9d2df5c 100644
--- a/src/spacebot.cpp
+++ b/src/spacebot.cpp
@@ -8,6 +8,7 @@ Spacebot::Spacebot(std::string outputPath)
: outputFilename(outputPath+"/move.txt"),
gameState(outputPath+"/map.txt")
{
+ gameState.logState();
}
void Spacebot::writeNextMove()
diff --git a/src/spaceship.cpp b/src/spaceship.cpp
index faf2501..b1cee9a 100644
--- a/src/spaceship.cpp
+++ b/src/spaceship.cpp
@@ -1,6 +1,6 @@
#include "spaceship.h"
Spaceship::Spaceship(int x, int y)
- :x(x), y(y)
+ :GameEntity(x, y)
{
}