Dayo Posted January 6, 2014 Share Posted January 6, 2014 (edited) Over the Christmas period i was ill so could not do as much as work on GL v2 as i planned, but i have done enough to warrant an small update for everyone. The core framework is at a point where i am happy with it so i can start on adding features/modules to the script, currently i have added the following features: - crimes - car thefts - Police Chases - Garage - Bullet Factory's - Travel - Jail A small example of a module is below <?php class module { private $html = ''; public $pageName = 'Police Chase'; public function __construct () { global $page, $user, $db; if (isset($_GET['move'])) { $this->move(); } $this->html .= $page->buildElement('policeChase', array()); } public function htmlOutput() { return $this->html; } public function timeLeft($ts) { return date('H:i:s', $ts); } private function move() { global $db, $page, $user; if (time() < $user->info->US_chaseTimer) { $time = $user->info->US_chaseTimer - time(); $crimeError = array('You cant commit another theft untill your timer is up! ('.$this->timeLeft($time).')'); $this->html .= $page->buildElement('error', $crimeError); } else { $rand = mt_rand(1, 4); if ($rand == 1) { $winnings = mt_rand(150, 850) * $user->info->US_rank; $u = $db->prepare("UPDATE userStats SET US_chaseTimer = ".(time()+300).", US_money = US_money + $winnings WHERE US_id = ".$user->id); $u->execute(); $this->html .= $page->buildElement('success', array('You got away, you were paid $'.number_format($winnings).'!')); } else if ($rand == 3) { $u = $db->prepare("UPDATE userStats SET US_chaseTimer = ".(time()+300).", US_jailTimer = ".(time() + 150)." WHERE US_id = ".$user->id); $u->execute(); $this->html .= $page->buildElement('error', array('You crashed and was sent to jail!')); } else { $this->html .= $page->buildElement('info', array('You are still going, what dirrection do you want to go now?')); } } } } ?> Please note this module is a bit old and is missing some things that i am currently working on now, things like if (time() < $user->info->US_chaseTimer) { ... are changed to if(!$user->timerCheck('chase')) { ... I will be adding a live demo as soon as i get home as my work has blocked the port i use to connect to my control panel Here are some screen shots http://imgur.com/a/eBkZt the styling is minimal at best, im no designer lol Edited January 6, 2014 by Dayo Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 Nice! I'd of had class module { as the parent of all modules, and extended that class for each respective module; class policeChase extends module { Then had core module logic in the module class. :) Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 Nice! I'd of had class module { as the parent of all modules, and extended that class for each respective module; class policeChase extends module { Then had core module logic in the module class. :) That makes sense, while there are only a few modules i think i may have to do that, there were a few global functions i had to re-declare in each module (i.e. timeLeft()) this would be much easier if i done what you said in the first place. Ill get on that now, should nottake too long :) Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 That makes sense, while there are only a few modules i think i may have to do that, there were a few global functions i had to re-declare in each module (i.e. getDate()) this would be much easier if i done what you said in the first place. Ill get on that now, should nottake too long :) Awesome! However, is getDate module specific, or core specific? It sounds like something that I would put in the core class, rather than a module class. But it's your design, so you choose - as it's just my opinion :) Quote Link to comment Share on other sites More sharing options...
Guest Posted January 6, 2014 Share Posted January 6, 2014 Agree with Sniko, extend the module class and cut out the globals I am looking forward to seeing new updates :) Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 Awesome! However, is getDate module specific, or core specific? It sounds like something that I would put in the core class, rather than a module class. But it's your design, so you choose - as it's just my opinion :) It is more module specific as its mainly used for timers (i.e. i have 00:01:12 left before i can commit another crime) probably should use a better name then getDate maybe timeLeft Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 It is more module specific as its mainly used for timers (i.e. i have 00:01:12 left before i can commit another crime) probably should use a better name then getDate maybe timeLeft But; public function timeLeft($ts) { return date('H:i:s', $ts); } Would indicate repeated code, if it was in the extended class (module specific class), would it not? Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 Yea sorry i have my wires mixed, having 3 different convos at once :P You are correct that this will be used several times across several modules, this will be coded into the core "module" class rather then each individual module (like it was) I have made the changes now im just adding to the module class so you will be able to get repeated information with ease (i.e. location names, car names/info etc ...) Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 Yea sorry i have my wires mixed, having 3 different convos at once :P You are correct that this will be used several times across several modules, this will be coded into the core "module" class rather then each individual module (like it was) I have made the changes now im just adding to the module class so you will be able to get repeated information with ease (i.e. location names, car names/info etc ...) Nice one! Are you using version control for this project, such as Git? Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 I have a source-forge project that i will be committing to soon, just want to neaten up the code a bit and add a few functions that will be useful when developing. Ive never used git before as ive got use to SVN maybe ill take a look at it if people prefer it. Note: The modules don't require global $page, $db, $user; you can now use $this->page->... $this->db->... and $this->user->... just going throgh the modules now and removing all the old globals (glad im making these changes early on rather then when there is 20 modules lol) Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 Note: The modules don't require global $page, $db, $user; you can now use $this->page->... $this->db->... and $this->user->... just going throgh the modules now and removing all the old globals (glad im making these changes early on rather then when there is 20 modules lol) Awesome. I have a source-forge project that i will be committing to soon, just want to neaten up the code a bit and add a few functions that will be useful when developing. Ive never used git before as ive got use to SVN maybe ill take a look at it if people prefer it. I prefer Git personally, as that's what I use at work (and now for personal private projects, too) Quote Link to comment Share on other sites More sharing options...
Guest Posted January 6, 2014 Share Posted January 6, 2014 class Crimes extends Module { public function __construct() { //Work out what to do if(isset($_GET['action'])) { switch($_GET['action']) { case 'viewcrimes': $this->viewCrimes(); break; } } if(isset($_POST['commit'])) { $this->commitCrime(); } } private function viewCrimes() { //Do work to display the crimes page $this->smarty->assign('crimes1', 'Mug a passerby'); $this->smarty->display('crimes.shtml'); } private function commitCrime() { //Do crime stuff } } however in a perfect scenario the application should manage POST & GET then execute the correct action for example if public function action_commit() { } The framework would call the action_* where * is the post request. Eww sourceforge, might not commit much as I dislike there apps. Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2014 Share Posted January 6, 2014 class Crimes extends Module { public function __construct() { //Work out what to do if(isset($_GET['action'])) { switch($_GET['action']) { case 'viewcrimes': $this->viewCrimes(); break; } } if(isset($_POST['commit'])) { $this->commitCrime(); } } private function viewCrimes() { //Do work to display the crimes page $this->smarty->assign('crimes1', 'Mug a passerby'); $this->smarty->display('crimes.shtml'); } private function commitCrime() { //Do crime stuff } } however in a perfect scenario the application should manage POST & GET then execute the correct action for example if public function action_commit() { } The framework would call the action_* where * is the post request. Eww sourceforge, might not commit much as I dislike there apps. Wait, what? Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 Ive always used SVN at work but i see more and more people using GIT after i have got V2 to a decent point ill look into GIT, dont want to swamp myself with several things at once. Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 class Crimes extends Module { public function __construct() { //Work out what to do if(isset($_GET['action'])) { switch($_GET['action']) { case 'viewcrimes': $this->viewCrimes(); break; } } if(isset($_POST['commit'])) { $this->commitCrime(); } } private function viewCrimes() { //Do work to display the crimes page $this->smarty->assign('crimes1', 'Mug a passerby'); $this->smarty->display('crimes.shtml'); } private function commitCrime() { //Do crime stuff } } however in a perfect scenario the application should manage POST & GET then execute the correct action for example if public function action_commit() { } The framework would call the action_* where * is the post request. Eww sourceforge, might not commit much as I dislike there apps. This sounds interesting, we use something similar at work, will neaten up having if (isset($_POST['...'])) {} at the top of each module how a module would then work is like so class garage extends module { public function constructModule() { // Build the module here } public function method_sell() { // Sell your car } public function method_repair() { // Repair your car $car = $this->methodData->car; // ($_GET['car']) } } Quote Link to comment Share on other sites More sharing options...
Guest Posted January 6, 2014 Share Posted January 6, 2014 This sounds interesting, we use something similar at work, will neaten up having if (isset($_POST['...'])) {} at the top of each module how a module would then work is like so class garage extends module { public function constructModule() { // Build the module here } public function method_sell() { // Sell your car } public function method_repair() { // Repair your car $car = $this->methodData->car; // ($_GET['car']) } } I like it, but how can you differentiate between get and post? We use getters and setters for storing most information from datasets. Maybe post_action and get_action, that way you can use the same name for different things? Oh and added you on Skype :) Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 Ill log into my skype now :) What i was thinking is when you make a module you have to register the globals you will use for that module kind of like this class garage extends module { public $allowedMethods = array('car'=>array('GET', 'int'), 'randomVar'=>array('POST', 'varchar')); public function constructModule() { // Build the module here } public function method_sell() { // Sell your car } public function method_repair() { // Repair your car $car = $this->methodData->car; // ($_GET['car']) } } From the allowed methods you can then build the methodData array from what i have added you can also add validation at this stage i.e. only allowing numbers if the type is set as a int Quote Link to comment Share on other sites More sharing options...
Guest Posted January 6, 2014 Share Posted January 6, 2014 Ill log into my skype now :) What i was thinking is when you make a module you have to register the globals you will use for that module kind of like this class garage extends module { public $allowedMethods = array('car'=>array('GET', 'int'), 'randomVar'=>array('POST', 'varchar')); public function constructModule() { // Build the module here } public function method_sell() { // Sell your car } public function method_repair() { // Repair your car $car = $this->methodData->car; // ($_GET['car']) } } From the allowed methods you can then build the methodData array from what i have added you can also add validation at this stage i.e. only allowing numbers if the type is set as a int Interesting, being able to filter information that way, use __construct instead of constructModule(). I'll keep my eye on updates. Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 I use __construct in the module class what in turn calls constructModule() i done it like this so i can set the $this->(page|db|user) variables before the module is set up. BTW i will check out GIT if its easy to pick up ill use that for my version controll Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 https://github.com/ChristopherDay/Gangster-Legends-V2 is the URL of the GIT Repository, just tested out committing and seamed rather painless so will try it out, once i have made a few changes ill commit what i have so far :) Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 6, 2014 Author Share Posted January 6, 2014 I have just committed what i have done so far, PLEASE NOTE this is not ready for you to make a game from, it has not gone through full testing for bugs/exploits. There is still sections of the script that code wise is very ugly (the template system is an example (im currently re-working it so you don't have to have an include for each module)) i am working on improving the core files, if you have any thoughts feel free to PM me, Post below or email me at [email protected]! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.