Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Метод генерации карты мира
- */
- public function _generate_world() {
- $arr_coords = array();
- $blocks_x = 49;
- $blocks_y = 49;
- $all_blocks = $blocks_x * $blocks_y;
- $def_x = -24;
- $def_y = 24;
- $s = 0;
- $coord_x = NULL;
- $coord_y = NULL;
- $i = 0;
- while($i < $all_blocks) {
- if($s < 49) {
- $coord_x = $def_x + $s;
- $coord_y = $def_y;
- $arr_coords[$coord_x.'&'.$coord_y] = 0;
- }
- else {
- $coord_x = $def_x;
- $coord_y = $def_y = $def_y - 1;
- $arr_coords[$coord_x.'&'.$coord_y] = 0;
- $s = 0;
- }
- $i++;
- $s++;
- }
- $rand_keys = array_rand($arr_coords, 250);
- foreach($rand_keys as $key) {
- $x = rand(0, 100);
- $zone = null;
- if($x > 0 && $x < 60) { $zone = 1; }
- elseif($x > 60 && $x < 85) { $zone = 2;}
- elseif($x > 85 && $x < 95) { $zone = 3;}
- else { $zone = 4; }
- $arr_coords[$key] = $zone;
- }
- $i = 0;
- while($i < 100) {
- foreach($arr_coords as $key => $value) {
- if($value != 0) {
- $xy_coords = explode('&', $key);
- $x_coord = $xy_coords[0];
- $y_coord = $xy_coords[1];
- $left_coords = ($x_coord - 1) . '&' . $y_coord;
- $top_coords = $x_coord . '&' . ($y_coord + 1);
- $right_coords = ($x_coord + 1) . '&' . $y_coord;
- $bottom_coords = $x_coord . '&' . ($y_coord - 1);
- if(isset($arr_coords[$left_coords]) && $arr_coords[$left_coords] == 0) { $arr_coords[$left_coords] = $value; }
- if(isset($arr_coords[$top_coords]) && $arr_coords[$top_coords] == 0) { $arr_coords[$top_coords] = $value; }
- if(isset($arr_coords[$right_coords]) && $arr_coords[$right_coords] == 0) { $arr_coords[$right_coords] = $value; }
- if(isset($arr_coords[$bottom_coords]) && $arr_coords[$bottom_coords] == 0) { $arr_coords[$bottom_coords] = $value; }
- }
- }
- $i++;
- }
- foreach($arr_coords as $key => $value) {
- echo '<div style="width: 25px; height: 25px; float: left; border: 1px solid black;';
- if($value == 1) { echo 'background: #00FA9A;">';}
- elseif($value == 2) { echo 'background: green;">';}
- elseif($value == 3) { echo 'background: blue;">';}
- elseif($value == 4) { echo 'background: gray;">';}
- else { echo 'background: #ffffff;">';}
- echo $value;
- echo '</div>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement