ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18gs

Dependencies:   mbed

Committer:
el18gs
Date:
Tue May 12 09:21:38 2020 +0000
Revision:
12:8666cd2c6201
Parent:
8:4220d116f17c
Child:
13:3b2a4e14937b
Added magnetometer library doccumentation

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 12:8666cd2c6201 32 * @version 1.0
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 8:4220d116f17c 70 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 71 */
el18gs 8:4220d116f17c 72 Ghost(const std::string path, const std::string root, SDFileSystem &sd);
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 8:4220d116f17c 78 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 79 * @note this constructor will save the object as a .ghost file using the @ref save(void)
el18gs 4:2e8d7c6d2953 80 * @note the UID (Unique ID) of this object will be generated by @ref gen_uid(void)
el18gs 4:2e8d7c6d2953 81 */
el18gs 8:4220d116f17c 82 Ghost(int type, int nameNumber, const std::string root, SDFileSystem &sd);
el18gs 4:2e8d7c6d2953 83
el18gs 4:2e8d7c6d2953 84 /** List all files in the directory path passed
el18gs 4:2e8d7c6d2953 85 * @param Path directory to list
el18gs 8:4220d116f17c 86 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 87 */
el18gs 8:4220d116f17c 88 void listdir(std::string path, SDFileSystem &sd);
el18gs 4:2e8d7c6d2953 89
el18gs 4:2e8d7c6d2953 90 /** Save the current ghost
el18gs 8:4220d116f17c 91 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 92 * @note save the current ghost as a .ghost file, the name of the file is the UID
el18gs 4:2e8d7c6d2953 93 */
el18gs 8:4220d116f17c 94 void save(SDFileSystem &sd);
el18gs 4:2e8d7c6d2953 95
el18gs 4:2e8d7c6d2953 96 /** 'Sell' the ghost, in reality this means deleting its file and returning the value of the ghost
el18gs 8:4220d116f17c 97 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 98 * @return an integer
el18gs 4:2e8d7c6d2953 99 */
el18gs 8:4220d116f17c 100 int sell(SDFileSystem &sd);
el18gs 4:2e8d7c6d2953 101
el18gs 4:2e8d7c6d2953 102 /** 'feed' the ghost, this means give it XP equal to the ammount passed
el18gs 4:2e8d7c6d2953 103 * @param ammount of food to feed, this is equal to the xp increase
el18gs 8:4220d116f17c 104 * @param sd Pointer to an SDFileSystem object
el18gs 4:2e8d7c6d2953 105 * @note after this function the ghost will be saved using @ref save()
el18gs 4:2e8d7c6d2953 106 */
el18gs 8:4220d116f17c 107 void feed(int ammount, SDFileSystem &sd);
el18gs 4:2e8d7c6d2953 108
el18gs 4:2e8d7c6d2953 109 /** Print all the member variables over serial
el18gs 4:2e8d7c6d2953 110 * @note primarily used in debugging & development, can be removed if more space needed in final version
el18gs 4:2e8d7c6d2953 111 */
el18gs 3:9d811414d35e 112 void print_all(void);
el18gs 4:2e8d7c6d2953 113
el18gs 4:2e8d7c6d2953 114 /** Get the type of ghost as an enum
el18gs 4:2e8d7c6d2953 115 * @notes uses the type stored in _type
el18gs 4:2e8d7c6d2953 116 * @return an enumerated class value
el18gs 4:2e8d7c6d2953 117 */
el18gs 3:9d811414d35e 118 Type get_type_enum(void);
el18gs 4:2e8d7c6d2953 119
el18gs 4:2e8d7c6d2953 120 /** Get a string version of the type of ghost
el18gs 4:2e8d7c6d2953 121 * @notes uses the type stored in _type
el18gs 4:2e8d7c6d2953 122 * @return an c++ string
el18gs 4:2e8d7c6d2953 123 */
el18gs 3:9d811414d35e 124 std::string get_type_string(void);
el18gs 4:2e8d7c6d2953 125
el18gs 4:2e8d7c6d2953 126 /** Get the name of the ghost
el18gs 4:2e8d7c6d2953 127 * @notes uses the name stored in _name
el18gs 4:2e8d7c6d2953 128 * @return an c++ string
el18gs 4:2e8d7c6d2953 129 */
el18gs 3:9d811414d35e 130 std::string get_name(void);
el18gs 4:2e8d7c6d2953 131
el18gs 4:2e8d7c6d2953 132 /** Get the attack value of the ghost
el18gs 4:2e8d7c6d2953 133 * @notes uses the attack value stored in _attack
el18gs 4:2e8d7c6d2953 134 * @return an interger
el18gs 4:2e8d7c6d2953 135 */
el18gs 3:9d811414d35e 136 int get_attack(void);
el18gs 4:2e8d7c6d2953 137
el18gs 4:2e8d7c6d2953 138 /** Get the defense value of the ghost
el18gs 4:2e8d7c6d2953 139 * @notes uses the defense value stored in _defense
el18gs 4:2e8d7c6d2953 140 * @return an integer
el18gs 4:2e8d7c6d2953 141 */
el18gs 3:9d811414d35e 142 int get_defense(void);
el18gs 4:2e8d7c6d2953 143
el18gs 4:2e8d7c6d2953 144 /** Get the level of the ghost
el18gs 4:2e8d7c6d2953 145 * @notes uses the level stored in _level
el18gs 4:2e8d7c6d2953 146 * @return an integer
el18gs 4:2e8d7c6d2953 147 */
el18gs 3:9d811414d35e 148 int get_level(void);
el18gs 4:2e8d7c6d2953 149
el18gs 4:2e8d7c6d2953 150 /** Get the ammount of XP the ghost has
el18gs 4:2e8d7c6d2953 151 * @notes uses the XP ammount stored in _xp
el18gs 4:2e8d7c6d2953 152 * @return an integer
el18gs 4:2e8d7c6d2953 153 */
el18gs 3:9d811414d35e 154 int get_xp(void);
el18gs 4:2e8d7c6d2953 155
el18gs 4:2e8d7c6d2953 156 /** Get the value of the ghost
el18gs 4:2e8d7c6d2953 157 * @notes uses the value stored in _value
el18gs 4:2e8d7c6d2953 158 * @return an integer
el18gs 4:2e8d7c6d2953 159 */
el18gs 3:9d811414d35e 160 int get_value(void);
el18gs 4:2e8d7c6d2953 161
el18gs 4:2e8d7c6d2953 162 /** Get the maximum HP of the ghost
el18gs 4:2e8d7c6d2953 163 * @notes uses the maximum HP stored in _hp_max
el18gs 4:2e8d7c6d2953 164 * @return an integer
el18gs 4:2e8d7c6d2953 165 */
el18gs 3:9d811414d35e 166 int get_hp_max(void);
el18gs 4:2e8d7c6d2953 167
el18gs 4:2e8d7c6d2953 168 /** Get the current hp value of the ghost
el18gs 4:2e8d7c6d2953 169 * @notes uses the hp value stored in _hp
el18gs 4:2e8d7c6d2953 170 * @return an integer
el18gs 4:2e8d7c6d2953 171 */
el18gs 3:9d811414d35e 172 int get_hp(void);
el18gs 4:2e8d7c6d2953 173
el18gs 4:2e8d7c6d2953 174 /** Get the UID of the ghost
el18gs 4:2e8d7c6d2953 175 * @notes uses the UID (Unique ID) stored in _uid
el18gs 4:2e8d7c6d2953 176 * @return an integer
el18gs 4:2e8d7c6d2953 177 */
el18gs 3:9d811414d35e 178 int get_uid(void);
el18gs 3:9d811414d35e 179
el18gs 3:9d811414d35e 180 private:
el18gs 4:2e8d7c6d2953 181 // Methods
el18gs 8:4220d116f17c 182 int gen_uid(SDFileSystem &sd);
el18gs 3:9d811414d35e 183 bool hasEnding (std::string const &fullString, std::string const &ending);
el18gs 3:9d811414d35e 184
el18gs 3:9d811414d35e 185 std::string type_to_string(Type type);
el18gs 3:9d811414d35e 186 Type string_to_type(std::string type);
el18gs 8:4220d116f17c 187 void delete_file(const char filename[], SDFileSystem &sd);
el18gs 3:9d811414d35e 188
el18gs 3:9d811414d35e 189 Type _type;
el18gs 3:9d811414d35e 190 std::string _name;
el18gs 3:9d811414d35e 191 int _attack;
el18gs 3:9d811414d35e 192 int _defense;
el18gs 3:9d811414d35e 193 int _level;
el18gs 3:9d811414d35e 194 int _xp;
el18gs 3:9d811414d35e 195 int _value;
el18gs 3:9d811414d35e 196 int _hp_max;
el18gs 3:9d811414d35e 197 int _hp;
el18gs 3:9d811414d35e 198 int _uid;
el18gs 3:9d811414d35e 199 static const string _suffix;
el18gs 3:9d811414d35e 200 std::string _root;
el18gs 3:9d811414d35e 201
el18gs 3:9d811414d35e 202 stringvec _names;
el18gs 3:9d811414d35e 203 };
el18gs 3:9d811414d35e 204
el18gs 3:9d811414d35e 205 #endif