Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-09-2005, 05:44 PM   #1
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
PHP Game Questions

Hey all! I have been working on creating a MMO game in PHP using MySQL databases, and I need some help. The game will be turn based, meanin that when a player does something (i.e. attacks) it takes a certain number of turns. When someone registers, they have 75 turns. I need a way to give the player 10 turns every hour, whether they are logged in or not. What is an easy way to do this?
__________________
Main Computer: Intel Core i5 2500K | AsRock Extreme3 Z68 | Corsair Vengeance 2 x 4GB DDR3 1600 | EVGA GTX460 768MB | Western Digital Caviar 750GB 7200RPM SATAII | Mushkin 60GB SSD w/ SRT enabled | Asus 20X DVD Burner | Antec 550W Modular | Cooler Master HAF 912 w/ 4 fans | NXZT Sentry Mesh fan controller | W7 | 2 x 23" LG IPS Monitors

Laptop: Asus EEE 1000HE | 2GB RAM | Ubuntu

Laptop: Lenovo Thinkpad T60p | 4GB RAM | W7
catacon is offline   Reply With Quote
Old 03-10-2005, 09:53 AM   #2
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Just log the start time of their first move, the number of moves they have left, and the time of the last time you added moves. From there you can do a calculation of the number of hours elasped from their last move and add to their turns accordingly.
faulkner132 is offline   Reply With Quote
Old 03-11-2005, 03:58 PM   #3
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
First move meaning what? How do I log the last move they made, get the time now, and what would the calcuation look like? I tried that, but I couldn't get it to work.
catacon is offline   Reply With Quote
Old 03-13-2005, 04:12 PM   #4
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
Anyone? Anyone at all?
catacon is offline   Reply With Quote
Old 03-14-2005, 11:00 AM   #5
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
You really only need to log the last time you calculated how many moves they have left. From this time when you run the new calculation to see how many new moves they have, determine the number of moves from the old time.

Update the calculated time and you should be able to repeat this procedure.
faulkner132 is offline   Reply With Quote
Old 03-14-2005, 02:00 PM   #6
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
Again, what would these calcuations look like?
catacon is offline   Reply With Quote
Old 03-15-2005, 11:05 AM   #7
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Don't know the functions off the top of my head, but PHP has an extensive collection of date/time functions. You can use these to determine the number of hours difference from one time to another.
faulkner132 is offline   Reply With Quote
Old 03-18-2005, 09:46 AM   #8
Member (2 bit)
 
Join Date: Mar 2005
Posts: 3
Here's a usefull function for you:
PHP Code:
<?php 
function getmicrotime(){ 
   list(
$usec$sec) = explode(" ",microtime()); 
   return ((float)
$usec + (float)$sec); 

$last_turngetmicrotime(); // <-- This is the timestamp representing "When was the last time the player received turns, gold or whatever, this will be uploaded in the database.

// CODE TO BE INTRODUCED IN EVERY PAGE OF THE GAME:
$now getmicrotime(); // <-- gets the timestamp in the moment the player loads the page.

$secs_passed $now $last_turn// seconds passed since the last turn
$min_passed = ($now $last_turn) * 60// minutes passed since....
$hours_passed = ($now $last_turn)* 3600// hours passed since...

if($hours_passed 0){ //If more than 1 hour has passed since the last turn...
  
Update_rankings_code(); // Here you can add a update ranking code to
                                    // update the rank tables every hour
  
$gold_per_turn=10
  
$moves_per_turn=10;
  
$gold=$hours_passed*$gold_per_turn;
  
$moves=$hours_passed*$moves_per_turn;
}
?>
And so on
Notice: This may not be valid code. I used it just to show you the utility of the getmicrotime() function. I hope you get the ideea.

Last edited by radiopunk; 03-18-2005 at 10:11 AM.
radiopunk is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:19 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2