map_generator.php

Gesponsorde koppelingen

PHP script bestanden

  1. map_generator.php
  2. worldmap.sql
  3. map_viewer.php
  4. dbconnect.php
  5. config.php

« Lees de omschrijving en reacties

<!-- php wereldmaker -->

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php
include_once('dbconnect.php');
include_once('config.php');
/*
* Gemaakt door Michael R
*
*/

?>

<html>
<form name = "generate" method = "post" action = "
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo($_SERVER['PHP_SELF']); ?>
">
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
while($y <= $max_y) {
    
        while($x <= $max_x) {
                $field_texture[$x][$y] = $texture[rand(0,2)];
                $last_water[$x][$y] = false;
                $last_grass[$x][$y] = false;
                mysqli_query($worldmap,"INSERT INTO map (x,y,texture) VALUES (".$x.",".$y.",'".$field_texture[$x][$y]."')") or die(mysqli_error($worldmap));
            $x++;
        }

        $x = 0;
    
    $y++;
}
    
$y = 0;

// Controle loop
while($y <= $max_y) {
        while($x <= $max_x) {
                if($min_x < $x && $max_x > $x && $max_y > $y && $min_y < $y) {
                    
                    if($field_texture[$x][$y] == "water") {
                            if(!$last_water[$x][$y]) {
                                $field_texture[$x + 1][$y] = "water";
                                mysqli_query($worldmap,"UPDATE map SET texture = 'water' WHERE x = ".($x + 1)." AND y = ".$y."");
                                $last_water[$x + 1][$y] = true;
                            }
                    }
elseif($field_texture[$x][$y] == "grass") {
                        if(!$last_grass[$x][$y]) {
                            if($field_texture[$x][$y - 1] != "water") {
                                $field_texture[$x][$y - 1] = "grass";
                                $last_grass[$x][$y - 1] = true;
                            }
                        }
                    }
                }

            $x++;
        }

        $x = 0;
        $y++;
}

$y = 0;
// De wereld is gegenereerd
header('Location: map_viewer.php');
}
else {
    echo("<input type = 'submit' value = 'Genereer wereld!' />");
}

?>

</form>
</html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.