Location: PHPKode > projects > Babylon 5: Upheaval > b5-upheaval/php_functions/create_universe.php
<!--    

	Copyright 2007 Martin Remisch

	This file is part of "Babylon 5: Upheaval".

    "Babylon 5: Upheaval" is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as published 
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Babylon 5: Upheaval" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Babylon 5: Upheaval".  If not, see <http://www.gnu.org/licenses/>.

 -->

<?php


	session_start();
	error_reporting(E_ALL);
	include_once('../db_include.inc');	

	define('ausdehnung'	,   25);			//spielfeldabmaße -> 25 * 25 = 625 felder
	define('dichte'		,	107);			//planetendichte  -> 107 planten

	mysql_connect(HOST,USER,PASS)or die(mysql_error());
	mysql_select_db(DATABASE) or die(mysql_error());

	$koord = array();
	$art   = array('terranisch','aquatisch','gasförmig','lavatisch','raum');

	$bewohnt = 0;
	$zeile = 0;
	
   for($i=0; $i < (ausdehnung * ausdehnung); $i++)
   {

		if ($bewohnt < dichte) 
		{
			$koord[$i] = 1;
			$bewohnt++;
		}
		else
		{
			$koord[$i] = 0;
		}
   }

	shuffle($koord);

	$x = 0;
	$y = 0;	
	$a = 0;
	srand(microtime()*1000000);
	
	for ($i=0; $i < (ausdehnung * ausdehnung); $i++)
	{
		$x = ($i % ausdehnung)+1;
		if (($i % ausdehnung) == 0) { $y++; }
		if ($koord[$i] == 1) { $a = rand(0,3); } else {$a = 4;}
		if ($art[$a] != 'raum')
		{
			$sql = "INSERT INTO universum (x,y,besitzer,typ) VALUES ('$x','$y','keiner','$art[$a]')";
		}
		else
		{
			$sql = "INSERT INTO universum (x,y,besitzer,typ) VALUES ('$x','$y','','$art[$a]')";	
		}
		mysql_query($sql);
	}
	
?>
Return current item: Babylon 5: Upheaval