ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18gs

Dependencies:   mbed

Committer:
el18gs
Date:
Mon May 11 18:28:37 2020 +0000
Revision:
7:220d3ebf74cf
Parent:
6:d755c4c56bdd
Child:
8:4220d116f17c
Added additional details to the Enum Type 'Type' doccumentations;

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