コード例 #1
0
        public IActionResult Index(Models.RobotWars model)
        {
            if (ModelState.IsValid)
            {
                Position.Position position = new Position.Position();
                model.PenaltyCount = 0;

                try
                {
                    //set initial position
                    position.X         = (int)Char.GetNumericValue(model.InitialPosition[0]);
                    position.Y         = (int)Char.GetNumericValue(model.InitialPosition[2]);
                    position.Direction = (Directions)Enum.Parse(typeof(Directions), model.InitialPosition[4].ToString().ToUpper());

                    //set variables for the max x and y values for processing the change of location
                    List <int> maxXYPoints = new List <int>()
                    {
                        4, 4
                    };

                    //process the new position
                    position.StartMoving(maxXYPoints, model.MovementInstructions.ToUpper());
                    model.FinalPosition = position.X + ", " + position.Y + ", " + position.Direction.ToString();
                    model.PenaltyCount  = position.penalty;

                    return(Location(model));
                }
                catch (Exception ex)
                {
                    _logger.LogError("There has been an error " + ex);
                    return(View("Error"));
                }
            }

            return(View("Index", model));
        }
コード例 #2
0
 /// <summary>
 /// Location
 /// </summary>
 /// <param name="model"></param>
 /// <returns>View - Location</returns>
 public IActionResult Location(Models.RobotWars model)
 {
     return(View("Location", model));
 }