summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2015-06-08 21:21:08 +0200
committerJustin Worthe <justin.worthe@gmail.com>2015-06-08 21:21:08 +0200
commit72eaaeb60916e736de6c1aaa3d1047663bce19d9 (patch)
tree9d11b011144c83f8d64ea6eb994573dfd9b83ae5 /src
parent0ef4646a9c19d3d88ffb7674123ccdc0a9012d98 (diff)
Started adding test for reading game state
Diffstat (limited to 'src')
-rw-r--r--src/game_state.cpp25
-rw-r--r--src/spacebot.cpp3
2 files changed, 13 insertions, 15 deletions
diff --git a/src/game_state.cpp b/src/game_state.cpp
index 59eb8c1..d99ca12 100644
--- a/src/game_state.cpp
+++ b/src/game_state.cpp
@@ -6,7 +6,7 @@
const int OPENING_LINES = 6;
const int GAME_AREA_LINES = 25;
-void moveToNextChar(int &x, int &y, int &width, char &nextChar, std::ifstream &mapFile)
+void moveToNextChar(int &x, int &y, int &width, char &nextChar, std::istream &mapFile)
{
if (nextChar == '\n')
{
@@ -24,9 +24,8 @@ void moveToNextChar(int &x, int &y, int &width, char &nextChar, std::ifstream &m
nextChar = mapFile.get();
}
-GameState::GameState(std::string mapFilename)
+GameState::GameState(std::istream &&mapFile)
{
- std::ifstream mapFile(mapFilename);
for (int i=0; i<OPENING_LINES; ++i)
{
mapFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
@@ -46,21 +45,21 @@ int GameState::addEntity(int x, int y, char type)
switch (type)
{
case Alien::MAP_CHAR:
- aliens.push_back(Alien(x,y));
+ _aliens.push_back(Alien(x,y));
return 1;
case EnemyBullet::ALIEN_MAP_CHAR:
case EnemyBullet::ENEMY_MISSILE_MAP_CHAR:
- bullets.push_back(EnemyBullet(x,y));
+ _bullets.push_back(EnemyBullet(x,y));
return 1;
case PlayerMissile::MAP_CHAR:
- missiles.push_back(PlayerMissile(x,y));
+ _missiles.push_back(PlayerMissile(x,y));
return 1;
case Shield::MAP_CHAR:
- shields.push_back(Shield(x,y));
+ _shields.push_back(Shield(x,y));
return 1;
case Spaceship::ENEMY_MAP_CHAR:
case Spaceship::PLAYER_MAP_CHAR:
- spaceships.push_back(Spaceship(x+1,y));
+ _spaceships.push_back(Spaceship(x+1,y));
return 3;
}
return 1;
@@ -68,23 +67,23 @@ int GameState::addEntity(int x, int y, char type)
void GameState::logState()
{
- for (auto alien : aliens)
+ for (auto alien : _aliens)
{
std::cout << "Alien " << alien.coords() << std::endl;
}
- for (auto bullet : bullets)
+ for (auto bullet : _bullets)
{
std::cout << "Enemy Bullet" << bullet.coords() << std::endl;
}
- for (auto missile : missiles)
+ for (auto missile : _missiles)
{
std::cout << "Player Missile" << missile.coords() << std::endl;
}
- for (auto shield : shields)
+ for (auto shield : _shields)
{
std::cout << "Shield" << shield.coords() << std::endl;
}
- for (auto spaceship : spaceships)
+ for (auto spaceship : _spaceships)
{
std::cout << "Spaceship" << spaceship.coords() << std::endl;
}
diff --git a/src/spacebot.cpp b/src/spacebot.cpp
index f30bb34..5f87df9 100644
--- a/src/spacebot.cpp
+++ b/src/spacebot.cpp
@@ -2,11 +2,10 @@
#include "move_string_mapper.h"
#include <random>
#include <fstream>
-#include <string>
Spacebot::Spacebot(std::string outputPath)
: outputFilename(outputPath+"/move.txt"),
- gameState(outputPath+"/map.txt")
+ gameState(std::ifstream(outputPath+"/map.txt"))
{
}