public void MoveTo(int x, int y, float z)
 {
     moving      = true;
     destination = new Vector3(GridPositions.GetVector(x, y).x, GridPositions.GetVector(x, y).y, z);
 }
Exemple #2
0
    void Update()
    {
        //checkMovesTimer += Time.deltaTime;
        if (ScoresManager.CurrentPoints >= WinningScore && started)
        {
            Time.timeScale = 0;
            GameOverText.GetComponent <Text>().text = "You Win!!";
            GameOverText.SetActive(true);
            started = false;
        }
        if (TimeOut && started)
        {
            Time.timeScale = 0;
            GameOverText.GetComponent <Text>().text = "Game Over";
            GameOverText.SetActive(true);
            started = false;
        }
        gameTimer += Time.deltaTime;
        RestTime  -= Time.deltaTime;
        if (RestTime <= 0)
        {
            TimeOut = true;
        }


        if (started)
        {
            _MovingPieces = false;
            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    if (PlayingPieces[x, y] != null && PlayingPieces[x, y].Moving)
                    {
                        _MovingPieces = true;
                        y             = rows;
                        break;
                    }
                }
            }
            if (destroyed && !_MovingPieces)
            {
                PlayerCanMove = false;
                destroyed     = false;
                for (int x = 0; x < columns; x++)
                {
                    SlideDown(x, rows - 1);
                }
                NewPieces();
                PlayerCanMove = true;
            }
            if (!_MovingPieces && !destroyed)
            {
                PlayerCanMove = false;
                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < columns; x++)
                    {
                        CheckTileMatchX(x, y, false);
                        CheckTileMatchY(x, y, false);
                    }
                }
                //deal with coins
                int specialCount = 0;
                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < columns; x++)
                    {
                        if (PlayingPieces[x, y] != null && PlayingPieces[x, y].Selected && PlayingPieces[x, y].Piece != null)
                        {
                            //deal with coins
                            //todo
                            _CurrentPosition = GridPositions.GetVector(x, y);
                            switch (PlayingPieces[x, y].pieceScript.currentStrenght)
                            {
                            case TileType.Normal:
                                Destroy(PlayingPieces[x, y].Piece);
                                PlayingPieces[x, y].Piece    = null;
                                PlayingPieces[x, y].Selected = false;
                                PlayingPieces[x, y]          = null;
                                gdesc[x, y] = (int)TileType.Done;
                                ScoresManager.AddPoints(PointsNormal);
                                RestTime += timeToAdd;
                                break;

                            case TileType.Strong:
                                string name = PlayingPieces[x, y].Piece.GetComponent <TextMesh>().text.ToString();
                                Destroy(PlayingPieces[x, y].Piece);
                                GameObject tmp = PieceNormal[0];
                                tmp.GetComponent <TextMesh>().text = name;
                                PlayingPieces[x, y].Piece          = Instantiate(tmp, new Vector3(_CurrentPosition.x, _CurrentPosition.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject;
                                PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                PlayingPieces[x, y].Selected = false;
                                gdesc[x, y] = (int)TileType.Normal;
                                ScoresManager.AddPoints(PointsNormal);
                                RestTime += timeToAdd;
                                break;
                            }
                            //audio.PlayOneShot(destroyPiece);
                            destroyed = true;
                        }
                    }
                }
                PlayerCanMove = true;
            }
        }
    }
 public void MoveTo(int x, int y)
 {
     moving      = true;
     destination = new Vector3(GridPositions.GetVector(x, y).x, GridPositions.GetVector(x, y).y, myTransform.position.z);
 }
Exemple #4
0
 private void NewPieces()
 {
     for (int x = 0; x < columns; x++)
     {
         for (int y = 0; y < rows; y++)
         {
             if (gdesc[x, y] != (int)TileType.NoTile && PlayingPieces[x, y] == null)
             {
                 int     chance = Random.Range(0, 7);
                 Vector2 v0     = GridPositions.GetVector(x, y);
                 bool    again  = false;
                 do
                 {
                     int t = Random.Range(0, maxPieces);
                     int title;
                     if (DifficultyManagement.currentDifficulty < Difficulty.Three)
                     {
                         title = Random.Range(0, (int)DifficultyManagement.currentDifficulty + 1);
                     }
                     else
                     {
                         title = Random.Range(0, 4);
                     }
                     if (!newPieceFromTop)
                     {
                         if (DifficultyManagement.currentDifficulty < Difficulty.Five)
                         {
                             GetPiecesToUse(title);
                             PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                             PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                         }
                         else
                         {
                             if (DifficultyManagement.currentDifficulty >= Difficulty.Five)
                             {
                                 int tmp = Random.Range(1, 9);
                                 if (tmp < 8)
                                 {
                                     GetPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                 }
                                 else
                                 {
                                     GetStrongPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Strong;
                                 }
                             }
                         }
                     }
                     else
                     {
                         if (DifficultyManagement.currentDifficulty < Difficulty.Five)
                         {
                             GetPiecesToUse(title);
                             PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                             PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                         }
                         else
                         {
                             if (DifficultyManagement.currentDifficulty >= Difficulty.Five)
                             {
                                 int tmp = Random.Range(1, 9);
                                 if (tmp < 8)
                                 {
                                     GetPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                 }
                                 else
                                 {
                                     GetStrongPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Strong;
                                 }
                             }
                         }
                     }
                     if (CheckTileMatchX(x, y, true) || CheckTileMatchY(x, y, true))
                     {
                         DestroyImmediate(PlayingPieces[x, y].Piece);
                         PlayingPieces[x, y] = null;
                         again = true;
                     }
                     else
                     {
                         again = false;
                     }
                 } while (again);
                 //audio.PlayOneShot(newPiece);
                 PlayingPieces[x, y].pieceScript.MoveTo(x, y, zPiecePosition - 25f);
                 PlayingPieces[x, y].Selected = false;
             }
             else if (gdesc[x, y] != (int)TileType.NoTile && PlayingPieces[x, y] != null && PlayingPieces[x, y].pieceScript.currentStrenght != TileType.Normal)
             {
                 break;
             }
         }
     }
 }