public void CalculateStep(Keys key) { keyPressed = key; var currentPosition = map.GetPositionOfPlayer(); if (currentPosition == null) { throw new InvalidDataException("Нет игрока на карте"); } var x = currentPosition.Value.X; var y = currentPosition.Value.Y; switch (keyPressed) { case Keys.Up: if (VerticalStepIsPossible(currentPosition, -1)) { MakeStep(x, y, 0, -1); } break; case Keys.Right: if (HorizontalStepIsPossible(currentPosition, 1)) { MakeStep(x, y, 1, 0); } break; case Keys.Down: if (VerticalStepIsPossible(currentPosition, 1)) { MakeStep(x, y, 0, 1); } break; case Keys.Left: if (HorizontalStepIsPossible(currentPosition, -1)) { MakeStep(x, y, -1, 0); } break; } }