Ejemplo n.º 1
0
 private void OnMouseDrag()
 {
     if ((PuzzleZone.GetInstance().GetState() == EGameState.eOnGame) && (PuzzleZone.GetInstance().m_bRotatable))
     {
         if (m_bRotated == false)
         {
             m_pressedTime += 10 * Time.deltaTime;
             if (m_pressedTime > 4)
             {
                 // lerp towards our target.
                 PuzzleZone.GetInstance().AudioPlayPuzzleSpin();
                 float adjustedAngle = (float)Math.Round(transform.localEulerAngles.y);
                 //.Log(adjustedAngle);
                 TargetAngle = Quaternion.Euler(transform.localEulerAngles.x, adjustedAngle + 90.000f, transform.localEulerAngles.z);
                 StartCoroutine(UpdateRotation(8.0f));
                 m_bRotated = true;
             }
         }
     }
 }
Ejemplo n.º 2
0
 void OnMouseUp()//OnMouseDown()
 {
     //Debug.Log(m_pressedTime);
     if ((PuzzleZone.GetInstance().GetState() == EGameState.eOnGame))
     {
         if (m_bRotated == true)
         {
             m_bRotated = false;
         }
         else
         {
             if (this.transform.parent.GetComponent <ST_PuzzleDisplay>().CanPuzzleMove(this.GetComponent <ST_PuzzleTile>()))
             {
                 PuzzleZone.GetInstance().AudioPlayPuzzleMove();
                 PuzzleZone.GetInstance().IncreaseMoveCount();                     // 이동 횟수 증가
                 // get the puzzle display and return the new target location from this tile.
                 LaunchPositionCoroutine(this.transform.parent.GetComponent <ST_PuzzleDisplay>().GetTargetLocation(this.GetComponent <ST_PuzzleTile>()), 10.0f);
             }
         }
         m_pressedTime = 0;
     }
 }
Ejemplo n.º 3
0
    public IEnumerator CheckForEnd()
    {
        while (Complete == false)
        {
            // iterate over all the tiles and check if they are in the correct position.
            Complete = true;
            for (int j = Height - 1; j >= 0; j--)
            {
                for (int i = 0; i < Width; i++)
                {
                    // check if this tile has the correct grid display location.
                    if ((TileDisplayArray[i, j].GetComponent <ST_PuzzleTile>().CorrectLocation == false) ||
                        (TileDisplayArray[i, j].GetComponent <ST_PuzzleTile>().IsCorrectRotation() == false))
                    {
                        Complete = false;
                        break;
                    }
                }
            }

            yield return(null);
        }

        // if we are still complete then all the tiles are correct.
        if (Complete)
        {
            Debug.Log("Puzzle Complete!");
            // 퍼즐 상태 완료 전환
            PuzzleZone.GetInstance().SetState(EGameState.eComplete);

            TileDisplayArray[0, 0].GetComponent <Renderer>().enabled = true;
        }
        //

        yield return(null);
    }
Ejemplo n.º 4
0
    private IEnumerator JugglePuzzle()
    {
        /*
         * 좌측하단 퍼즐 페이드아웃
         * 나머지 퍼즐 사라진 후 즉시 섞인상태로 등장
         */
        yield return(new WaitForSeconds(2.0f));

        // 퍼즐을 0,0 기준으로부터 랜덤하게 빈공간을 채워넣는다.
        // 0,0 위치와 인접한 퍼즐들의 객체에 접급한다.

        for (int i = 0; i < ShuffleComplexity; i++)
        {
            List <Vector2Int> moveList = new List <Vector2Int>();
            //현재 빈공간의 인접한 방향에 대해
            for (int d = 0; d < 4; d++) // 동/서/남/북 검사
            {
                //단, 이전 빈공간위치가 아닌 인접한 퍼즐에 대해
                Vector2Int checkPos = new Vector2Int(BlankPosition.x + Dir[d, 0], BlankPosition.y + Dir[d, 1]);
                if (checkPos.x >= 0 && checkPos.x < Width && checkPos.y >= 0 && checkPos.y < Height && PrevBlankPosition != checkPos)
                {
                    moveList.Add(checkPos);
                    Debug.Log("chk: " + checkPos.x + "," + checkPos);
                }
            }

            int r = Random.Range(0, moveList.Count);

            Vector2Int next = moveList[r];

            //선택한 퍼즐을 빈 공간으로 위치시킨다.(swap 함수구현) ex) value<1,0>.position = <0,0>
            SwapPuzzle(BlankPosition, next);   // next 위치의 퍼즐과 자리를 바꾼다.

            //전빈공간 위치 갱신
            PrevBlankPosition = BlankPosition;

            //빈공간 위치 갱신
            BlankPosition = next;
        }

        //섞인 위치로 실제 퍼즐을 이동시킨다.
        for (int j = 0; j < Height; j++)
        {
            for (int i = 0; i < Width; i++)
            {
                int start_grid_x = SuffledTilePosition[i, j].x;
                int start_grid_y = SuffledTilePosition[i, j].y;                                                                             //1,0 -> 0,0

                TileDisplayArray[start_grid_x, start_grid_y].GetComponent <ST_PuzzleTile>().GridLocation = new Vector2(i, j);               // Tile 의 grid 포지션 갱신
                TileDisplayArray[start_grid_x, start_grid_y].GetComponent <ST_PuzzleTile>().MoveToTarget(GridToPosMap[i, j], shuffleSpeed); // targetTile의 position으로 이동시킴

                /****************************
                **** 회전 가능한 스테이질 경우****
                ****************************/
                if (PuzzleZone.GetInstance().m_bRotatable&& (start_grid_x != 0 || start_grid_y != 0))
                {
                    int r = Random.Range(0, 4);
                    TileDisplayArray[start_grid_x, start_grid_y].GetComponent <ST_PuzzleTile>().RotateToTarget(90.0000f * r, 10.0f);
                }

                yield return(new WaitForSeconds(0.1f));
            }
        }


        // continually check for the correct answer.
        StartCoroutine(CheckForEnd());

        yield return(null);
    }