spelletje-lights-out

Gesponsorde koppelingen

PHP script bestanden

  1. spelletje-lights-out

« Lees de omschrijving en reacties

//------------ lights.php ------------\\

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start();
class lights_out{
    
    var
$int_level = 1;
    var
$field = array();
    var
$moves = '0';
//in deze functie word het veld geladen uit het bestand lights.games.php    
    function lights_out(){
        include('lights.games.php');
        list($this->int_level) = func_get_args();
        if(isset($game[$this->int_level])){
            $this->field = $game[$this->int_level];
            $this->show_field();
        }

        else{
            $this->int_level = 1;
            $this->field = $game[1];
            $this->show_field();
        }
    }
    
    function
reset_game(){
        $this->moves = 0;
        $this->lights_out($this->int_level);
    }

//laad een nieuw spel    
    function load_new_game(){
        list($mode,$nr) = func_get_args();
        switch($mode){
            case
'NEW':
                include('lights.games.php');
                if(isset($game[$nr])){
                    $this->int_level = $nr;
                    $this->field = $game[$this->int_level];
                    $this->show_field();
                }

                else{
                    echo 'deze game bestaat niet';
                }

                break;
            case
'NEXT':
            default:

                include('lights.games.php');
                if(isset($game[$this->int_level+1])){
                    $this->int_level++;
                    $this->field = $game[$this->int_level];
                    $this->show_field();
                }

                else{
                //text die weergegeven word als er geen volgende game is en het spel dus uitgespeeld is
                    echo 'je hebt het spel uitgespeeld<br><br>';
                    echo '<a href="?id=NEW">start opnieuw</a>';
                }

                break;
        }
    }

//laat het veld zien    
    function show_field(){
        echo 'level: '.$this->int_level;
        echo '<table>';
        foreach($this->field as $row_nr => $row){
            echo '<tr>';
            foreach($row as $col_nr => $value){
                if($value == 1){
                    $color = '#888888'; //kleur vakje met het "licht aan"
                    $color_mouseover = '#dddddd'; //kleur vakje met het "licht aan" als de muis erover heen gaat
                }
                else{
                    $color = '#ffffff'; //kleur vakje met het "licht uit"
                    $color_mouseover = '#dddddd'; //kleur vakje met het "licht uit" als de muis erover heen gaat
                }
                echo '<td style="background-color:'.$color.';border:1px solid #000000;" onclick="location.href=\'?id='.$row_nr.'_'.$col_nr.'&sid='.serialize($this).'\'" onMouseOver="this.style.backgroundColor=\''.$color_mouseover.'\'; this.style.cursor=\'hand\'" onMouseOut="this.style.backgroundColor=\''.$color.'\'"><a href="?id='.$row_nr.'_'.$col_nr.'" style="text-decoration:none;">&nbsp; &nbsp; &nbsp;</a>';
                
            }
        }

        echo '</table>moves: '.$this->moves.'<br>';
        echo '<a href="?id=RESET">reset</a>';
    }

//klap de waarde van een vakje om;    
    function c_v($id){
        if($id == 1){
            $return = 0;
        }

        elseif($id == 0){
            $return = 1;
        }

        else{
            $return = 1;
        }

        return $return;
    }

//verander waardes van de vakjes rondom het aangeklikte vakje    
    function change($id){
        $this->moves++;
        list($row,$col) = explode('_',$id);
        if(isset($this->field[$row][$col])){
            $this->field[$row][$col] = $this->c_v($this->field[$row][$col]);
        }

        if(isset($this->field[$row][$col-1])){
            $this->field[$row][$col-1] = $this->c_v($this->field[$row][$col-1]);
        }

        if(isset($this->field[$row][$col+1])){
            $this->field[$row][$col+1] = $this->c_v($this->field[$row][$col+1]);
        }

        if(isset($this->field[$row-1][$col])){
            $this->field[$row-1][$col] = $this->c_v($this->field[$row-1][$col]);
        }

        if(isset($this->field[$row+1][$col])){
            $this->field[$row+1][$col] = $this->c_v($this->field[$row+1][$col]);
        }

        //in deze loop word gekeken of er ergens nog een "lampje brand"
        foreach($this->field as $field){
            if(in_array('1',$field)){
                $light = 1;
            }
        }

        if($light == 1){
            $this->show_field();
        }

        else{
            //text die weergegeven word als een level gehaald is
            echo 'level gehaald in <b>'.$this->moves.'</b> moves<br><br>';
            echo '<a href="?id=NEXT">volgende level</a>';
            $this->moves = 0;
        }
    }    
}
function
game(){
    $nr = 1;
    list($nr) = func_get_args();
    if(!isset($_GET['id'])){
        $game = new lights_out($nr);
        $_SESSION['game'] = serialize($game);
    }

    elseif($_GET['id'] == 'RESET'){
        $game = unserialize($_SESSION['game']);
        $game->reset_game();
        $_SESSION['game'] = serialize($game);
    }

    elseif($_GET['id'] == 'NEXT'){
        $game = unserialize($_SESSION['game']);
        $game->load_new_game('NEXT');
        $_SESSION['game'] = serialize($game);
    }

    elseif($_GET['id'] == 'NEW'){
        $game = unserialize($_SESSION['game']);
        $game->load_new_game('NEW',1);
        $_SESSION['game'] = serialize($game);
    }

    else{
        $game = unserialize($_SESSION['game']);
        $game->change($_GET['id']);
        $_SESSION['game'] = serialize($game);
    }
}

