예제 #1
0
파일: Maze.cs 프로젝트: Zagamant/Maze
        public void TryToStep(Direction direction)
        {
            BaseCell cellToMove = null;

            var hero = Player.GetPlayer;

            switch (direction)
            {
            case Direction.Up:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y - 1];
                break;

            case Direction.Right:
                cellToMove = this[hero.Coordinates.X + 1, hero.Coordinates.Y];
                break;

            case Direction.Down:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y + 1];
                break;

            case Direction.Left:
                cellToMove = this[hero.Coordinates.X - 1, hero.Coordinates.Y];
                break;
            }

            if (cellToMove?.TryToStep() ?? false)
            {
                hero.Coordinates = cellToMove.Coordinates;
            }
        }
예제 #2
0
        public void TryToStep(Direction direction)
        {
            RememberLast = false;
            BaseCell cellToMove = null;

            var hero = Player.GetPlayer;

            switch (direction)
            {
            case Direction.Up:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y - 1];
                break;

            case Direction.Right:
                cellToMove = this[hero.Coordinates.X + 1, hero.Coordinates.Y];
                break;

            case Direction.Down:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y + 1];
                break;

            case Direction.Left:
                cellToMove = this[hero.Coordinates.X - 1, hero.Coordinates.Y];
                break;
            }

            if (cellToMove?.TryToStep() ?? false)
            {
                hero.Coordinates = cellToMove.Coordinates;
            }

            if (Cells[Cells.FindIndex(n => n.Coordinates.X == hero.Coordinates.X & n.Coordinates.Y == hero.Coordinates.Y)].Skin == ExitCell.Skin())
            {
                LastExitX        = hero.Coordinates.X;
                LastExitY        = hero.Coordinates.Y;
                hero.Coordinates = Cells[0].Coordinates;
                GenerateNew      = true;
            }

            if (Cells[Cells.FindIndex(n => n.Coordinates.X == hero.Coordinates.X & n.Coordinates.Y == hero.Coordinates.Y)].Skin == LastMazeCell.Skin())
            {
                hero.Coordinates = Cells[0].Coordinates;
                RememberLast     = true;
            }
        }
예제 #3
0
파일: Maze.cs 프로젝트: Taburet47/HW-3
        } = new List <BaseCell>();                                        //delete set


        public void TryToStep(Direction direction)
        {
            BaseCell cellToMove = null;

            var hero = Player.GetPlayer;

            switch (direction)
            {
            case Direction.Up:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y - 1];
                break;

            case Direction.Right:
                cellToMove = this[hero.Coordinates.X + 1, hero.Coordinates.Y];
                break;

            case Direction.Down:
                cellToMove = this[hero.Coordinates.X, hero.Coordinates.Y + 1];
                break;

            case Direction.Left:
                cellToMove = this[hero.Coordinates.X - 1, hero.Coordinates.Y];
                break;
            }
            for (int i = hero.Coordinates.X - 1; i <= hero.Coordinates.X + 1; i++)
            {
                for (int j = hero.Coordinates.Y - 1; j <= hero.Coordinates.Y + 1; j++)
                {
                    this[i, j].Checked = true;
                }
            }
            if (cellToMove?.TryToStep() ?? false)
            {
                hero.Coordinates = cellToMove.Coordinates;
            }
        }