我正在构建一个与空间相关的游戏,但不知道如何遍历我的百分比“生成”机会数组,最终得到一个具有一定大小的生成星。
它必须如何生成的示例:
$star_chance = rand(1,100);
$star_size_chance = rand(1,100);
//loop through the list of stars here
//selected star - orange
//loop through the size chances of star orange
//selected star size = medium
- 红色、橙色和黄色星星各有一个生成机会,一次只能生成一个
- 对于每个生成的恒星,它都有可能变成什么大小
该方程需要适应可能更多的恒星或尺寸
$star_array = array( "red" => array( "spawn_chance" => "25", "size_immense_chance" => "50", "size_giant_chance" => "25", "size_large_chance" => "15", "size_medium_chance" => "5", "size_small_chance" => "4", "size_dwarf_chance" => "1" ), "orange" => array( "spawn_chance" => "50", "size_immense_chance" => "4", "size_giant_chance" => "15", "size_large_chance" => "50", "size_medium_chance" => "25", "size_small_chance" => "6", "size_dwarf_chance" => "0" ), "yellow" => array( "spawn_chance" => "25", "size_immense_chance" => "0", "size_giant_chance" => "6", "size_large_chance" => "25", "size_medium_chance" => "50", "size_small_chance" => "15", "size_dwarf_chance" => "4", ) );