コード例 #1
0
 public bool checkMove(Location nextLoc, Direction direction)
 {
     if (nextLoc.drawLoc().Equals('.') || nextLoc.drawLoc().Equals('x') || nextLoc.drawLoc().Equals('~') || nextLoc.drawLoc().Equals(' ') || nextLoc.drawLoc().Equals('z'))
     {
         if (nextLoc.drawLoc().Equals('z'))
         {
             BaseFloor workerFloor = (BaseFloor)nextLoc;
             workerFloor._movable.symbol = '$';
             return(false);
         }
         return(true);
     }
     if ((nextLoc.drawLoc().Equals('o') || nextLoc.drawLoc().Equals('0')) && canMoveObject)
     {
         BaseFloor crateFloor = (BaseFloor)nextLoc;
         return(crateFloor._movable.Move(direction));
     }
     if (symbol.Equals('$') && nextLoc.drawLoc().Equals('@'))
     {
         BaseFloor characterFloor = (BaseFloor)nextLoc;
         if (characterFloor._movable.Move(direction))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        public void LoadMaze(int mazeNumber)
        {
            string[] lines;
            lines = System.IO.File.ReadAllLines(@"doolhof" + mazeNumber + ".txt");
            int xIndex = 0;
            int yIndex = 0;

            _maze        = new Maze();
            _maze.width  = lines[0].Length;
            _maze.height = lines.Length;
            foreach (string line in lines)
            {
                foreach (char c in line)
                {
                    Location  newLoc       = null;
                    BaseFloor newBase      = null;
                    Character newCharacter = null;
                    Worker    newWorker    = null;
                    Crate     newCrate     = null;
                    switch (c)
                    {
                    case '@':
                        newCharacter            = new Character(c);
                        newLoc                  = new BaseFloor(xIndex, yIndex, '.');
                        newBase                 = (BaseFloor)newLoc;
                        newBase._movable        = newCharacter;
                        newCharacter.currentLoc = newLoc;
                        _maze.character         = newCharacter;
                        break;

                    case 'o':
                        newCrate            = new Crate('o');
                        newLoc              = new BaseFloor(xIndex, yIndex, '.');
                        newBase             = (BaseFloor)newLoc;
                        newBase._movable    = newCrate;
                        newCrate.currentLoc = newLoc;
                        _maze.crateList.Add(newCrate);
                        break;

                    case '0':
                        newCrate            = new Crate('o');
                        newLoc              = new Destination(xIndex, yIndex, 'x');
                        newBase             = (BaseFloor)newLoc;
                        newBase._movable    = newCrate;
                        newCrate.currentLoc = newLoc;
                        _maze.crateList.Add(newCrate);
                        break;

                    case '$':
                        newWorker            = new Worker('$');
                        newLoc               = new BaseFloor(xIndex, yIndex, '.');
                        newBase              = (BaseFloor)newLoc;
                        newBase._movable     = newWorker;
                        newWorker.currentLoc = newLoc;
                        _maze.worker         = newWorker;
                        break;

                    case 'z':
                        newWorker            = new Worker('z');
                        newLoc               = new BaseFloor(xIndex, yIndex, '.');
                        newBase              = (BaseFloor)newLoc;
                        newBase._movable     = newWorker;
                        newWorker.currentLoc = newLoc;
                        _maze.worker         = newWorker;
                        break;

                    case '.':
                        newLoc = new BaseFloor(xIndex, yIndex, '.');
                        break;

                    case 'x':
                        newLoc = new Destination(xIndex, yIndex, 'x');
                        break;

                    case '~':
                        newLoc = new Trap(xIndex, yIndex, '~');
                        break;

                    case ' ':
                        newLoc = new Location(xIndex, yIndex, ' ');
                        break;

                    case '#':
                        newLoc = new Location(xIndex, yIndex, '█');
                        break;
                    }
                    _maze.addLoc(newLoc);
                    xIndex++;
                }
                xIndex = 0;
                yIndex++;
            }
        }