Exemple #1
0
        private ShipDto CreateShip(ShipData shipData)
        {
            var k    = 0;
            var ship = new ShipDto
            {
                Cells = new List <CellDto>()
            };

            while (k < shipData.Desk)
            {
                _matrix[shipData.X + k * shipData.KX][shipData.Y + k * shipData.KY] = 1;
                ship.Cells.Add(new CellDto
                {
                    X       = shipData.X + k * shipData.KX,
                    Y       = shipData.Y + k * shipData.KY,
                    IsAlive = true
                });

                k++;
            }

            ship.IsHorizontal = shipData.KX == 1;

            return(ship);
        }
        public async Task <IActionResult> GetAllShips()
        {
            var ships = await shipService.GetAllShips();

            var shipsDto = ShipDto.ToListShipDto(ships);

            return(Ok(new ShipDto {
                Ships = shipsDto
            }));
        }
Exemple #3
0
        private dynamic ExpandSingleShipItem(ShipEntity shipItem, ApiVersion version)
        {
            var     links = GetLinks(shipItem.ShipId, version);
            ShipDto item  = _mapper.Map <ShipDto>(shipItem);

            var resourceToReturn = item.ToDynamic() as IDictionary <string, object>;

            resourceToReturn.Add("links", links);

            return(resourceToReturn);
        }
        public async Task <IActionResult> CreateShip(ShipDto type)
        {
            if (!Enum.IsDefined(typeof(ShipType), type.Type))
            {
                return(BadRequest(new ResponseDto {
                    Status = "error", Message = "Wrong type of ship"
                }));
            }

            await timeService.UpdateResourceAmount(1);

            var ship = await purchaseService.PurchaseNewShip(type.Type);

            if (ship == null)
            {
                return(BadRequest(new ResponseDto
                {
                    Status = "error", Message = "You don't have enough of gold or food"
                }));
            }
            return(Ok(new ShipDto(ship)));
        }