Exemple #1
0
        public Maze CreateMaze(int mazeNumber)
        {
            try
            {
                this._maze     = new Maze();
                this._fileName = "..\\..\\Doolhofs\\doolhof" + mazeNumber + ".txt";

                _reader = new StreamReader(_fileName);

                List <Tile> currentTileList  = new List <Tile>();
                List <Tile> previousTileList = null;


                this._input  = new FileStream(this._fileName, FileMode.Open, FileAccess.Read);
                this._reader = new StreamReader(this._input);
                string lineString = this._reader.ReadLine();

                while (lineString != null)
                {
                    currentTileList = new List <Tile>();

                    Tile currentTile  = null;
                    Tile previousTile = null;

                    for (int x = 0; x < lineString.Length; x++)
                    {
                        currentTile = null;

                        switch (lineString[x])
                        {
                        case 'x':
                            currentTile = new Destination();
                            break;

                        case '~':
                            currentTile = new Trap();
                            break;

                        case 'Z':
                            currentTile = new Floor();

                            Employee employeeASleep = new Employee(currentTile, false);
                            currentTile.ObjectOnTile = employeeASleep;
                            _maze.Employee           = employeeASleep;
                            break;

                        case 'o':
                            currentTile = new Floor();

                            Crate crateNormal = new Crate(currentTile);
                            _maze.AddCrate(crateNormal);
                            currentTile.ObjectOnTile = crateNormal;

                            break;

                        case '0':
                            currentTile = new Destination();

                            Crate crateOnDestination = new Crate(currentTile);
                            _maze.AddCrate(crateOnDestination);
                            currentTile.ObjectOnTile = crateOnDestination;
                            break;

                        case '$':
                            currentTile = new Floor();

                            Employee employeeAwake = new Employee(currentTile, true);
                            currentTile.ObjectOnTile = employeeAwake;
                            _maze.Employee           = employeeAwake;
                            break;

                        case '.':
                            currentTile = new Floor();
                            break;

                        case '@':
                            currentTile = new Floor();

                            Truck truck = new Truck(currentTile);
                            currentTile.ObjectOnTile = truck;
                            _maze.Truck = truck;
                            break;

                        case ' ':
                            currentTile = new EmptySpot();
                            break;

                        case '#':
                            currentTile = new Wall();
                            break;

                        default:
                            break;
                        }
                        if (previousTile != null)
                        {
                            currentTile.LeftTile   = previousTile;
                            previousTile.RightTile = currentTile;
                        }
                        previousTile = currentTile;
                        currentTileList.Add(currentTile);
                    }

                    if (previousTileList != null)
                    {
                        for (int i = 0; i < currentTileList.Count; i++)
                        {
                            currentTileList[i].UpTile    = previousTileList[i];
                            previousTileList[i].DownTile = currentTileList[i];
                        }
                    }
                    else
                    {
                        this._maze.OriginalTile = currentTileList[0];
                    }

                    previousTileList = currentTileList;

                    lineString = this._reader.ReadLine();
                }

                this._reader.Close();
                this._input.Close();

                return(_maze);
            }
            catch
            {
                throw;
            }
        }
Exemple #2
0
 public override void PlaceTruck(Truck truck)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
        public Maze ParseMaze(char mazeNumber)
        {
            try
            {
                if (mazeNumber == 's')
                {
                    Environment.Exit(0);
                }
                string[] lines = File.ReadAllLines("../../../Mazes/doolhof" + mazeNumber + ".txt");
                Maze = new Maze(lines.Count());

                int row = -1;

                foreach (string line in lines)
                {
                    row++;
                    foreach (char c in line)
                    {
                        FieldDoublyDoublyLink fieldDoublyDoublyLink = new FieldDoublyDoublyLink();
                        switch (c)
                        {
                        case '.':
                            fieldDoublyDoublyLink.Floor = new Normal();
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            break;

                        case '#':
                            fieldDoublyDoublyLink.Floor = new Wall();
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            break;

                        case 'o':
                            Chest chest = new Chest();
                            fieldDoublyDoublyLink.Floor       = new Normal();
                            fieldDoublyDoublyLink.Floor.Chest = chest;
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            chest.Current = fieldDoublyDoublyLink;

                            break;

                        case 'x':
                            Maze.Destinations++;
                            fieldDoublyDoublyLink.Floor = new Destination();
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            break;

                        case '~':
                            fieldDoublyDoublyLink.Floor = new Pitfall();
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            break;

                        case '@':
                            Truck truck = new Truck();

                            fieldDoublyDoublyLink.Floor       = new Normal();
                            fieldDoublyDoublyLink.Floor.Truck = truck;
                            Maze.AddField(fieldDoublyDoublyLink, row);

                            Maze.AddTruck(truck, fieldDoublyDoublyLink);
                            break;

                        case '$':
                            Employee employee = new Employee();

                            fieldDoublyDoublyLink.Floor          = new Normal();
                            fieldDoublyDoublyLink.Floor.Employee = employee;
                            Maze.AddField(fieldDoublyDoublyLink, row);

                            Maze.AddEmployee(employee, fieldDoublyDoublyLink);
                            break;

                        default:
                            fieldDoublyDoublyLink.Floor = new Empty();
                            Maze.AddField(fieldDoublyDoublyLink, row);
                            break;
                        }
                    }
                }
            }
            catch
            {
                outputView.FileNotFound();
                outputView.ChooseMaze();
            }
            return(Maze);
        }
Exemple #4
0
 public override void PlaceTruck(Truck truck)
 {
     Truck = truck;
 }