summaryrefslogtreecommitdiff
path: root/source/data/LevelReader.h
blob: 293d820717f9abc8a326e22e74421c67cab8d42d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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