public void CoordinatesParserShould_ParseCellCoords(string strCoords, int x, int y)
        {
            var actual = _parser.ParseCellCoords(strCoords, CoordsLimit);

            Assert.AreEqual(x, actual.X);
            Assert.AreEqual(y, actual.Y);
        }
예제 #2
0
        public ActionResult <ShotResult> TakeShot(ShotModel shotModel)
        {
            if (shotModel == null)
            {
                return(BadRequest());
            }
            Coordinates coords;

            try
            {
                coords = _coordinatesParser.ParseCellCoords(shotModel.Coordinates, _game.Matrix.Size);
            }
            catch (BadCoordinatesException e)
            {
                return(BadRequest(e.ToString()));
            }
            if (_battleService.CheckCellIsAlive(coords))
            {
                return(BadRequest($"Shot at coordinates: {coords.StringRepresentation} was taken earlier."));
            }
            _statisticsService.IncrementShotsCount();
            return(_battleService.TakeShot(coords));
        }