From e42727977b3dab7aecff0ce8afa5b16abcd8b26b Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 3 Jun 2015 21:22:14 +0200 Subject: Started reading of gamestate --- .gitignore | 1 + include/alien.h | 1 + include/game_state.h | 2 +- src/game_state.cpp | 31 +++++++++++++++++++++++++++++++ src/spacebot.cpp | 2 +- 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/game_state.cpp diff --git a/.gitignore b/.gitignore index 87be59f..bf013a7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ cppbot *.sdf *.suo Debug/ +Makefile diff --git a/include/alien.h b/include/alien.h index 476990b..2f7d596 100644 --- a/include/alien.h +++ b/include/alien.h @@ -3,6 +3,7 @@ class Alien { public: Alien(int x, int y); + const static char MAP_CHAR = 'x'; private: int x; int y; diff --git a/include/game_state.h b/include/game_state.h index abb2efa..aa49fc8 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -11,7 +11,7 @@ class GameState { public: - GameState(const std::istream& mapFile){} + GameState(std::istream& mapFile); private: std::vector aliens; std::vector bullets; 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 + +const int OPENING_LINES = 6; +const int GAME_AREA_LINES = 25; + +GameState::GameState(std::istream& file) +{ + for (int i=0; i::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")) { } -- cgit v1.2.3