?>

//------------ lights.games.php ------------\\
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
$game
[1] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    2 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    3 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    4 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    5 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     )
);


$game[2] = array(
    1 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    2 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    3 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    4 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    5 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     )
);


$game[3] = array(
    1 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     ),
    2 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    3 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    4 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    5 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     )
);


$game[4] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    2 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    3 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    4 => array(        1 => 1,        2 => 0,        3 => 0,        4 => 0,        5 => 1     ),
    5 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     )
);


$game[5] = array(
    1 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    2 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 0,        5 => 1     ),
    3 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 0,        5 => 1     ),
    4 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 1,        5 => 1     ),
    5 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     )
);

$game[6] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    2 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    3 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    4 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    5 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     )
);

$game[7] = array(
    1 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    2 => array(        1 => 1,        2 => 0,        3 => 0,        4 => 0,        5 => 1     ),
    3 => array(        1 => 1,        2 => 0,        3 => 0,        4 => 0,        5 => 1     ),
    4 => array(        1 => 1,        2 => 0,        3 => 0,        4 => 0,        5 => 1     ),
    5 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 1,        5 => 0     )
);

$game[8] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    2 => array(        1 => 0,        2 => 0,        3 => 1,        4 => 0,        5 => 0     ),
    3 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     ),
    4 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    5 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     )
);

$game[9] = array(
    1 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     ),
    2 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 1,        5 => 1     ),
    3 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    4 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    5 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 0,        5 => 0     )
);

$game[10] = array(
    1 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    2 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    3 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     ),
    4 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     ),
    5 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0     )
);

$game[11] = array(
    1 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    2 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    3 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    4 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 1     ),
    5 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0     )
);

$game[12] = array(
    1 => array(        1 => 1,        2 => 1,        3 => 1,        4 => 1,        5 => 1     ),
    2 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0     ),
    3 => array(        1 => 1,        2 => 1,        3 => 0,        4 => 1,        5 => 1     ),
    4 => array(        1 => 0,        2 => 1,        3 => 1,        4 => 1,        5 => 0    ),
    5 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0    )
);

$game[13] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 1,        5 => 0    ),
    2 => array(        1 => 0,        2 => 0,        3 => 1,        4 => 0,        5 => 1    ),
    3 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 1,        5 => 0    ),
    4 => array(        1 => 1,        2 => 0,        3 => 1,        4 => 0,        5 => 0    ),
    5 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    )
);

$game[14] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0    ),
    2 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0    ),
    3 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    ),
    4 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    ),
    5 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    )
);

$game[15] = array(
    1 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0    ),
    2 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    ),
    3 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0    ),
    4 => array(        1 => 0,        2 => 1,        3 => 0,        4 => 0,        5 => 0    ),
    5 => array(        1 => 0,        2 => 0,        3 => 0,        4 => 0,        5 => 0    )
);

/*lege game
$game[] = array(
    1 => array(        1 => ,        2 => ,        3 => ,        4 => ,        5 =>     ),
    2 => array(        1 => ,        2 => ,        3 => ,        4 => ,        5 =>     ),
    3 => array(        1 => ,        2 => ,        3 => ,        4 => ,        5 =>     ),
    4 => array(        1 => ,        2 => ,        3 => ,        4 => ,        5 =>     ),
    5 => array(        1 => ,        2 => ,        3 => ,        4 => ,        5 =>    )
);
*/
    
?>

 
 

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.