/// <summary>
        /// returns the world postions ceter of provide gridcors
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns
        /// >
        private Vector3 CoordsGridToWorld(GridCoords grid)
        {
            float x = grid.x * gridSize + gridSize / 2 + gridOffset.x;
            float y = grid.y * gridSize + gridSize / 2 + gridOffset.y;

            return(new Vector3(x, 0, y));
        }
Exemplo n.º 2
0
    protected virtual void CheckIfInTile()
    {
        if (_currentDropZone != null)
        {
            _spriteRenderer.sprite = angleSprite;
            return;
        }


        _isInTile = GridCoords.IsInTile(transform.position, out _currentTile);

        if (_isInTile)
        {
            _spriteRenderer.sprite = upSprite;

            if (markerPinnedOnTile != null)
            {
                markerPinnedOnTile(this);
            }

            //int sortingOrder = (int)(5000f - (transform.position.y * 32));
            //bool overlap = ObjectsManager.instance.ObjectOverlap(this);
            //if (overlap)
            //{
            //    sortingOrder += 1;
            //}

            //SetOrderInLayer(sortingOrder, false);
        }
        else
        {
            _spriteRenderer.sprite = angleSprite;
        }
    }
        } // ends the Start() function

        /// <summary>
        /// This function allows the towers to be spawned when the mouse is clicked.
        /// </summary>
        void Update()
        {
            SetHelperToMouse();
            if (Input.GetButtonDown("Fire2"))
            {
                /// <summary>
                /// Sets the grid helper to the world coordinates.
                /// </summary>
                GridCoords grid = CoordsWorldToGrid(gridHelper.position);

                if (IsValidGridCoords(grid))
                {
                    /// <summary>
                    /// Shows whether or not there is a tower in the current space on the grid.
                    /// </summary>
                    Tower existingTower = LookupTower(grid);

                    if (existingTower == null)
                    {
                        Tower tower = Instantiate(towerPrefab, gridHelper.position, Quaternion.identity);
                        towers[grid.x, grid.y] = tower;
                    }
                }
            }
        } // ends the Update() function
Exemplo n.º 4
0
    public void Rebuild()
    {
        _grid = new bool[size, height, size];
        for (var x = 0; x < _grid.GetLength(0); x++)
        {
            for (var t = 0; t < _grid.GetLength(1); t++)
            {
                for (var y = 0; y < _grid.GetLength(2); y++)
                {
                    if (Random.value * 100 < obstacleFrequency)
                    {
                        _grid[x, t, y] = true;
                    }
                }
            }
        }

        var center = Mathf.RoundToInt(size / 2);

        _start = new GridCoords(0, 0, 0);
        _end   = new GridCoords(size - 1, height - 1, size - 1);

        if (size > 0 && height > 0)
        {
            _path = SpacetimePathFinder.FindPath(
                _grid, _start, _end, 1, 1, 1
                );
        }
    }
