summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game_state.cpp31
-rw-r--r--src/spacebot.cpp2
2 files changed, 32 insertions, 1 deletions
diff --git a/src/game_state.cpp b/src/game_state.cpp
new file mode 100644
index 0000000..48a9e42
--- /dev/null
+++ b/src/game_state.cpp
@@ -0,0 +1,31 @@
+#include "game_state.h"
+#include <iostream>
+
+const int OPENING_LINES = 6;
+const int GAME_AREA_LINES = 25;
+
+GameState::GameState(std::istream& file)
+{
+ for (int i=0; i<OPENING_LINES; ++i)
+ {
+ file.ignore(numeric_limits<streamsize>::max(), '\n');
+ }
+
+ int x = -1;
+ int y = 0;
+ char nextChar = ' ';
+ while (char nextChar = file.get())
+ {
+ ++x;
+ switch (nextChar)
+ {
+ case Alien.MAP_CHAR:
+ aliens.push_back(Alien(x,y));
+ break;
+ case '\n':
+ ++y;
+ x = -1;
+ break;
+ }
+ }
+}
diff --git a/src/spacebot.cpp b/src/spacebot.cpp
index b297eb3..7460fe3 100644
--- a/src/spacebot.cpp
+++ b/src/spacebot.cpp
@@ -5,7 +5,7 @@
Spacebot::Spacebot(std::string outputPath)
: outputPath(std::move(outputPath)),
- gameState(std::ifstream(outputPath+"/map.txt", std::ifstream::in))
+ gameState(std::ifstream(outputPath+"/map.txt"))
{
}