Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4135c523c3
Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (37 sloc) 1.106 kb
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
<?php

class DungeonGenerator{

    private $myWalkStrategy;

    function __construct($walkStrategy=null){
        if ($walkStrategy==null){
            $walkStrategy=new DrunkManStrategy();
        }

        $this->myWalkStrategy=$walkStrategy;
    }

    public function createMap($lines,$columns){
        $myMap=null;

        for($i=0; $i<$lines; $i++){
            for($y=0; $y<$columns; $y++){
                $myMap[$i][$y]="#";
            }
        }
        return $myMap;
    }

    public function pickStartPoint($myMap) {
        $lines=sizeof($myMap);
        $columns=sizeof($myMap[0]);

        return array(rand(0,$lines-1),rand(0,$columns-1));
    }

    public function walk($myMap ,$stepNumber){
        $startPoint= $this->pickStartPoint($myMap);
        return $this->myWalkStrategy->walk($myMap ,$stepNumber, $startPoint[0], $startPoint[1]);
    }

    public function printMap($map){
        echo "\n====================\n";
        foreach($map as $line){
            foreach($line as $item){
                echo($item);
            }
            echo("\n");
        }
    }
}
Something went wrong with that request. Please try again.