Exemplo n.º 5
0
        public void UpdateObject(WorldObject obj)
        {
            if (this.Grids.ContainsKey(obj.Grid.Value)) //Already associated
            {
                Grid current = this.Grids[obj.Grid.Value];
                if (current.Contains(obj)) //Same grid
                {
                    return;
                }

                if (current.TryRemove(obj))
                {
                    current.SendAll(obj.BuildDestroy());
                }
            }

            GridCoords coords = new GridCoords(obj.Location, obj.Map);

            if (this.Grids.ContainsKey(coords.Key))
            {
                this.Grids[coords.Key].TryAdd(obj);
            }
            else
            {
                AddOrGet(obj, true);
            }
        }
        /// <summary>
        /// spawns a tower on the grid on right click acording to whatever tower is selcted
        /// </summary>
        private void SpawnTowerOnRightClick()
        {
            if (Input.GetButtonDown("Fire2"))
            {
                GridCoords grid = CoordsWorldToGrid(gridHelper.position);
                if (IsValidGridCoords(grid))
                {
                    Tower exstingTower = LookUpTower(grid);
                    if (exstingTower == null)
                    {
                        if (buildDarkTower == true)
                        {
                            Tower tower = Instantiate(towerPrefab, gridHelper.position, Quaternion.identity);

                            towers[grid.x, grid.y] = tower;
                        }
                        if (buildLightTower == true)
                        {
                            Tower tower = Instantiate(towerPrefabLight, gridHelper.position, Quaternion.identity);

                            towers[grid.x, grid.y] = tower;
                        }
                        if (buildNatrueTower == true)
                        {
                            Tower tower = Instantiate(towerPrefabNature, gridHelper.position, Quaternion.identity);

                            towers[grid.x, grid.y] = tower;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Method which handles a shot being fired within a Game
        /// </summary>
        /// <param name="game"></param>
        /// <param name="shot"></param>
        /// <returns></returns>
        public Game FireShot(Game game, GridCoords shot)
        {
            var indices = ArrayMapper.GetArrayIndicesForCoords(shot);

            var target = game.GameGrid.Cells[indices.X, indices.Y];

            switch (target.Status)
            {
            case GridCellStatus.OpenSea:
                game = ShotMissed(game, indices);
                break;

            case GridCellStatus.ShipIntact:
                game = ShotLanded(game, indices);
                break;

            case GridCellStatus.ShotLanded:
                AlreadyAttempted(game);
                break;

            case GridCellStatus.ShotMissed:
                AlreadyAttempted(game);
                break;
            }
            ;

            return(game);
        }
Exemplo n.º 8
0
    private bool ValidateDestination(string dest, out TileCoordinates destCoords)
    {
        destCoords = new TileCoordinates(0, 0);
        bool valid = GridCoords.FromTileNameToTilePosition(dest, out destCoords);

        return(valid);
    }
 /// <summary>
 /// checks  if towers on vaild cords
 /// </summary>
 /// <param name="grid"></param>
 /// <returns></returns>
 private Tower LookUpTower(GridCoords grid)
 {
     if (!IsValidGridCoords(grid))
     {
         return(null);
     }
     return(towers[grid.x, grid.y]);
 }
Exemplo n.º 10
0
        } // ends the LookupTower() function

        /// <summary>
        /// This function checks to see if the grid coordinates are valid.
        /// </summary>
        /// <param name="grid">The grid to check.</param>
        /// <returns>Whether or not the coordinates are valid.</returns>
        private bool IsValidGridCoords(GridCoords grid)
        {
            if (grid.x < 0) return false;
            if (grid.y < 0) return false;
            if (grid.x >= towers.GetLength(0)) return false;
            if (grid.y >= towers.GetLength(1)) return false;

            return true;
        } // ends the IsValidGridCoords() function
Exemplo n.º 11
0
    // Fonction qui essaie d'exécuter la commande à partir de la syntaxe fournie.
    // Si la syntaxe est invalide, la commande ne s'exécute pas, et renvoie un message d'erreur au CommandManager.
    public override bool TryExecution(string shipName, string coordinatesText, string productCode, out string errorMessage)
    {
        // Variables locales temporaires
        bool    success             = false;
        bool    validShip           = false;
        Ship    targetShip          = null;
        bool    coordsInDeployPoint = false;
        Vector2 shipGridCoords      = Vector2.zero;

        errorMessage = "";

        //Validation 1 : -Vérifier avec le ShipManager si le vaisseau entré est trouvable.
        if (ShipManager.instance != null)
        {
            validShip = ShipManager.instance.FindShipByCallsign(shipName, out targetShip);
        }


        // Validation 2 : Vérifier avec deploymanager si les coordonnées du vaisseaux sont dans un point de déploiement.
        if (targetShip != null)
        {
            shipGridCoords = GridCoords.FromWorldToGrid(targetShip.transform.position);

            if (DeployManager.instance != null)
            {
                coordsInDeployPoint = DeployManager.instance.IsInDeployPoint(shipGridCoords);
            }
            else
            {
                coordsInDeployPoint = false;
            }
        }

        //Confirmation finale 1 : Le vaisseau est valide?
        if (!validShip)
        {
            success      = false;
            errorMessage = "Invalid ship name : " + shipName;
        }

        // Confirmation finale 2 : Les coordonnées sont dans un point de déploiement?
        else if (!coordsInDeployPoint)
        {
            success      = false;
            errorMessage = "Coordinates are outisde of Deploy Point : " + coordinatesText;
        }

        // Si tout est valide, exécution de la commande et envoie du bool succès au CommandManager
        else
        {
            success = true;
            ExecuteCommand(targetShip);
        }

        return(success);
    }
Exemplo n.º 12
0
    public override bool TryExecution(string shipName, List <string> route, out string errorMessage)
    {
        // Variables locales temporaires
        bool   success     = false;
        bool   validShip   = false;
        bool   validCoords = false;
        string coordsError = "";
        Ship   targetShip  = null;

        errorMessage = "";

        //Validation 1 : -Vérifier avec le ShipManager si le vaisseau entré est trouvable.
        if (ShipManager.instance != null)
        {
            validShip = ShipManager.instance.FindShipByCallsign(shipName, out targetShip);
        }


        foreach (var pos in route)
        {
            TileCoordinates coords = default;
            validCoords = (GridCoords.FromTileNameToTilePosition(pos, out coords));
            if (!validCoords)
            {
                coordsError = "Position " + pos + " does not exist.";
                break;
            }
        }

        //TODO: Confirmation finale 1 : Le vaisseau est valide?
        if (!validShip)
        {
            success      = false;
            errorMessage = "Invalid ship name : " + shipName;
        }
        else if (!validCoords)
        {
            errorMessage = "MOVE syntax error : \n\n" + coordsError;

            if (MessageManager.instance != null)
            {
                MessageManager.instance.GenericMessage(errorMessage, true);
            }

            success = false;
        }
        // Si tout est valide, exécution de la commande et envoie du bool succès au CommandManager
        else
        {
            success = true;
            ExecuteCommand(targetShip, route);
        }

        return(success);
    }
Exemplo n.º 13
0
    private void CheckForClients()
    {
        TileCoordinates currentTile = GridCoords.FromWorldToTilePosition(transform.position);
        GridTile        tile        = GridCoords.CurrentGridInfo.gameGridTiles[currentTile.tileX, currentTile.tileY];
        GridTile_Planet planet      = tile.GetComponent <GridTile_Planet>();

        if (planet != null)
        {
            CheckForClients(planet);
        }
    }
Exemplo n.º 14
0
    public override void PlaceGridObject(Vector2 gridCoordinates)
    {
        GridCoordinates         = gridCoordinates;
        ParentTile              = GridCoords.FromGridToTile(gridCoordinates);
        this.transform.position = GridCoords.FromGridToWorld(gridCoordinates);

        if (gridObjectPositionAdded != null)
        {
            gridObjectPositionAdded(this);
        }
    }
Exemplo n.º 15
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public void Reset()
    {
        m_TYPE = WEB_MAP_TYPE.Satellite;

        m_size = 512;

        m_hres = false;

        m_coordGeo = Vector3.zero;

        m_coordGrid = new GridCoords(int.MaxValue, int.MaxValue);
    }
Exemplo n.º 16
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public void Set(WebMapParams otherParams)
    {
        m_TYPE = otherParams.m_TYPE;

        m_size = otherParams.m_size;

        m_hres = otherParams.m_hres;

        m_coordGeo = otherParams.m_coordGeo;

        m_coordGrid = otherParams.m_coordGrid;
    }
Exemplo n.º 17
0
    public bool IsInDeployTile(TileCoordinates tileCoords)
    {
        Vector2 worldCoords = GridCoords.FromTilePositionToWorld(tileCoords);

        foreach (var deployTile in _allDeployTiles)
        {
            if (deployTile.IsInTile(worldCoords))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 18
0
    public void Move(Vector2 gridCoords)
    {
        if (pickupCoroutine != null)
        {
            StopCoroutine(pickupCoroutine);
            pickupCoroutine = null;
        }

        //When MOVE command is called, it converts gridCoords to WorldCoords and sets isMoving to true
        displayedGridCoords = gridCoords;
        targetWorldCoords   = GridCoords.FromGridToWorld(gridCoords);
        isMoving            = true;
    }
Exemplo n.º 19
0
        public void GetArrayIndicesForCoords_WhenArgumentsAreValid_ExpectSuccessfulMapping()
        {
            // Arrange
            _gridCoordsArgument   = new GridCoords(5, "D");
            _arrayIndicesResponse = new Indices(4, 3);

            // Act
            var result = ArrayMapper.GetArrayIndicesForCoords(_gridCoordsArgument);

            // Assert
            Assert.AreEqual(this._arrayIndicesResponse.X, result.X);
            Assert.AreEqual(this._arrayIndicesResponse.Y, result.Y);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns a pair of array indices for a given set of Grid Coordinates
        /// </summary>
        /// <returns></returns>
        public static Indices GetArrayIndicesForCoords(GridCoords coords)
        {
            Condition.Requires(coords).IsNotNull("coords");
            Condition.Requires(coords.X).IsGreaterOrEqual(1);
            Condition.Requires(coords.Y).IsShorterOrEqual(1);

            var x = coords.X - 1;
            var y = AlphabetHelper.GetAlphabetPositionOfLetter(coords.Y.ToString()) - 1;

            var indices = new Indices(x, y);

            return(indices);
        }
Exemplo n.º 21
0
    // Fonction qui permet de vérifier si une coordonnée donnée se trouve dans un point de déploiement
    public bool IsInDeployPoint(Vector2 gridCoords)
    {
        Vector2 worldCoords = GridCoords.FromGridToWorld(gridCoords);

        foreach (var deployPoint in _allDeployPoints)
        {
            if (deployPoint.IsInRadius(worldCoords))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 22
0
        public void GetCoordsForArrayIndices_WhenArgumentsAreValid_ExpectSuccessMapping()
        {
            // Arrange
            _arrayIndicesArgument = new Indices(6, 3);
            _gridCoordsResponse   = new GridCoords(7, "D");

            // Act
            var result = ArrayMapper.GetCoordsForArrayIndices(_arrayIndicesArgument);

            // Assert
            Assert.IsInstanceOfType(result, typeof(GridCoords));
            Assert.AreEqual(this._gridCoordsResponse.X, result.X);
            Assert.AreEqual(this._gridCoordsResponse.Y, result.Y);
        }
Exemplo n.º 23
0
    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        else
        {
            instance = this;
        }

        _gridCoords = GetComponent <GridCoords>();
        _pathFinder = GetComponent <PathFinder>();
    }
Exemplo n.º 24
0
        /// <summary>
        /// makes the visual fllow the mouse so u can see where tower spanes
        /// </summary>

        private void SetHelperToMouse()
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition); // creat a ray from the camera through

            if (Physics.Raycast(ray, out RaycastHit hit, 50, objectsThatSupportTowers))
            { //
                GridCoords gridPos    = CoordsWorldToGrid(hit.point);
                bool       isVaildPos = IsValidGridCoords(gridPos);
                gridHelper.gameObject.SetActive(isVaildPos);
                Vector3 worldPos = CoordsGridToWorld(gridPos);
                worldPos.y          = hit.point.y + +0.01f;
                gridHelper.position = worldPos;
                // tell new agent to go where we clicked
            }
        }
Exemplo n.º 25
0
        public void GetArrayIndicesForCoords_WhenTheXCoordIsInvalid_ExpectArgumentException()
        {
            // Arrange
            _gridCoordsArgument = new GridCoords(-1, "E");

            // Act
            try
            {
                var result = ArrayMapper.GetArrayIndicesForCoords(_gridCoordsArgument);
            }
            catch (Exception ex)
            {
                // Assert
                Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
                throw;
            }
        }
Exemplo n.º 26
0
    // Vérifier si la souris se trouve sur la grille
    private bool MouseIsOverGrid(out Vector3 mousePos)
    {
        // Convertir position de souris en pixels en une position en WORLD COORDS
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePosition.z = 0f;
        mousePos        = mousePosition;

        // Assigner le texte
        _coordsText = GridCoords.FromWorldToGrid(mousePos).ToString();

        // Vérifier si la position se trouve dans les bounds de la grille.
        if (_currentGridInfo.gameGridWorldBounds.Contains(mousePosition))
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 27
0
        private void SetHelperToMouse()
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);                        // create a ray from the camera, throught the mouse position

            if (Physics.Raycast(ray, out RaycastHit hit, 50, objectsThatSupportTowers)) // shoot ray into scene, detect hit
            {
                GridCoords gridPos = CoordsWorldToGrid(hit.point);

                bool isValidPos = IsValidGridCoords(gridPos);

                gridHelper.gameObject.SetActive(isValidPos);


                Vector3 worldPos = CoordsGridToWorld(gridPos);
                worldPos.y = hit.point.y + .01f;

                gridHelper.position = worldPos;
            }
        }
Exemplo n.º 28
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public GridCoords GetGridCoordsFromRelativePosition(Vector3 pos)
    {
        GridCoords coords = new GridCoords();

        Vector3 gridLocalPos = (pos + m_virtualPos) - m_TLCorner;

        coords.X = ( int )(gridLocalPos.x / m_tilesSize); if (gridLocalPos.x < 0)
        {
            coords.X += (1 << zoom) - 1;
        }

        coords.Y = ( int )(-gridLocalPos.z / m_tilesSize); if (gridLocalPos.z > 0)
        {
            coords.Y += (1 << zoom) - 1;
        }

        coords.Clamp(1 << zoom, 1 << zoom);

        return(coords);
    }
Exemplo n.º 29
0
    protected override void CheckIfInTile()
    {
        base.CheckIfInTile();

        if (_currentDropZone != null)
        {
            _tileText.enabled = false;
            return;
        }

        if (_isInTile)
        {
            _tileText.text    = GridCoords.GetTileName(_currentTile);
            _tileText.enabled = true;
        }
        else
        {
            _tileText.enabled = false;
        }
    }
Exemplo n.º 30
0
        } // ends the IsValidGridCoords() function

        /// <summary>
        /// This function sets the grid helper to the mouse and allows it to move with the mouse.
        /// </summary>
        private void SetHelperToMouse()
        {
            /// <summary>
            /// creates a ray from the camera to the mouse
            /// </summary>
            Ray ray = cam.ScreenPointToRay(Input.mousePosition); // create a ray from the camera, to the mouse

            if (Physics.Raycast(ray, out RaycastHit hit))//, 50, objectsThatSupportTowers))
            {
                GridCoords gridPos = CoordsWorldToGrid(hit.point);

                bool isValidPos = IsValidGridCoords(gridPos);
                gridHelper.gameObject.SetActive(isValidPos);

                Vector3 worldPos = CoordsGridToWorld(gridPos);
                worldPos.y = hit.point.y + .01f;

                gridHelper.position = worldPos;

            }
        } // ends the SetHelperToMouse()