Example #1
0
        private MapForEnemyDto CreateEmptyOpponentMapDto()
        {
            var mapForEnemyDto = new MapForEnemyDto();

            for (var x = 0; x < mapForEnemyDto.Cells.GetLength(0); x++)
            {
                for (var y = 0; y < mapForEnemyDto.Cells.GetLength(1); y++)
                {
                    mapForEnemyDto.Cells[x, y] = new CellForEnemyDto();
                }
            }

            return(mapForEnemyDto);
        }
Example #2
0
        private async Task <MapForEnemyDto> FireAsync(MapForEnemyDto opponentMap, RoomDto room)
        {
            while (true)
            {
                var(x, y) = (random.Next(10), random.Next(10));
                if (opponentMap.Cells[x, y].Status == CellForEnemyDtoStatus.Unknown)
                {
                    var fireRequest = new FireRequestDto {
                        X = x, Y = y
                    };
                    var fireResult = await client.FireAsync(fireRequest, room.Id, playerId).ConfigureAwait(false);

                    logger.Info($"Выстрел по координате {(x,y)} с результатом {fireResult.EnemyMap.Cells[x,y].Status}");
                    return(fireResult.EnemyMap);
                }
            }
        }
Example #3
0
        public static Map ToModel(this MapForEnemyDto dto)
        {
            var xLength = dto.Cells.GetLength(0);
            var yLength = dto.Cells.GetLength(1);

            var domainModel = new Map
            {
                Cells = new Cell[xLength, yLength]
            };

            for (var x = 0; x < xLength; x++)
            {
                for (var y = 0; y < yLength; y++)
                {
                    domainModel.Cells[x, y] = dto.Cells[x, y].ToModel();
                }
            }

            return(domainModel);
        }
Example #4
0
        public static MapForEnemyDto ToMapForEnemyDto(this Map map)
        {
            var mapDto = new MapForEnemyDto();

            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    mapDto.Cells[i, j] = new CellForEnemyDto
                    {
                        Status = map.Cells[i, j].Status switch
                        {
                            CellStatus.EmptyFired => CellForEnemyDtoStatus.Missed,
                            CellStatus.EngagedByShipFired => CellForEnemyDtoStatus.Damaged,
                            CellStatus.ShipNeighbour => CellForEnemyDtoStatus.ShipNeighbour,
                            _ => CellForEnemyDtoStatus.Unknown
                        }
                    };
                }
            }

            return(mapDto);
        }