Esempio n. 1
0
        [InlineData(-33.996379, 18.537121, "South Africa")]             // Cape Point
        public void RandomCoordinate_Next_Multi_ShouldGenerateValidCoordinate(double lat, double lng, string country)
        {
            RandomCoordinate         randomCoordinate = new();
            IEnumerable <Coordinate> coordinates      = RandomCoordinate.Next(new Coordinate(lat, lng), 1000, 5);

            foreach (Coordinate coordinate in coordinates)
            {
                Assert.True(coordinate.Latitude >= -90 && coordinate.Latitude <= 90);
                Assert.True(coordinate.Longitude >= -180 && coordinate.Longitude <= 180);

                string requestUri = $"https://eu1.locationiq.com/v1/reverse.php" +
                                    $"?key={TestSettings.LocationIqKey}" +
                                    $"&lat={coordinate.Latitude.ToString(CultureInfo.InvariantCulture)}" +
                                    $"&lon={coordinate.Longitude.ToString(CultureInfo.InvariantCulture)}" +
                                    $"&format=json";

                RestClient  client  = new();
                RestRequest request = new(requestUri, DataFormat.Json);

                IRestResponse <GeocodeResponse> response = client.Get <GeocodeResponse>(request);
                GeocodeResponse responseData             = response.Data;

                if (responseData.Address != null)
                {
                    Assert.True(responseData.Address.Country == country);
                }
            }
        }
Esempio n. 2
0
        public bool EnemyChooseCellToShoot(Board board)
        {
            var coord = new Coord();

            do
            {
                coord.Number = RandomCoordinate.Next(10) + 1;
                coord.Letter = RandomCoordinate.Next(10) + 1;
                switch (BoardContent[coord.Letter, coord.Number])
                {
                case CellContent.empty:
                    BoardContent[coord.Letter, coord.Number] = CellContent.missedShot;
                    RedrawBoard();
                    Console.Write("Pudło!");
                    return(false);

                case CellContent.ship:
                    if (CheckIfShootSinkTheShip(board, coord))
                    {
                        RedrawBoard();
                        Console.Write("Trafiony zatopiony! Przeciwnik może strzelić jeszcze raz.");
                    }
                    else
                    {
                        RedrawBoard();
                        Console.Write("Trafiony! Przeciwnik może strzelić jeszcze raz.");
                    }
                    return(true);

                default:
                    break;
                }
            }while (true);
        }
Esempio n. 3
0
        public Ship(int shipSize, Board board)
        {
            Body = new List <Part>();
            var Coord1 = new Coord();
            var Coord2 = new Coord();

            do
            {
                do
                {
                    Coord1.Letter = RandomCoordinate.Next(10) + 1;
                    Coord1.Number = RandomCoordinate.Next(10) + 1;
                } while (!CellIsAvailable(Coord1, board));

                Coord2.Number = Coord1.Number;
                Coord2.Letter = Coord1.Letter;

                if (CellIsAvailable(Coord1.Letter + shipSize - 1, Coord1.Number, board))
                {
                    Coord2.Letter = Coord1.Letter + shipSize - 1;
                }
                else if (CellIsAvailable(Coord1.Letter, Coord1.Number + shipSize - 1, board))
                {
                    Coord2.Number = Coord1.Number + shipSize - 1;
                }
                else if (CellIsAvailable(Coord1.Letter, Coord1.Number - shipSize + 1, board))
                {
                    Coord2.Number = Coord1.Number - shipSize + 1;
                }
                else
                {
                    Coord2.Letter = Coord1.Letter - shipSize + 1;
                }
            } while (!CellIsAvailable(Coord2, board));

            for (int row = Math.Min(Coord1.Letter, Coord2.Letter);
                 row <= Math.Max(Coord1.Letter, Coord2.Letter); row++)
            {
                for (int column = Math.Min(Coord1.Number, Coord2.Number);
                     column <= Math.Max(Coord1.Number, Coord2.Number); column++)
                {
                    Body.Add(new Part
                    {
                        ShipPart = CellContent.ship,
                        Coord    = new Coord {
                            Letter = row, Number = column
                        }
                    });
                }
            }

            UpdateShipOnBoard(board);
        }