diff options
author | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-31 13:58:22 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-31 13:58:22 +0200 |
commit | 98ba22e7064db57316dfff1ae127feb3dceeb73e (patch) | |
tree | 1f7fe3065f804e491f558650285e8c6d05fc914b /source/data/LevelReader.h |
Diffstat (limited to 'source/data/LevelReader.h')
-rw-r--r-- | source/data/LevelReader.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/source/data/LevelReader.h b/source/data/LevelReader.h new file mode 100644 index 0000000..293d820 --- /dev/null +++ b/source/data/LevelReader.h @@ -0,0 +1,71 @@ +#ifndef MAZEREADER_H +#define MAZEREADER_H + +#include <vector> +#include <list> +#include <string> +#include <fstream> +using namespace std; + +#include <allegro5/allegro_native_dialog.h> + +#include "../logic/Maze.h" +#include "../logic/PlayerCar.h" +#include "../logic/EnemyCar.h" +#include "../logic/Checkpoint.h" +#include "../logic/Rock.h" + +/** +* @brief An exception that is thrown if the file selected for opening does not exist. +* +* This should never be thrown, since the Allegro native file dialog is being used to select +* this file, and it only allows one to select existing files. +* +* @author Justin Wernick +* @author David Schneider +*/ +class FileOpenError{}; + +/** +* @brief Reads the game objects from a text file and calls relevant constructors. +* +* @author Justin Wernick +* @author David Schneider +*/ +class LevelReader +{ + public: + /** + * @brief Constructor that stores the path of the file containing the level to be read with the readLevel function. + * + * @param [in] filename The path of the file containing the level. + */ + LevelReader(string filename); + + //Assignment and copy operations are handled by the compiler generated versions + + /** + * @brief Function to read the chosen file into the data structures used in the game. + * + * Each character in the file is iterated through, and added to the appropriate data structure if it matches + * one of the defined constants. Lists should be cleared prior to calling this function. + * + * @param [out] maze Object representing the walls, populated with a vector of x,y pairs. + * @param [out] players List representing the player(s) in the game. + * @param [out] enemies List representing the enemies in the game. + * @param [out] checkpoints List representing the checkpoints in the game. + * @param [out] rocks List representing the rocks in the game. + */ + void readLevel(Maze& maze, list<PlayerCar>& players, list<EnemyCar>& enemies, list<Checkpoint>& checkpoints, list<Rock>& rocks); + + private: + static const char PLAYER_CHAR = '@'; ///< Character represented a PlayerCar in the level file. + static const char ENEMY_CHAR = 'X'; ///< Character represented an EnemyCar in the level file. + static const char CHECKPOINT_CHAR = 'P'; ///< Character represented a Checkpoint in the level file. + static const char ROCK_CHAR = 'O'; ///< Character represented a Rock in the level file. + static const char WALL_CHAR = '#'; ///< Character represented a solid part of the maze in the level file. + + string _filename; ///< Path of the file containing the level. +}; + +#endif // MAZEREADER_H |