Ejemplo n.º 1
0
    private void NodaCheck()
    {
        List <Vector2Int> dirVectors = new List <Vector2Int> {
            Vector2Int.right, Vector2Int.left, Vector2Int.up, Vector2Int.down
        };

        foreach (var item in dirVectors)
        {
            Vector2Int vector = open[0] + item;

            if (characterProvider.IsExistsPosition(vector) && characterProvider.Get(vector.x, vector.y) == null)
            {
                if (close.IndexOf(vector) == -1)
                {
                    if (path.IndexOf(vector) == -1)
                    {
                        path.Add(vector);
                        pathlink.Add(open[0]);
                        open.Add(vector);
                    }
                }
            }
        }

        close.Add(open[0]);
        open.RemoveAt(0);
    }
Ejemplo n.º 2
0
    public void Save()
    {
        var nextIndexPrefab = _gameWorld.GetNextPrefabIndexs();

        var allCharacters = _characterProvider.GetAllFillPosition();

        SaveCharacter[] allSavedCharacters = new SaveCharacter[allCharacters.Count];

        for (int i = 0; i < allCharacters.Count; i++)
        {
            var x         = allCharacters[i].x;
            var y         = allCharacters[i].y;
            var character = _characterProvider.Get(x, y);

            if (character != null)
            {
                allSavedCharacters[i] = new SaveCharacter()
                {
                    prefabIndex = character.PrefabIndex, x = x, y = y
                };
            }
        }

        Save save = new Save()
        {
            score          = _score.Value,
            allCharacters  = allSavedCharacters,
            nextCharacters = nextIndexPrefab
        };

        string json = JsonUtility.ToJson(save);

        File.WriteAllText(filePath, json);
    }
Ejemplo n.º 3
0
    private Character[,] HorizontalLines()
    {
        var width  = characterProvider.Width;
        var height = characterProvider.Height;

        Character[,] lines = new Character[height, width];

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                lines[y, x] = characterProvider.Get(x, y);
            }
        }

        return(lines);
    }
Ejemplo n.º 4
0
    public void SelectPosition(Vector2Int position)
    {
        if (characterProvider.IsExistsPosition(position) == false)
        {
            return;
        }

        var character = characterProvider.Get(position.x, position.y);

        if (character != null)
        {
            if (selectedCharacter != character)
            {
                if (selectedCharacter != null)
                {
                    selectedCharacter.OnMoved -= MovedCharacterHandler;
                    selectedCharacter.Unselect();
                }

                selectedCharacter = character;
                selectionSound.Play();
                character.Select();
                var pos = Vector2Int.RoundToInt(character.transform.localPosition);
                pathFinder.CreatePathMap(pos);
            }
        }
        else if (selectedCharacter != null && pathFinder.IsInPathMap(position))
        {
            selectionSound.Play();
            gameWorldInput.enabled = false;
            pathFinder.DestroyPathMarkers();
            var startPosition = Vector2Int.RoundToInt(selectedCharacter.transform.localPosition);
            var path          = pathFinder.GetPath(startPosition, position);

            selectedCharacter.OnMoved += MovedCharacterHandler;
            selectedCharacter.StartMove(path);
        }
    }