Beispiel #1
0
<?php

Labyrinth::main();
class Labyrinth
{
    private static $lab = array(array('.', '.', '.', '*', '.', '.', '.'), array('*', '*', '.', '*', '.', '*', '.'), array('.', '.', '.', '.', '.', '.', '.'), array('.', '*', '*', '*', '*', '*', '.'), array('.', '.', '.', '.', '.', '.', 'E'));
    private static $numRows = 4;
    private static $numcols = 6;
    public static function main()
    {
        self::head();
        self::printLabyrinth();
        self::findExit(0, 0, 'S');
    }
    private static function head()
    {
        echo "<!doctype html>\n                <head>\n                    <style>\n                        body { \n                            font-family: Lucida Console,Lucida Sans Typewriter,monaco,Bitstream Vera Sans Mono,monospace; \n                            font-size: 36px;\n                            }\n                    </style>\n                </head>\n            <body>";
    }
    private static function findExit($row, $col, $dir)
    {
        if ($row < 0 || $col < 0 || $row > self::$numRows || $col > self::$numcols) {
            return;
        }
        if (self::$lab[$row][$col] == 'E') {
            // exit
            self::printLabyrinth();
            return;
        }
        if (self::$lab[$row][$col] != '.') {
            // cell already visited
            return;