示例#1
0
    void Update()
    {
        // 뒤로가기
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (stop)
        {
            return;
        }

        // 문지르기
        if (Input.GetMouseButtonDown(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began))
        {
            wait     = true;
            firstPos = Input.GetMouseButtonDown(0) ? Input.mousePosition : (Vector3)Input.GetTouch(0).position;
        }

        if (Input.GetMouseButton(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved))
        {
            gap = (Input.GetMouseButton(0) ? Input.mousePosition : (Vector3)Input.GetTouch(0).position) - firstPos;
            if (gap.magnitude < 100)
            {
                return;
            }
            gap.Normalize();

            if (wait)
            {
                wait = false;
                // 위
                if (gap.y > 0 && gap.x > -0.5f && gap.x < 0.5f)
                {
                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 0; y <= 2; y++)
                        {
                            for (i = 3; i >= y + 1; i--)
                            {
                                MoveOrCombine(x, i - 1, x, i);
                            }
                        }
                    }
                }
                // 아래
                else if (gap.y < 0 && gap.x > -0.5f && gap.x < 0.5f)
                {
                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 3; y >= 1; y--)
                        {
                            for (i = 0; i <= y - 1; i++)
                            {
                                MoveOrCombine(x, i + 1, x, i);
                            }
                        }
                    }
                }
                // 오른쪽
                else if (gap.x > 0 && gap.y > -0.5f && gap.y < 0.5f)
                {
                    for (y = 0; y <= 3; y++)
                    {
                        for (x = 0; x <= 2; x++)
                        {
                            for (i = 3; i >= x + 1; i--)
                            {
                                MoveOrCombine(i - 1, y, i, y);
                            }
                        }
                    }
                }
                // 왼쪽
                else if (gap.x < 0 && gap.y > -0.5f && gap.y < 0.5f)
                {
                    for (y = 0; y <= 3; y++)
                    {
                        for (x = 3; x >= 1; x--)
                        {
                            for (i = 0; i <= x - 1; i++)
                            {
                                MoveOrCombine(i + 1, y, i, y);
                            }
                        }
                    }
                }
                else
                {
                    return;
                }

                if (move)
                {
                    move = false;
                    Spawn();
                    k = 0;
                    l = 0;

                    // 점수
                    if (score > 0)
                    {
                        Plus.text = "+" + score.ToString() + "    ";
                        Plus.GetComponent <Animator>().SetTrigger("PlusBack");
                        Plus.GetComponent <Animator>().SetTrigger("Plus");
                        Score.text = (int.Parse(Score.text) + score).ToString();
                        if (PlayerPrefs.GetInt("BestScore", 0) < int.Parse(Score.text))
                        {
                            PlayerPrefs.SetInt("BestScore", int.Parse(Score.text));
                        }
                        BestScore.text = PlayerPrefs.GetInt("BestScore").ToString();
                        score          = 0;
                    }

                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 0; y <= 3; y++)
                        {
                            // 모든 타일이 가득 차면 k가 0이 된다.
                            if (Square[x, y] == null)
                            {
                                k++; continue;
                            }
                            if (Square[x, y].tag == "Combine")
                            {
                                Square[x, y].tag = "Untagged";
                            }
                        }
                    }
                    if (k == 0)
                    {
                        // 가로, 세로 같은 블럭이 없으면 l이 0이 되어서 게임 종료
                        for (y = 0; y <= 3; y++)
                        {
                            for (x = 0; x <= 2; x++)
                            {
                                if (Square[x, y].name == Square[x + 1, y].name)
                                {
                                    l++;
                                }
                            }
                        }
                        for (x = 0; x <= 3; x++)
                        {
                            for (y = 0; y <= 2; y++)
                            {
                                if (Square[x, y].name == Square[x, y + 1].name)
                                {
                                    l++;
                                }
                            }
                        }
                        if (l == 0)
                        {
                            stop = true; Quit.SetActive(true); return;
                        }
                    }
                }
            }
        }
    }
