diff --git a/Controllers/FieldController.cs b/Controllers/FieldController.cs index c9e329a..332c81c 100644 --- a/Controllers/FieldController.cs +++ b/Controllers/FieldController.cs @@ -30,20 +30,37 @@ namespace WebApplication1.Controllers [HttpPost("new")] - public Field StartNewGame() + public ActionResult StartNewGame() { - return _fm.StartNewGame(); + Field result = _fm.StartNewGame(); + if (result == null) + { + return NotFound(); + } + + return Ok(result); } [HttpPost("move")] - public Field Move(string identifier) + public ActionResult Move(string identifier) { - return _fm.Move(identifier); + Field result = _fm.Move(identifier); + if (result == null) + { + return NotFound(); + } + + return Ok(result); } [HttpGet("list")] - public Field List(string identifier) + public ActionResult List(string identifier) { - return _fm.List(identifier); + var result = _fm.List(identifier); + if (result == null) + { + return NotFound(); + } + return Ok(result); } } diff --git a/Model/RandomField.cs b/Model/RandomField.cs index 29ebd09..26015df 100644 --- a/Model/RandomField.cs +++ b/Model/RandomField.cs @@ -4,6 +4,9 @@ namespace WebApplication1 { public class RandomField : Field { + private const int MaxTypeValue = 1; + private const int MaxColorValue = 2; + public RandomField(int iCount) { Random rr = new Random(); @@ -11,10 +14,10 @@ namespace WebApplication1 { this.Figures.Add(new Figure() { - FigureColor = rr.Next(2), - FigureType = rr.Next(1), - PosX = rr.Next(FigureMover.FieldXMin, FigureMover.FieldXMax), - PosY = rr.Next(FigureMover.FieldYMin, FigureMover.FieldYMax), + FigureColor = rr.Next(MaxColorValue), + FigureType = rr.Next(MaxTypeValue) + 1, + PosX = rr.Next(FigureMover.FieldXMin, FigureMover.FieldXMax + 1), + PosY = rr.Next(FigureMover.FieldYMin, FigureMover.FieldYMax + 1), }); } } diff --git a/TextFile.md b/TextFile.md index 2c7ba93..e6395ba 100644 --- a/TextFile.md +++ b/TextFile.md @@ -1,5 +1,6 @@ # Задача -Продемонстрировать работающий сервис с реализацией логики вне контроллера +Продемонстрировать работающий сервис +с реализацией логики вне контроллера # Алгоритм решения задачи - Создать пустое веб-апи сервис на основе шаблона