-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.php
54 lines (46 loc) · 2.01 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*************************************************************
* This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
* Feel free to distribute and modify code, but keep reference to its creator
*
* Gamify class allows to implement game logic into PHP aplications.
* It can create needed tables for storing information on most popular database platforms using PDO.
* It also can add users, define levels and achievements and generate user statistics and tops.
* Then it is posible to bind class functions to user actions, to allow them gain experience and achievements.
*
* For more information, examples and online documentation visit:
* http://webcodingeasy.com/PHP-classes/Implement-game-logic-to-your-web-application
**************************************************************/
include("./gamify.php");
//create class instance with database connection
$g = new gamify("localhost", "root", "password", "gamify");
//output pdo errors
$g->debug();
//create sql tables (only for the first time)
$g->install();
//create new user
//providing username
$g->create_user("ar2rsawseen");
//create new level
//providing level name and experience needed
$g->create_level("First level", 100);
//create new achievement for click every 24 hours
//providing achievement name, actions needed,
//time period in seconds between actions,
//optional achievement badge and description
$g->create_achievement("Clicker", 100, 60*60*24, "./cbadge.png", "Do 100 clicks");
echo "<pre>";
//add experience to created user and output new gained level
//by providing username and amount of experience
print_r($g->add_experience("ar2rsawseen", 100));
//automatically create user if it doesn't exist and add experience
//by providing username and amount of experience
print_r($g->add_experience("ar2rs", 50));
//output user information and errors if any
//output information about users
print_r($g->get_user("ar2rsawseen"));
print_r($g->get_user("ar2rs"));
//output errors
print_r($g->get_errors());
echo "</pre>";
?>