public override void Execute(MainCharacter robot, Algorithm algorithm, Field field) { var turn = robot.CurrentAction as Turn; switch (turn.Direction) { case Directions.Right: if (robot.Direction == Side.Left) { robot.Direction = Side.Up; } else { robot.Direction += 90; } break; case Directions.Left: if (robot.Direction == Side.Up) { robot.Direction = Side.Left; } else { robot.Direction -= 90; } break; } }
/// <summary> /// ВЫбор следующего действия. /// </summary> /// <param name="action"></param> public AbstractAction ExecuteAction(MainCharacter robot, Algorithm algorithm, Field field) { var currentAction = robot.CurrentAction; robot.CurrentAction.Execute(robot, algorithm, field); return(GoToNextAction(currentAction.NextAction.Type, currentAction.NextAction.Number, algorithm)); }
/// <summary> /// Обновление данных при открытии нового алгоритма /// </summary> /// <param name="fileName"></param> private void RefreshData() { _robot = new MainCharacter(_algorithm); DataContext = _robot; _algorithmWork = new AlgorithmWork(); _field = new Field((int)_algorithm.FieldSize.Width + 1, (int)_algorithm.FieldSize.Height + 1); _field.InitializeField(_algorithm.BorderColor, _algorithm.DefaultColor); ActionsList.ItemsSource = _algorithm.ActionList; }
/// <summary> /// Проверить позицию робота на предмет выхода за пределы поля /// </summary> /// <param name="algorithm"></param> public bool CheckPosition(Algorithm algorithm, MainCharacter robot) { if (robot.Position.X < 0 || robot.Position.X >= algorithm.FieldSize.Width) { return(false); } if (robot.Position.Y < 0 || robot.Position.Y >= algorithm.FieldSize.Height) { return(false); } return(true); }
/// <summary> /// Получение прямоугольника для рисования робота /// </summary> /// <param name="rectangle"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public Rectangle GetRobotRectangle(Rectangle rectangle, int x, int y, MainCharacter robot) { var rotateTransform = new RotateTransform() { CenterX = 0.5, CenterY = 0.5, Angle = (int)robot.Direction }; var imageBrush = GetImageBrush(rotateTransform); rectangle.StrokeThickness = 5; rectangle.Stroke = Brushes.Red; rectangle.Fill = imageBrush; return(rectangle); }
private void ChangeRobotPosition(object sender, RoutedEventArgs e) { var robotCoordinatesWindow = new RobotCoordinatesWindow(_robot); if (robotCoordinatesWindow.ShowDialog() == true) { if (robotCoordinatesWindow.DialogResult == true) { _robot = robotCoordinatesWindow.DataContext as MainCharacter; } UpdateBackPattern(); DrawField(); } }
/// <summary> /// Выполнение текущего действия /// </summary> /// <param name="robot"></param> /// <param name="algorithm"></param> /// <param name="field"></param> public override void Execute(MainCharacter robot, Algorithm algorithm, Field field) { var fill = robot.CurrentAction as Fill; var algorithmWork = new AlgorithmWork(); for (var x = 0; x < algorithm.FieldSize.Width; x++) { for (var y = 0; y < algorithm.FieldSize.Height; y++) { if (robot.Position.X == x && robot.Position.Y == y) { field.CellsColorArray[x, y] = fill.Color; } } } }
/// <summary> /// Выполнение текущего действия /// </summary> /// <param name="robot"></param> /// <param name="algorithm"></param> /// <param name="field"></param> public override void Execute(MainCharacter robot, Algorithm algorithm, Field field) { var study = robot.CurrentAction as Study; var color = field.CellsColorArray[(int)robot.Position.X, (int)robot.Position.Y]; var isColor = false; foreach (var t in DictionaryActionForColor) { if (t.Key == color) { NextAction.Type = t.Value.Type; NextAction.Number = t.Value.Number; isColor = true; } } if (!isColor) { throw new Exception("элемент отсутствует в словаре"); } }
/// <summary> /// Выполнение текущего действия /// </summary> /// <param name="robot"></param> /// <param name="algorithm"></param> /// <param name="field"></param> public override void Execute(MainCharacter robot, Algorithm algorithm, Field field) { var move = robot.CurrentAction as Move; switch (robot.Direction) { case Side.Right: robot.WriteNewRobotPosition(move.CellAmount, 0); break; case Side.Left: robot.WriteNewRobotPosition(-move.CellAmount, 0); break; case Side.Up: robot.WriteNewRobotPosition(0, -move.CellAmount); break; case Side.Down: robot.WriteNewRobotPosition(0, move.CellAmount); break; } }
public RobotCoordinatesWindow(MainCharacter robot) { InitializeComponent(); _robot = robot; DataContext = _robot; }
/// <summary> /// Выполнение текущего действия /// </summary> /// <param name="robot"></param> /// <param name="algorithm"></param> /// <param name="field"></param> public abstract void Execute(MainCharacter robot, Algorithm algorithm, Field field);