ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18gs

Dependencies:   mbed

Committer:
el18gs
Date:
Mon May 11 17:43:49 2020 +0000
Revision:
5:27aa2d0891b7
Parent:
4:2e8d7c6d2953
Child:
6:d755c4c56bdd
Doxygen testing 4

Who changed what in which revision?

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