示例#2
0
    void Update()
    {
        if (stop)
        {
            return;
        }

        // scrape
        if (Input.GetMouseButtonDown(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began))
        {
            wait     = true;
            firstPos = Input.GetMouseButtonDown(0) ? Input.mousePosition : (Vector3)Input.GetTouch(0).position;
        }

        if (Input.GetMouseButton(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved))
        {
            gap = (Input.GetMouseButton(0) ? Input.mousePosition : (Vector3)Input.GetTouch(0).position) - firstPos;
            if (gap.magnitude < 100)
            {
                return;
            }
            gap.Normalize();



            if (wait && !menuPanel.activeSelf)
            {
                wait = false;
                //  Up
                if (gap.y > 0 && gap.x > -0.5f && gap.x < 0.5f)
                {
                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 0; y <= 2; y++)
                        {
                            for (i = 3; i >= y + 1; i--)
                            {
                                MoveOrCombine(x, i - 1, x, i);
                            }
                        }
                    }
                    Debug.Log("Up");
                }
                // Down
                else if (gap.y < 0 && gap.x > -0.5f && gap.x < 0.5f)
                {
                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 3; y >= 1; y--)
                        {
                            for (i = 0; i <= y - 1; i++)
                            {
                                MoveOrCombine(x, i + 1, x, i);
                            }
                        }
                    }
                    Debug.Log("Down");
                }
                // Right
                else if (gap.x > 0 && gap.y > -0.5f && gap.y < 0.5f)
                {
                    for (y = 0; y <= 3; y++)
                    {
                        for (x = 0; x <= 2; x++)
                        {
                            for (i = 3; i >= x + 1; i--)
                            {
                                MoveOrCombine(i - 1, y, i, y);
                            }
                        }
                    }
                    Debug.Log("Right");
                }
                // Left
                else if (gap.x < 0 && gap.y > -0.5f && gap.y < 0.5f)
                {
                    for (y = 0; y <= 3; y++)
                    {
                        for (x = 3; x >= 1; x--)
                        {
                            for (i = 0; i <= x - 1; i++)
                            {
                                MoveOrCombine(i + 1, y, i, y);
                            }
                        }
                    }
                    Debug.Log("Left");
                }

                else
                {
                    return;
                }

                if (move)
                {
                    //K becomes 0 when all tiles are full
                    move = false;
                    Spawn();
                    k = 0;
                    l = 0;

                    // Score
                    if (score > 0)
                    {
                        Plus.text = "+" + score.ToString() + "    ";
                        Plus.GetComponent <Animator>().SetTrigger("PlusBack");
                        Plus.GetComponent <Animator>().SetTrigger("Plus");
                        Score.text = (int.Parse(Score.text) + score).ToString();
                        if (PlayerPrefs.GetInt("BestScore", 0) < int.Parse(Score.text))
                        {
                            PlayerPrefs.SetInt("BestScore", int.Parse(Score.text));
                        }

                        BestScore.text = PlayerPrefs.GetInt("BestScore").ToString();
                        score          = 0;
                        Debug.Log("Score added");
                    }

                    for (x = 0; x <= 3; x++)
                    {
                        for (y = 0; y <= 3; y++)
                        {
                            //K becomes 0 when all tiles are full
                            if (Square[x, y] == null)
                            {
                                k++; continue;
                            }
                            if (Square[x, y].tag == "Combine")
                            {
                                Square[x, y].tag = "Untagged";
                            }
                        }
                    }

                    if (k == 0)
                    {
                        //If there is no block such as horizontal or vertical, l becomes 0,
                        for (y = 0; y <= 3; y++)
                        {
                            for (x = 0; x <= 2; x++)
                            {
                                if (Square[x, y].name == Square[x + 1, y].name)
                                {
                                    l++;
                                }
                            }
                        }
                        for (x = 0; x <= 3; x++)
                        {
                            for (y = 0; y <= 2; y++)
                            {
                                if (Square[x, y].name == Square[x, y + 1].name)
                                {
                                    l++;
                                }
                            }
                        }
                        if (l == 0)
                        {
                            stop = true; Quit.SetActive(true); return;
                        }
                    }
                }
            }
        }
    }
示例#3
0
    void Update()
    {
        if (stop)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftArrow) == true)
        {
            //Debug.Log("keydown- left");
            for (y = 0; y <= 3; y++)
            {
                for (x = 3; x >= 1; x--)
                {
                    for (i = 0; i <= x - 1; i++)
                    {
                        MoveorCombine(i + 1, y, i, y);
                    }
                }
            }
        }

        else if (Input.GetKeyDown(KeyCode.RightArrow) == true)
        {
            //Debug.Log("keydown- right");
            for (y = 0; y <= 3; y++)
            {
                for (x = 0; x <= 2; x++)
                {
                    for (i = 3; i >= x + 1; i--)
                    {
                        MoveorCombine(i - 1, y, i, y);
                    }
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow) == true)
        {
            // Debug.Log("keydown- up");
            for (x = 0; x <= 3; x++)
            {
                for (y = 0; y <= 2; y++)
                {
                    for (i = 3; i >= y + 1; i--)
                    {
                        MoveorCombine(x, i - 1, x, i);
                    }
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow) == true)
        {
            //Debug.Log("keydown- down");
            for (x = 0; x <= 3; x++)
            {
                for (y = 3; y >= 1; y--)
                {
                    for (i = 0; i <= y - 1; i++)
                    {
                        MoveorCombine(x, i + 1, x, i);
                    }
                }
            }
        }
        else
        {
            return;
        }

        if (move)
        {
            move = false;
            Spawn();
            k = 0;
            l = 0;

            //점수
            if (score > 0)
            {
                Plus.text = "+" + score.ToString() + "    ";
                Plus.GetComponent <Animator>().SetTrigger("PlusBack");
                Plus.GetComponent <Animator>().SetTrigger("Plus");
                Score.text = (int.Parse(Score.text) + score).ToString();
                if (PlayerPrefs.GetInt("BestScore", 0) < int.Parse(Score.text))
                {
                    PlayerPrefs.SetInt("BestScore", int.Parse(Score.text));
                }
                BestScore.text = PlayerPrefs.GetInt("BestScore").ToString();
                score          = 0;
            }

            for (x = 0; x <= 3; x++)
            {
                for (y = 0; y <= 3; y++)
                {
                    if (Square[x, y] == null)
                    {
                        k++; continue;
                    }
                    if (Square[x, y].tag == "Combine")
                    {
                        Square[x, y].tag = "Untagged";
                    }
                }
            }
            if (k == 0)
            {
                for (y = 0; y <= 3; y++)
                {
                    for (x = 0; x <= 2; x++)
                    {
                        if (Square[x, y].name == Square[x + 1, y].name)
                        {
                            l++;
                        }
                    }
                }
                for (x = 0; x <= 3; x++)
                {
                    for (y = 0; y <= 2; y++)
                    {
                        if (Square[x, y].name == Square[x, y + 1].name)
                        {
                            l++;
                        }
                    }
                }
                {
                    stop = true; Quit.SetActive(true); return;
                }
            }
        }
    }