Beispiel #1
0
        /// <summary>
        /// Действие пользователя на очередной итерации
        /// </summary>
        /// <param name="position">Тип действия</param>
        public void Action(ActionType action)
        {
            switch (action)
            {
            case ActionType.Down:
                _timer.Interval = DownSpeed;
                break;

            case ActionType.Left:
                if (Field.IsCanSetUpFigure(_figure, _x - 1, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _x--;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.Right:
                if (Field.IsCanSetUpFigure(_figure, _x + 1, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _x++;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.TurnRight:
                Field.SetUp(_figure, _y, _x, CellType.Empty);
                _figure.Turn(true);
                if (Field.IsCanSetUpFigure(_figure, _x, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    _figure.Turn(false);
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.TurnLeft:
                Field.SetUp(_figure, _y, _x, CellType.Empty);
                _figure.Turn(false);
                if (Field.IsCanSetUpFigure(_figure, _x, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    _figure.Turn(true);
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;
            }

            FieldChanged?.Invoke();
        }
Beispiel #2
0
        private FigureBase Turn(FigureBase figure)
        {
            var number = Random.Next(4);

            for (var i = 0; i < number; i++)
            {
                figure.Turn();
            }

            return(figure);
        }