PHP Classes

File: start.php

Recommend this page to a friend!
  Classes of Arturs Sosins   Gamify   start.php   Download  
File: start.php
Role: Example script
Content type: text/plain
Description: generate needed tables, create some users, levels, achievements example
Class: Gamify
Manage user points to implement site game logic
Author: By
Last change:
Date: 12 years ago
Size: 2,109 bytes


Class file image Download
 * This script is developed by Arturs Sosins aka ar2rsawseen,
 * 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:
//create class instance with database connection
$g = new gamify("localhost", "root", "password", "gamify");

//output pdo errors

//create sql tables (only for the first time)

//create new user
//providing username

//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");

//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
//output errors