Code Search for Developers
 
 
  

Random.php from Astrum Futura at Krugle


Show Random.php syntax highlighted

<?php
/**
 * @internal
 * Quantum Game Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the text file LICENSE located in the root
 * directory of this library.
 * It is also available through the internet at this URL:
 * http://doc.astrumfutura.com/license.html
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the internet, please send an email
 * to license@astrumfutura.com so we can send you a copy.
 *
 * @package    Map
 * @subpackage Position
 * @category   Quantum
 * @copyright  Copyright (c) 2007 The QGL Group (refer to COPYRIGHT file)
 * @version    $Id: Random.php 210 2007-02-03 02:55:49Z santosj $
 * @license    http://doc.astrumfutura.com/license.html     New BSD License
 */

/** Quantum_Map_Exception */
require_once 'Quantum/Map/Exception.php';

/** Quantum_Coordinate_Node_Star */
require_once 'Quantum/Coordinate/Node/Star.php';

/** Quantum_Coordinate_Array */
require_once 'Quantum/Coordinate/Array.php';

/** Quantum_Map_Star_Position_Interface */
require_once 'Quantum/Map/Star/Position/Interface.php';

/**
 * Simple first implementation of a Position scheme. Positions Stars at
 * random across a Sector Grid.
 *
 * @package    Map
 * @subpackage Position
 * @category   Quantum
 * @author     Pádraic Brady (http://blog.astrumfutura.com)
 */
class Quantum_Map_Star_Position_Random 
    implements Quantum_Map_Star_Position_Interface
{
    
    public function __construct()
    {  
    }

    public function position(Quantum_Map_Grid_Abstract $grid, $stars)
    {
        $stars = (int) $stars; // Make sure stars is an integer
        if($stars < 0)
        {
            $stars = 1;
        }
        
        $gridWidth = $grid->getWidth();
        $gridHeight = $grid->getHeight();
        $centreX = floor($gridWidth / 2);
        $centreY = floor($gridHeight / 2);

        $starPositions = new Quantum_Coordinate_Array();
        
        for($starIndex=0;$starIndex<$stars;++$starIndex)
        {
            $x = mt_rand(0, $gridWidth-1);
            $y = mt_rand(0, $gridHeight-1);
            
            $starNode = new Quantum_Coordinate_Node_Star($x, $y);
            $starPositions->append($starNode);
        }

        return $starPositions;
    }

}



See more files for this project here

Astrum Futura

Multiplayer space strategy game written in PHP5 with the Zend Framework. User interface uses Javascript/AJAX for dynamic interaction. Players compete across a hexagonal map of 10,000 sectors, planets, stars and other locations through trade and combat.

Project homepage: http://sourceforge.net/projects/astrumfutura
Programming language(s): PHP,XML
License: other

  Interface.php
  Random.php