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