summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2015-06-03 07:50:05 +0200
committerJustin Worthe <justin.worthe@gmail.com>2015-06-03 07:50:05 +0200
commit618501b6fae62fa2d5db922ec8abf94120e5e99c (patch)
tree26cd18ceef12003d4d7b84b40bf9b77f7465093c
parent4f75af9646b03ce4101820c10152944c780e7c0a (diff)
Added gamestate object
-rw-r--r--include/game_state.h21
-rw-r--r--include/spacebot.h10
-rw-r--r--src/main.cpp2
-rw-r--r--src/spacebot.cpp9
4 files changed, 32 insertions, 10 deletions
diff --git a/include/game_state.h b/include/game_state.h
new file mode 100644
index 0000000..abb2efa
--- /dev/null
+++ b/include/game_state.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "alien.h"
+#include "enemy_bullet.h"
+#include "player_missile.h"
+#include "shield.h"
+#include "spaceship.h"
+#include <vector>
+#include <iostream>
+
+class GameState
+{
+public:
+ GameState(const std::istream& mapFile){}
+private:
+ std::vector<Alien> aliens;
+ std::vector<EnemyBullet> bullets;
+ std::vector<PlayerMissile> missiles;
+ std::vector<Shield> shields;
+ std::vector<Spaceship> spaceships;
+};
diff --git a/include/spacebot.h b/include/spacebot.h
index a5c23c2..b152197 100644
--- a/include/spacebot.h
+++ b/include/spacebot.h
@@ -1,16 +1,16 @@
#pragma once
-#include <iostream>
-#include <fstream>
+#include <string>
#include "move.h"
+#include "game_state.h"
class Spacebot {
public:
- Spacebot(const std::string& outputPath);
+ Spacebot(std::string outputPath);
void writeNextMove();
private:
- std::ifstream mapStream;
- std::ofstream resultStream;
+ std::string outputPath;
+ GameState gameState;
void writeMove(const Move& move);
Move chooseMove();
};
diff --git a/src/main.cpp b/src/main.cpp
index 1621ba8..c780e1f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,7 +11,7 @@ int main(int argc, char* argv[])
}
std::string outputFolder = argv[1];
- Spacebot bot(outputFolder);
+ Spacebot bot(std::move(outputFolder));
bot.writeNextMove();
return 0;
diff --git a/src/spacebot.cpp b/src/spacebot.cpp
index 24a5d1e..716f7cb 100644
--- a/src/spacebot.cpp
+++ b/src/spacebot.cpp
@@ -1,11 +1,11 @@
#include "spacebot.h"
#include <random>
+#include <fstream>
-Spacebot::Spacebot(const std::string& outputPath)
- : mapStream(outputPath+"/map.txt", std::ifstream::in)
- , resultStream(outputPath+"/move.txt", std::ofstream::out)
+Spacebot::Spacebot(std::string outputPath)
+ : outputPath(std::move(outputPath)),
+ gameState(std::ifstream(outputPath+"/map.txt", std::ifstream::in))
{
- std::srand(time(0));
}
void Spacebot::writeNextMove()
@@ -26,6 +26,7 @@ Move Spacebot::chooseMove()
void Spacebot::writeMove(const Move& move)
{
+ std::ofstream resultStream(outputPath+"/move.txt");
switch (move)
{
case Move::NOTHING: