Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > General > PHP Games

PHP Games Like Games?, Like PHP?...

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-09-02, 04:59 PM
Junior Member
 
Join Date: Sep 2006
Posts: 4
dumbwaiters is on a distinguished road
Default RPG City Search question

Has anyone here ever written code for an RPG that invloves some sort of search?

Specifically what I am trying to do is write code that will give a player 250 "search moves" per day and allow them the chance of finding money, an object, or nothing. I would like to randomize the money found to $5, $10, $15, or $20, and the objects to 1, 2, or 3.

I've been searching for tutorials or examples but keep coming up short. Any guidance is appreciated.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-09-03, 04:38 AM
Junior Member
 
Join Date: Sep 2006
Posts: 1
Sinzygy is on a distinguished road
Default

uhm, i guess i would do it this way:

PHP Code:
function random_search($s_moves)
{
    if(
$s_moves >= 1)
    {
        
$rand round(rand(1,7));

        if(
$rand == 1)
        {
            
//Found nothing
        
}
    
        else if(
$rand == 2)
        {
            
//Found $5
        
}

        
// go on like this, for every number a special event

    
        //Now you gotta decrease the players search moves by one

        //and now return your result
    
}


If you want to make some events occur with different chances:

Just change
PHP Code:
$rand round(rand(1,7)); 
to
PHP Code:
$rand round(rand(1,100)); 
and then
PHP Code:
        if($rand <= 50)
        {
            
//50% chance to find nothing
        
}
    
        else if(
$rand 50 && =<60)
        {
            
//105 chance to find $5
        

hope that helps.

- Sinzygy
Reply With Quote
  #3 (permalink)  
Old 2006-09-03, 08:38 AM
Junior Member
 
Join Date: Sep 2006
Posts: 4
dumbwaiters is on a distinguished road
Default

That looks great, thank you very much!
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:21 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.