ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18gs

Dependencies:   mbed

Committer:
el18gs
Date:
Mon May 11 18:14:40 2020 +0000
Revision:
6:d755c4c56bdd
Parent:
5:27aa2d0891b7
Child:
7:220d3ebf74cf
Added details on Type enum

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 5:27aa2d0891b7 1 /** @file Ghost.h
el18gs 6:d755c4c56bdd 2 * @brief Ghosts library contains the necessary class, enums and typedefs
el18gs 6:d755c4c56bdd 3 * @brief to genearate and manipulate .ghost files for the game
el18gs 5:27aa2d0891b7 4 */
el18gs 5:27aa2d0891b7 5
el18gs 4:2e8d7c6d2953 6 // Ensure that the library is not importated twice
el18gs 4:2e8d7c6d2953 7 #ifndef GHOST_H
el18gs 4:2e8d7c6d2953 8 #define GHOST_H
el18gs 4:2e8d7c6d2953 9
el18gs 4:2e8d7c6d2953 10 // Import necessay libraries
el18gs 4:2e8d7c6d2953 11 #include "SDFileSystem.h"
el18gs 4:2e8d7c6d2953 12 #include <string>
el18gs 4:2e8d7c6d2953 13 #include <vector>
el18gs 4:2e8d7c6d2953 14 #include <iostream>
el18gs 4:2e8d7c6d2953 15
el18gs 4:2e8d7c6d2953 16 // Define a stringvec as a vector of strings
el18gs 6:d755c4c56bdd 17 /** @pulic
el18gs 6:d755c4c56bdd 18 * @var test
el18gs 5:27aa2d0891b7 19 */
el18gs 5:27aa2d0891b7 20 typedef std::vector<std::string> stringvec;
el18gs 4:2e8d7c6d2953 21
el18gs 6:d755c4c56bdd 22 /** @public Enumerated Type called Type
el18gs 6:d755c4c56bdd 23 * Used to illustrate the type or species of a ghost object
el18gs 5:27aa2d0891b7 24 */
el18gs 5:27aa2d0891b7 25 enum Type {BASIC, /**< float for x value */
el18gs 5:27aa2d0891b7 26 ECTO, /**< float for x value */
el18gs 5:27aa2d0891b7 27 POLTER, /**< float for x value */
el18gs 5:27aa2d0891b7 28 ORB, /**< float for x value */
el18gs 5:27aa2d0891b7 29 FUNNEL /**< float for x value */
el18gs 5:27aa2d0891b7 30 };
el18gs 4:2e8d7c6d2953 31
el18gs 4:2e8d7c6d2953 32 /** Ghost Class
el18gs 3:9d811414d35e 33 * @brief revision 0.9
el18gs 4:2e8d7c6d2953 34 * @brief Library for generating and saving .ghost files for the game. Some of
el18gs 4:2e8d7c6d2953 35 * @brief the files need to be imported from the SD others are generated.
el18gs 3:9d811414d35e 36 * @author George Sykes [el18gs]
el18gs 3:9d811414d35e 37 * @date 11 May 2020
el18gs 3:9d811414d35e 38
el18gs 3:9d811414d35e 39 @code
el18gs 4:2e8d7c6d2953 40 sample.ghost file
el18gs 3:9d811414d35e 41 1.ghost:
el18gs 3:9d811414d35e 42 /Type
el18gs 3:9d811414d35e 43 Basic
el18gs 3:9d811414d35e 44 /Name
el18gs 3:9d811414d35e 45 Casper
el18gs 3:9d811414d35e 46 /Attack
el18gs 3:9d811414d35e 47 10
el18gs 3:9d811414d35e 48 /Defense
el18gs 3:9d811414d35e 49 10
el18gs 3:9d811414d35e 50 /Level
el18gs 3:9d811414d35e 51 1
el18gs 3:9d811414d35e 52 /XP
el18gs 3:9d811414d35e 53 0
el18gs 3:9d811414d35e 54 /Value
el18gs 3:9d811414d35e 55 10
el18gs 3:9d811414d35e 56 /HP_max
el18gs 3:9d811414d35e 57 10
el18gs 3:9d811414d35e 58 /HP
el18gs 3:9d811414d35e 59 10
el18gs 3:9d811414d35e 60 /UID
el18gs 3:9d811414d35e 61 1
el18gs 3:9d811414d35e 62 @endcode
el18gs 3:9d811414d35e 63 */
el18gs 3:9d811414d35e 64 class Ghost
el18gs 3:9d811414d35e 65 {
el18gs 3:9d811414d35e 66 public:
el18gs 4:2e8d7c6d2953 67 // Constructors
el18gs 4:2e8d7c6d2953 68 /** Create a Ghost object by importing a .ghost file
el18gs 4:2e8d7c6d2953 69 * @param path The name of the .ghost file to import
el18gs 4:2e8d7c6d2953 70 * @param root The directory to look for the file in
el18gs 4:2e8d7c6d2953 71 */
el18gs 3:9d811414d35e 72 Ghost(const std::string path, const std::string root);
el18gs 4:2e8d7c6d2953 73
el18gs 4:2e8d7c6d2953 74 /** Create a Ghost object using two numbers to define its type and name
el18gs 4:2e8d7c6d2953 75 * @param type an interger number between 0 and 100 to define the type of ghost
el18gs 4:2e8d7c6d2953 76 * @param nameNumber an integer number between 0 and 20 to define the name of the ghost
el18gs 4:2e8d7c6d2953 77 * @param root the directory to save the Ghost object in
el18gs 4:2e8d7c6d2953 78 * @note this constructor will save the object as a .ghost file using the @ref save(void)
el18gs 4:2e8d7c6d2953 79 * @note the UID (Unique ID) of this object will be generated by @ref gen_uid(void)
el18gs 4:2e8d7c6d2953 80 */
el18gs 3:9d811414d35e 81 Ghost(int type, int nameNumber, const std::string root);
el18gs 4:2e8d7c6d2953 82
el18gs 4:2e8d7c6d2953 83 /** List all files in the directory path passed
el18gs 4:2e8d7c6d2953 84 * @param Path directory to list
el18gs 4:2e8d7c6d2953 85 */
el18gs 3:9d811414d35e 86 void listdir(std::string path);
el18gs 4:2e8d7c6d2953 87
el18gs 4:2e8d7c6d2953 88 /** Save the current ghost
el18gs 4:2e8d7c6d2953 89 * @note save the current ghost as a .ghost file, the name of the file is the UID
el18gs 4:2e8d7c6d2953 90 */
el18gs 3:9d811414d35e 91 void save(void);
el18gs 4:2e8d7c6d2953 92
el18gs 4:2e8d7c6d2953 93 /** 'Sell' the ghost, in reality this means deleting its file and returning the value of the ghost
el18gs 4:2e8d7c6d2953 94 * @return an integer
el18gs 4:2e8d7c6d2953 95 */
el18gs 3:9d811414d35e 96 int sell(void);
el18gs 4:2e8d7c6d2953 97
el18gs 4:2e8d7c6d2953 98 /** 'feed' the ghost, this means give it XP equal to the ammount passed
el18gs 4:2e8d7c6d2953 99 * @param ammount of food to feed, this is equal to the xp increase
el18gs 4:2e8d7c6d2953 100 * @note after this function the ghost will be saved using @ref save()
el18gs 4:2e8d7c6d2953 101 */
el18gs 3:9d811414d35e 102 void feed(int ammount);
el18gs 4:2e8d7c6d2953 103
el18gs 4:2e8d7c6d2953 104 /** Print all the member variables over serial
el18gs 4:2e8d7c6d2953 105 * @note primarily used in debugging & development, can be removed if more space needed in final version
el18gs 4:2e8d7c6d2953 106 */
el18gs 3:9d811414d35e 107 void print_all(void);
el18gs 4:2e8d7c6d2953 108
el18gs 4:2e8d7c6d2953 109 /** Get the type of ghost as an enum
el18gs 4:2e8d7c6d2953 110 * @notes uses the type stored in _type
el18gs 4:2e8d7c6d2953 111 * @return an enumerated class value
el18gs 4:2e8d7c6d2953 112 */
el18gs 3:9d811414d35e 113 Type get_type_enum(void);
el18gs 4:2e8d7c6d2953 114
el18gs 4:2e8d7c6d2953 115 /** Get a string version of the type of ghost
el18gs 4:2e8d7c6d2953 116 * @notes uses the type stored in _type
el18gs 4:2e8d7c6d2953 117 * @return an c++ string
el18gs 4:2e8d7c6d2953 118 */
el18gs 3:9d811414d35e 119 std::string get_type_string(void);
el18gs 4:2e8d7c6d2953 120
el18gs 4:2e8d7c6d2953 121 /** Get the name of the ghost
el18gs 4:2e8d7c6d2953 122 * @notes uses the name stored in _name
el18gs 4:2e8d7c6d2953 123 * @return an c++ string
el18gs 4:2e8d7c6d2953 124 */
el18gs 3:9d811414d35e 125 std::string get_name(void);
el18gs 4:2e8d7c6d2953 126
el18gs 4:2e8d7c6d2953 127 /** Get the attack value of the ghost
el18gs 4:2e8d7c6d2953 128 * @notes uses the attack value stored in _attack
el18gs 4:2e8d7c6d2953 129 * @return an interger
el18gs 4:2e8d7c6d2953 130 */
el18gs 3:9d811414d35e 131 int get_attack(void);
el18gs 4:2e8d7c6d2953 132
el18gs 4:2e8d7c6d2953 133 /** Get the defense value of the ghost
el18gs 4:2e8d7c6d2953 134 * @notes uses the defense value stored in _defense
el18gs 4:2e8d7c6d2953 135 * @return an integer
el18gs 4:2e8d7c6d2953 136 */
el18gs 3:9d811414d35e 137 int get_defense(void);
el18gs 4:2e8d7c6d2953 138
el18gs 4:2e8d7c6d2953 139 /** Get the level of the ghost
el18gs 4:2e8d7c6d2953 140 * @notes uses the level stored in _level
el18gs 4:2e8d7c6d2953 141 * @return an integer
el18gs 4:2e8d7c6d2953 142 */
el18gs 3:9d811414d35e 143 int get_level(void);
el18gs 4:2e8d7c6d2953 144
el18gs 4:2e8d7c6d2953 145 /** Get the ammount of XP the ghost has
el18gs 4:2e8d7c6d2953 146 * @notes uses the XP ammount stored in _xp
el18gs 4:2e8d7c6d2953 147 * @return an integer
el18gs 4:2e8d7c6d2953 148 */
el18gs 3:9d811414d35e 149 int get_xp(void);
el18gs 4:2e8d7c6d2953 150
el18gs 4:2e8d7c6d2953 151 /** Get the value of the ghost
el18gs 4:2e8d7c6d2953 152 * @notes uses the value stored in _value
el18gs 4:2e8d7c6d2953 153 * @return an integer
el18gs 4:2e8d7c6d2953 154 */
el18gs 3:9d811414d35e 155 int get_value(void);
el18gs 4:2e8d7c6d2953 156
el18gs 4:2e8d7c6d2953 157 /** Get the maximum HP of the ghost
el18gs 4:2e8d7c6d2953 158 * @notes uses the maximum HP stored in _hp_max
el18gs 4:2e8d7c6d2953 159 * @return an integer
el18gs 4:2e8d7c6d2953 160 */
el18gs 3:9d811414d35e 161 int get_hp_max(void);
el18gs 4:2e8d7c6d2953 162
el18gs 4:2e8d7c6d2953 163 /** Get the current hp value of the ghost
el18gs 4:2e8d7c6d2953 164 * @notes uses the hp value stored in _hp
el18gs 4:2e8d7c6d2953 165 * @return an integer
el18gs 4:2e8d7c6d2953 166 */
el18gs 3:9d811414d35e 167 int get_hp(void);
el18gs 4:2e8d7c6d2953 168
el18gs 4:2e8d7c6d2953 169 /** Get the UID of the ghost
el18gs 4:2e8d7c6d2953 170 * @notes uses the UID (Unique ID) stored in _uid
el18gs 4:2e8d7c6d2953 171 * @return an integer
el18gs 4:2e8d7c6d2953 172 */
el18gs 3:9d811414d35e 173 int get_uid(void);
el18gs 3:9d811414d35e 174
el18gs 3:9d811414d35e 175 private:
el18gs 4:2e8d7c6d2953 176 // Methods
el18gs 3:9d811414d35e 177 int gen_uid(void);
el18gs 3:9d811414d35e 178 bool hasEnding (std::string const &fullString, std::string const &ending);
el18gs 3:9d811414d35e 179
el18gs 3:9d811414d35e 180 std::string type_to_string(Type type);
el18gs 3:9d811414d35e 181 Type string_to_type(std::string type);
el18gs 3:9d811414d35e 182 void delete_file(const char filename[]);
el18gs 3:9d811414d35e 183
el18gs 3:9d811414d35e 184 Type _type;
el18gs 3:9d811414d35e 185 std::string _name;
el18gs 3:9d811414d35e 186 int _attack;
el18gs 3:9d811414d35e 187 int _defense;
el18gs 3:9d811414d35e 188 int _level;
el18gs 3:9d811414d35e 189 int _xp;
el18gs 3:9d811414d35e 190 int _value;
el18gs 3:9d811414d35e 191 int _hp_max;
el18gs 3:9d811414d35e 192 int _hp;
el18gs 3:9d811414d35e 193 int _uid;
el18gs 3:9d811414d35e 194 static const string _suffix;
el18gs 3:9d811414d35e 195 std::string _root;
el18gs 3:9d811414d35e 196
el18gs 3:9d811414d35e 197 stringvec _names;
el18gs 3:9d811414d35e 198 };
el18gs 3:9d811414d35e 199
el18gs 3:9d811414d35e 200 #endif