示例#1
0
    public void LoadGame()
    {
        if (saveGame == true)
        {
            score = saveScore;
            UpdateScore();

            foreach (Transform child in transform)
            {
                Destroy(child.gameObject);
            }
            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    grid[x, y] = null;

                    NotATile notATile = saveGrid[x, y];
                    if (notATile != null)
                    {
                        int    tileValue   = notATile.value;
                        string newTileName = "tile_" + tileValue;

                        GameObject newTile = (GameObject)Instantiate(Resources.Load(newTileName, typeof(GameObject)), notATile.location, Quaternion.identity);

                        newTile.transform.parent = transform;
                        grid[x, y] = newTile.transform;
                    }
                }
            }
        }
    }
示例#2
0
    public void SaveGame()
    {
        saveGame = true;

        saveScore = score;

        for (int x = 0; x < gridWidth; x++)
        {
            for (int y = 0; y < gridHeight; y++)
            {
                saveGrid[x, y] = null;

                if (grid[x, y] != null)
                {
                    Transform t        = grid[x, y];
                    Vector2   location = t.localPosition;

                    int value = t.GetComponent <Tile>().tileValue;

                    NotATile notATile = new NotATile();

                    notATile.location = location;

                    notATile.value = value;

                    saveGrid[x, y] = notATile;
                }
            }
        }
    }
示例#3
0
    public void Undo()
    {
        score = previousScore;
        UpdateScore();

        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }
        for (int i = 0; i < gridWidth; i++)
        {
            for (int j = 0; j < gridHeigth; j++)
            {
                grid[i, j] = null;
                NotATile notAtile = previousGrid[i, j];

                if (notAtile != null)
                {
                    int    tileValue   = notAtile.getValue();
                    string newTileName = "tile_" + tileValue;

                    GameObject newTile = (GameObject)Instantiate(Resources.Load(newTileName, typeof(GameObject)), notAtile.getLocation(), Quaternion.identity);
                    newTile.transform.parent = transform;
                    grid[i, j] = newTile.transform;
                }
            }
        }
    }
示例#4
0
    public void Undo()
    {
        if (madeFirstMove)
        {
            // debug.Add("Undo Pressed", "Yes", "Undo Pressed", CFDebugObject.DebugMessageKind.Informational,false);

            if (CheckGameOver())
            {
                gameOverCanvas.gameObject.SetActive(false);
            }

            score = previousScore;

            UpdateScore();

            foreach (Transform child in transform)
            {
                Destroy(child.gameObject);
            }

            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    grid[x, y] = null;

                    NotATile notATile = previousGrid[x, y];

                    if (notATile != null)
                    {
                        int    tileValue   = notATile.value;
                        string newTileName = "tile_" + tileValue;

                        GameObject newTile = (GameObject)Instantiate(Resources.Load(newTileName, typeof(GameObject)), notATile.location, Quaternion.identity);

                        newTile.transform.parent = transform;

                        grid[x, y] = newTile.transform;
                    }
                }
            }
        }
    }
示例#5
0
 private void storePreviousTiles()
 {
     previousScore = score;
     for (int i = 0; i < gridWidth; i++)
     {
         for (int j = 0; j < gridHeigth; j++)
         {
             Transform tempTile = grid[i, j];
             previousGrid[i, j] = null;
             if (tempTile != null)
             {
                 NotATile notATile = new NotATile();
                 notATile.setLocation(tempTile.localPosition);
                 notATile.setValue(tempTile.GetComponent <tile>().tileValue);
                 previousGrid[i, j] = notATile;
                 //se guardan todas las posiciones de las Tiles para poder volver atras
             }
         }
     }
 }
示例#6
0
    private void StorePreviousTiles()
    {
        previousScore = score;

        for (int x = 0; x < gridWidth; x++)
        {
            for (int y = 0; y < gridHeight; y++)
            {
                Transform tempTile = grid[x, y];
                previousGrid[x, y] = null;

                if (tempTile != null)
                {
                    NotATile notATile = new NotATile();

                    notATile.location = tempTile.localPosition;
                    notATile.value    = tempTile.GetComponent <Tile>().tileValue;

                    previousGrid[x, y] = notATile;
                }
            }
        }
    }