Example #1
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);
        }
Example #2
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);
                }
            }
        }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        playerObject = Instantiate(playerPrefab);
        enemyObject  = Instantiate(enemyPrefab);

        _inputHandler = new InputHandler();
        _inputHandler.InputInit();
        _player      = new Player(playerObject);
        _powerUpPool = new ObjectPool <PowerUp>();

        _levelGeneration = new LevelGeneration(_player, _powerUpPool) as ILevelGenerator;
        _score           = new PointCounter();

        powerUpManager = new PowerUpManager();
        //powerUpManager.createRandomPowerUp(Instantiate(PowerUpPrefab).transform);

        _enemyStateMachine = new EnemyFSM();
        _enemyStateMachine.AddState(EnemyStateType.Idle, new IdleState());
        _enemyStateMachine.AddState(EnemyStateType.Attack, new AttackState());



        _levelGeneration = new LevelGeneration() as ILevelGenerator;

        _randomCoordinate = new RandomCoordinate(_levelGeneration);
        _pathfinder       = new Pathfinder2(_levelGeneration);
    }
Example #4
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);
        }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        _winScreen.gameObject.SetActive(false);
        _playerObject = Instantiate(_playerPrefab);

        _inputHandler = new InputHandler();
        _inputHandler.InputInit();
        _player      = new Player(_playerObject);
        _powerUpPool = new ObjectPool <PowerUp>();

        _levelGeneration = new LevelGeneration(_player, _powerUpPool) as ILevelGenerator;
        _score           = new PointCounter();

        _powerUpManager = new PowerUpManager();

        _enemyStateMachine = new EnemyFSM();
        _enemyStateMachine.AddState(EnemyStateType.Idle, new IdleState());
        _enemyStateMachine.AddState(EnemyStateType.Attack, new AttackState());

        _randomCoordinate = new RandomCoordinate(_levelGeneration);
        _pathfinder       = new Pathfinder2(_levelGeneration);
    }