This code, written in C#, is not meant to be used on its own. Instead, it should be imported or copied into an existing project (originally meant for a Unity game project) and used as a library.
Before you use this library, you should have an instance of the zombie-run-iv-api running. Put the URL it is running on into the field at the top of zombie-run-api-client/ApiClient.cs. Ideally, you would have this URL in some global configuration variable, which you would place there instead.
In addition to having the actual API up and running, you should probably come up with a way to uniquely identify devices through the zombie-run-api-client/Util.cs "getDeviceID()" function. This could return the device's MAC address, the Processor ID, or some other UUID you can retrieve from the machine the program will be running on.
The usage as thought out when developing this library is as follows:
- Retrieve name from user
- Retrieve Player object via
ApiClient.getPlayer(name)
- ...Do other system things with app...
- Use other operations on Player object and ApiClient as needed.
* to get list of high scores:
ApiClient.getScores()
* to add a new high score:player.addScore(score_int)
* to get players's high score:player.getScores()
* to update players' hifive_count value:player.setHiFives(count)
player.saveHiFives()
* to update players' characters value:player.setCharacters(value)
player.saveCharacters()
* to update players' powerup_lvl:player.setPowerupLvl(level)
player.savePowerupLvl()
-
Fields
string URL
- the URL the API is running on
-
Methods: (all statically called, i.e.
ApiClient.getPlayer("nick")
)Player getPlayer(string name)
- Preconditions:
name
is some defined stringUtil.getDeviceID()
has been defined to return a device UUID- The zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- If a player with
name
on the current device already exists, that player is returned; otherwise the player is created and sent to the API - A Player class object corresponding to the database record is returned
- If a player with
- Preconditions:
List<Score> getScores()
- Preconditions:
- zombie-run-iv-api is online and referenced in
ApiClient
- zombie-run-iv-api is online and referenced in
- Postconditions:
- returns a list of high scores from the API server
- Preconditions:
List<Score> getScores(string name)
:- Preconditions:
name
is some defined stringUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- returns a list of high scores earned by player with name
name
on current device from the API server
- returns a list of high scores earned by player with name
- Preconditions:
List<Score> getScores(Player player)
:- Preconditions:
player
is some defined Player objectUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- returns a list of high scores earned by player
player
from API server
- returns a list of high scores earned by player
- Preconditions:
int newScore(int score, string name)
:- Preconditions:
name
is some defined stringUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- A new score corresponding to the parameters has been created on the API server
- Returns the rank of the new score
- Preconditions:
int newScore(Score score)
:- Preconditions:
score
is some defined Score objectUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- A new score corresponding to the parameter has been created on the API server
- Returns the rank of the new score
- Preconditions:
bool saveHiFives(int pid, int val)
:- Preconditions:
pid
corresponds to an existing Player on the API serverUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- The
hifive_count
field of the player has been updated on the API server and database - Returns a boolean of whether the operation was a success
- The
- Preconditions:
bool saveCharacters(int pid, int val)
:- Preconditions:
pid
corresponds to an existing Player on the API serverUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- The
characters
field of the player has been updated on the API server and database - Returns a boolean of whether the operation was a success
- The
- Preconditions:
bool savePowerupLvl(int pid, int val)
:- Preconditions:
pid
corresponds to an existing Player on the API serverUtil.getDeviceID()
has been defined to return a device UUID- zombie-run-iv-api is online and referenced in
ApiClient
- Postconditions:
- The
powerup_lvl
field of the player has been updated on the API server and database - Returns a boolean of whether the operation was a success
- The
- Preconditions:
The Player class corresponds to an individual player
object from the API and its database. Most operations required can be completed through an object of this class type.
-
Fields:
int id
- the unique ID of this player in the databasestring name
- the name of this playerstring device_id
- the UUID of the device this player is registered onint hifive_count
- the number of high fives this player has obtained over their entire careerint characters
- the number of characters this player has unlockedint powerup_lvl
- the powerup level this player has reached
-
Methods:
Player (int id, string name, int hifive_count, int characters, int powerup_lvl)
:- Preconditions: None
- Postconditions: an object instance of
Player
is returned
int getID()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
id
attribute value is returned
string getName()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
name
attribute value is returned
string getDeviceID()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
device_id
attribute value is returned
int getHiFives()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
hifive_count
attribute value is returned
void setHiFives(int val)
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
hifive_count
attribute value is updated to beval
void saveHiFives()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the API server's database has been updated to reflect the current
hifive_count
value
int getCharacters()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
characters
attribute value is returned
void setCharacters(int val)
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
characters
attribute value is updated to beval
void saveCharacters()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the API server's database has been updated to reflect the current
characters
value
int getPowerupLvl()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
powerup_lvl
attribute value is returned
void setPowerupLvl(int val)
:- Preconditions: the calling object has been properly instantiated
- Postconditions: the
powerup_lvl
attribute value is updated to beval
void savePowerupLvl()
- Preconditions: the calling object has been properly instantiated
- Postconditions: the API server's database has been updated to reflect the current
powerup_lvl
value
List<Score> getScores()
:- Preconditions: the calling object has been properly instantiated
- Postconditions: returns a list of all the scores achieved by the player record this object refers to
int addScore(int score)
:- Preconditions: the calling object has been properly instantiated
- Postconditions:
- A new score corresponding to the parameter has been created on the API server
- The rank of the new score is returned
-
Fields:
int score
- the score in reference by this objectstring name
- the name of the owner of this scoreDateTime time
- the time at which this score was created
-
Methods:
Score (int score, string name, string time)
:- Preconditions: None
- Postconditions: an object instance of
Score
is returned
string toJson()
- returns the json representation of this score- Preconditions: the calling object has been properly instantiated
- Postconditions: a string is returned which represents this object in JSON format
Licensed under the MIT License.
Please use GitHub issues for support requests.