PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/UniverseSeederClass.php

https://bitbucket.org/PacificACM/spacezoo
PHP | 67 lines | 66 code | 1 blank | 0 comment | 6 complexity | 0bef11505566e4ebe04fc1d49e707b84 MD5 | raw file
  1. <?php
  2. class UniverseSeederClass
  3. {
  4. function __construct()
  5. {
  6. }
  7. function addPlanetsToArea($xLocation1, $yLocation1, $xLocation2, $yLocation2, $planets)
  8. {
  9. $db = new DatabaseClass();
  10. for($i = 0; $i < $planets; $i++)
  11. {
  12. $xRand = mt_rand($xLocation1,$xLocation2);
  13. $yRand = mt_rand($yLocation1,$yLocation2);
  14. $xRandDecimal = mt_rand(0,1000);
  15. $yRandDecimal = mt_rand(0,1000);
  16. $xRand *= 1000;
  17. $yRand *= 1000;
  18. $xRand += $xRandDecimal;
  19. $yRand += $yRandDecimal;
  20. $tempLow = mt_rand(-265,200);
  21. $tempHighOffset = mt_rand(50,1000);
  22. $tempHigh = $tempLow + $tempHighOffset;
  23. $result = mysql_query("SELECT id FROM planets WHERE (ABS(xLocation - $xRand) < 50) AND (ABS(yLocation - $yRand) < 50)");
  24. $numRows = mysql_numrows($result);
  25. $query = "INSERT INTO planets (name, tempLow, tempHigh, xLocation, yLocation) VALUES ('Unnamed', $tempLow, $tempHigh, $xRand, $yRand)";
  26. if($numRows == 0)
  27. {
  28. mysql_query($query);
  29. }
  30. }
  31. }
  32. function createAnimalTypes($numTypes)
  33. {
  34. $db = new DatabaseClass();
  35. for($i = 0; $i < $numTypes; $i++)
  36. {
  37. $rarity = mt_rand(2,100);
  38. $tempLow = mt_rand(-265,200);
  39. $tempHigh = mt_rand(50, 1000);
  40. $query = "INSERT INTO animalTypes (name, rarity, tempLow, tempHigh) VALUES ('Unnamed', $rarity, $tempLow, $tempHigh)";
  41. echo $query;
  42. mysql_query($query) or die(mysql_error());
  43. }
  44. }
  45. function createPlanetAnimalTypes($numConnections)
  46. {
  47. $db = new DatabaseClass();
  48. for($i = 0; $i < $numConnections; $i++)
  49. {
  50. $result = mysql_query("SELECT id FROM planets") or die(mysql_error());
  51. $numPlanets = mysql_numrows($result);
  52. $result = mysql_query("SELECT id FROM animalTypes") or die(mysql_error());
  53. $numAnimalTypes = mysql_numrows($result);
  54. $numPlanet = mt_rand(0,$numPlanets);
  55. $numAnimalType = mt_rand(0,$numAnimalTypes);
  56. $currPlanet = new PlanetClass($numPlanet);
  57. $currAnimalType = new AnimalTypeClass($numAnimalType);
  58. if($currPlanet->canPlanetSupport($currAnimalType))
  59. {
  60. $query = "INSERT INTO planetAnimalTypes (animalTypeID, planetID) VALUES ($numAnimalType, $numPlanet)";
  61. mysql_query($query) or die(mysql_error());
  62. }
  63. }
  64. }
  65. }
  66. ?>