Advertisement
Guest User

randomEntity

a guest
Mar 31st, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1. <?php
  2.  
  3. //require 'Personnage.class.php';
  4.  
  5. function customRandom($element)
  6. {
  7.     return rand(0,sizeof($element)-1);
  8. }
  9.  
  10. function getRandomSexe(){
  11.     $sexe_array = ["man", "woman"];
  12.     return $sexe_array[rand(0,1)];
  13. }
  14.  
  15. function getRandomName($sexe){
  16.     if ($sexe == "man") return getManName();
  17.     elseif ($sexe == "woman") return getWomanName();
  18. }
  19.  
  20. function randomEntity(){
  21.     $dir    = 'assets/';
  22.     $imgDir = scandir($dir);
  23.  
  24.     $sexe = getRandomSexe();
  25.     $name = getRandomName($sexe);
  26.  
  27.     $tab_glasses = ["glasses", false];
  28.  
  29.     if ($sexe == "man"){
  30.         //size : 7
  31.         $tab_hairMan = ["hair_10", "hair_1", "hair_2", "hair_6", "hair_7", "hair_9"];
  32.         //size : 2
  33.         $tab_clotheMan = ["clothe", false];
  34.         //size : 3
  35.         $tab_suitMan = ["suit_1", "suit_3"];
  36.         //size : 2
  37.         $tab_beard = ["beard", false];
  38.         //size : 2
  39.         $tab_mustache = ["mustache", false];
  40.  
  41.         $randomClotheMan = $tab_clotheMan[rand(0,1)];
  42.         $randomSuitMan = $tab_suitMan[rand(0,1)];
  43.         if (!empty($randomClotheMan)) $randomSuitMan = false;
  44.  
  45.         //size : 7
  46.         $tab_imgElements = array($tab_glasses[rand(0,1)], "body", $randomClotheMan, $tab_hairMan[rand(0,6)], $randomSuitMan, $tab_mustache[rand(0,1)], $tab_beard[rand(0,1)]);
  47.     }
  48.     elseif ($sexe == "woman"){
  49.         //size : 8
  50.         $tab_clotheWoman = ["clothe_basic", "clothe_claudine", "clothe_pull", "clothe_roule", "clothe_shirt", "clothe_sweat", "clothe_V", false];
  51.         //size : 3
  52.         $tab_hairWoman = ["hair_3", "hair_4", "hair_8"];
  53.         //size : 2
  54.         $tab_suitWoman = ["suit_2", "suit_4"];
  55.         //size : 2
  56.         $tab_pearl = ["pearl", false];
  57.  
  58.         $randomClotheWoman = $tab_clotheWoman[rand(0,7)];
  59.         $randomSuitWoman = $tab_suitWoman[rand(0,1)];
  60.         if (!empty($randomClotheWoman)) $randomSuitWoman = false;
  61.  
  62.         //size : 8
  63.         $tab_imgElements = array($tab_glasses[rand(0,1)], "body", $randomClotheWoman, $tab_hairWoman[rand(0,2)], $randomSuitWoman, false, false, $tab_pearl[rand(0,1)]);
  64.     }
  65.  
  66.     $tabElement = array();
  67.  
  68.     $count = 0;
  69.      
  70.     for($i=0;$i<sizeof($tab_imgElements);$i++) {
  71.  
  72.         $count = 0;
  73.      
  74.         foreach($imgDir as $img){
  75.             $imgElement = strstr($img, $tab_imgElements[$i]);
  76.      
  77.             if($imgElement) {
  78.                 $tabElement[$tab_imgElements[$i]][$count] = $imgElement;
  79.                 $count++;
  80.             }
  81.      
  82.         }
  83.      
  84.     }
  85.  
  86.     $beard = $tabElement[$tab_imgElements[6]][customRandom($tabElement[$tab_imgElements[6]])];
  87.  
  88.     $body = $tabElement["body"][customRandom($tabElement["body"])];
  89.  
  90.     $clothe = $tabElement[$tab_imgElements[2]][customRandom($tabElement[$tab_imgElements[2]])];
  91.  
  92.     $glasses = $tabElement[$tab_imgElements[0]][customRandom($tabElement[$tab_imgElements[0]])];
  93.  
  94.     $hair = $tabElement[$tab_imgElements[3]][customRandom($tabElement[$tab_imgElements[3]])];
  95.  
  96.     $mustache = $tabElement[$tab_imgElements[5]][customRandom($tab_imgElements[5])];
  97.  
  98.     $pearl = $tabElement[$tab_imgElements[7]][customRandom($tabElement[$tab_imgElements[7]])];
  99.  
  100.     $suit = $tabElement[$tab_imgElements[4]][customRandom($tabElement[$tab_imgElements[4]])];
  101.  
  102.     //Affichage
  103.  
  104.     echo ("Sexe : ".$sexe);
  105.  
  106.     echo "<br/><br/>";
  107.  
  108.     echo ("Nom : ".$name);
  109.  
  110.     echo "<br/><br/>";
  111.  
  112.     echo("Barbe : ".$beard."\n");
  113.  
  114.     echo "<br/><br/>";
  115.        
  116.     echo("Body : ".$body."\n");
  117.  
  118.     echo "<br/><br/>";
  119.  
  120.     echo("Clothe : ".$clothe."\n");
  121.  
  122.     echo "<br/><br/>";
  123.  
  124.     echo("Glasses : ".$glasses."\n");
  125.  
  126.     echo "<br/><br/>";
  127.  
  128.     echo("Hair : ".$hair."\n");
  129.  
  130.     echo "<br/><br/>";
  131.  
  132.     echo("Mustache : ".$mustache."\n");
  133.  
  134.     echo "<br/><br/>";
  135.  
  136.     echo("Pearl : ".$pearl."\n");
  137.  
  138.     echo "<br/><br/>";
  139.  
  140.     echo("Suit : ".$suit."\n");
  141.  
  142.     echo "<br/><br/>";
  143. }
  144.  
  145. //$randomPersonnage = new Personnage($name, $sexe, $beard, $body, $clothe, $glasses, $hair, $mustache, $pearl, $suit, true, false);
  146.  
  147. randomEntity();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement