Example #1
0
    // Use this for initialization
    void Start()
    {
        ST_PuzzleDisplay.PuzzleMoves = 0;
        ST_PuzzleDisplay.CanMove     = false;
        ST_PuzzleDisplay.CanCount    = false;
        ST_PuzzleDisplay.Moves.Clear();
        //Texture2D encryptImg = PuzzleImage as Texture2D;
        Instance    = this;
        AudioSource = GetComponent <AudioSource>();

        PuzzleImage = PuzzleImages[UnityEngine.Random.Range(0, PuzzleImages.Length)];
        PuzzleImage = Steganography.Encode(PuzzleImage, PuzzleManager.CurrentHash);

        // create the games puzzle tiles from the provided image.
        CreatePuzzleTiles2();

        // mix up the puzzle.
        //StartCoroutine(JugglePuzzle());
        //SetInitialState(PuzzleManager.PuzzleData.field);

        StartCoroutine(CheckForComplete());
        CanMove  = true;
        CanCount = true;
        LetsgoPopup.EnableFor(1);
        GameTimerUpdater.StartTimer();
    }
Example #2
0
    // new ]
    // REFACTOR 2 ]

    private void SetInitialState(List <int> state)
    {
        int maxIndex = (Height * Width) - 1;

        if (state.Count - 1 == maxIndex)
        {
            Vector3[] positions = new Vector3[maxIndex + 1];

            for (int i = 0; i <= maxIndex; i++)
            {
                var xy           = ConvertIndexToGrid(i);
                var tile         = TileDisplayArray[(int)xy.x, (int)xy.y];
                var tilePosition = tile.GetComponent <ST_PuzzleTile>().TargetPosition;
                positions[i] = new Vector3(tilePosition.x, tilePosition.y, tilePosition.z);
            }

            GameObject[,] newTiles = new GameObject[Width, Height];
            for (int newIndex = 0; newIndex <= maxIndex; newIndex++)
            {
                var oldIndex       = state[newIndex];
                var newCoordinates = ConvertIndexToGrid(newIndex);
                var oldCoordinates = ConvertIndexToGrid(oldIndex);

                if (oldIndex == -1)
                {
                    var oldTile = TileDisplayArray[(int)newCoordinates.x, (int)newCoordinates.y];
                    newTiles[(int)newCoordinates.x, (int)newCoordinates.y] = oldTile;
                    oldTile.GetComponent <ST_PuzzleTile>().Active          = false;
                }
                else
                {
                    var oldTile = TileDisplayArray[(int)oldCoordinates.x, (int)oldCoordinates.y];
                    newTiles[(int)newCoordinates.x, (int)newCoordinates.y] = oldTile;
                    oldTile.GetComponent <ST_PuzzleTile>().GridLocation    = new Vector2(newCoordinates.x, newCoordinates.y);

                    var position = positions[newIndex];
                    oldTile.GetComponent <ST_PuzzleTile>().transform.localPosition = new Vector3(position.x, position.y, position.z);
                    oldTile.GetComponent <ST_PuzzleTile>().TargetPosition          = new Vector3(position.x, position.y, position.z);
                }
            }

            TileDisplayArray = newTiles;

            StartCoroutine(CheckForComplete());
            CanMove  = true;
            CanCount = true;
            LetsgoPopup.EnableFor(1);
            GameTimerUpdater.StartTimer();
            return;
        }
        throw new ArgumentException("The initial state size does not match with puzzle size", nameof(state));
    }
Example #3
0
        protected void Update()
        {
            if (Input.GetKeyUp(KeyCode.F))
            {
                Rotate(RubikFaceType.Front, true);
            }
            if (Input.GetKeyUp(KeyCode.L))
            {
                Rotate(RubikFaceType.Left, false);
            }
            if (Input.GetKeyUp(KeyCode.R))
            {
                Rotate(RubikFaceType.Right, false);
            }
            if (Input.GetKeyUp(KeyCode.T))
            {
                Rotate(RubikFaceType.Top, false);
            }
            if (Input.GetKeyUp(KeyCode.B))
            {
                Rotate(RubikFaceType.Bottom, false);
            }
            if (Input.GetKeyUp(KeyCode.U))
            {
                Rotate(RubikFaceType.Back, false);
            }

            if (_shuffleMode)
            {
                if (_shuffleCounter < _numberOfShuffles && _canMove)
                {
                    var type      = (RubikFaceType)_moveTypes.GetValue(UnityEngine.Random.Range(0, _moveTypes.Length - 1));
                    var clockwise = (UnityEngine.Random.value <= 0.5f);
                    _isShuffling = true;

                    Rotate(type, clockwise, () =>
                    {
                        _shuffleCounter++;
                        _isShuffling = false;
                    });
                }
            }

            if (_shuffleMode && _shuffleCounter >= _numberOfShuffles)
            {
                GameTimerUpdater.StartTimer();
                _shuffleMode = false;
                LetsgoPopup.EnableFor(1);
                ControlsManager.CanMove = true;
            }
        }
Example #4
0
 protected void Awake()
 {
     _audioSource = GetComponent <AudioSource>();
     StartCoroutine(WebServiceManager.GetTopScores((scores) =>
     {
         int index = 0;
         foreach (var topScore in scores)
         {
             LeaderboardManager.Instance.SetEntry(index, topScore.PlayerAddress, topScore.Score);
             index++;
         }
     }));
     Grid = new MatchingGrid((int)Size.x, (int)Size.y, TilePrefabs, Border, Angle, BorderBall, this, ref Image);
     LetsGoPopup.EnableFor(1);
     GameTimerUpdater.StartTimer();
 }
Example #5
0
        private void OnVictory()
        {
            GameTimerUpdater.StopTimer();
            _audioSource.PlayOneShot(OnVictorySound);

            var decryptedText = Steganography.Decode(Image);

            var amount = LocalStorage.GetInt(StorageKeys.DecryptedAmountKey).Value + 1;

            StartCoroutine(WebServiceManager.SetTopScore(ScoreCounter.GetScore(), (score) =>
            {
                Debug.Log("Score correctly pushed: " + score);
            }));

            OnCompletedPopupText.text = "You won 1 Herc token and decrypted\nHerciD: " + amount.ToString("000-000-000");
            OnCompletedPopup.gameObject.SetActive(true);

            LocalStorage.Store(StorageKeys.DecryptedAmountKey, amount);
        }
Example #6
0
    private IEnumerator JugglePuzzle()
    {
        ShufflingPopup.EnableFor(4);
        yield return(new WaitForSeconds(1.0f));

        int tileToHideX = UnityEngine.Random.Range(0, Width);
        int tileToHideY = UnityEngine.Random.Range(0, Height);

        // hide a puzzle tile (one is always missing to allow the puzzle movement).
        TileDisplayArray[tileToHideX, tileToHideY].GetComponent <ST_PuzzleTile>().Active = false;

        yield return(new WaitForSeconds(1.0f));

        int howManyShuffles = UnityEngine.Random.Range(20, 35);

        for (int k = 0; k < howManyShuffles; k++)
        {
            // use random to position each puzzle section in the array delete the number once the space is filled.
            for (int j = 0; j < Height; j++)
            {
                for (int i = 0; i < Width; i++)
                {
                    // attempt to execute a move for this tile.
                    TileDisplayArray[i, j].GetComponent <ST_PuzzleTile>().ExecuteAdditionalMove();

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

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

        yield return(null);

        CanMove  = true;
        CanCount = true;
        LetsgoPopup.EnableFor(1);
        GameTimerUpdater.StartTimer();
    }
Example #7
0
        protected void Update()
        {
            if (Input.GetKeyUp(KeyCode.F))
            {
                Rotate(RubikFaceType.Front, true);
            }
            if (Input.GetKeyUp(KeyCode.L))
            {
                Rotate(RubikFaceType.Left, false);
            }
            if (Input.GetKeyUp(KeyCode.R))
            {
                Rotate(RubikFaceType.Right, false);
            }
            if (Input.GetKeyUp(KeyCode.T))
            {
                Rotate(RubikFaceType.Top, false);
            }
            if (Input.GetKeyUp(KeyCode.B))
            {
                Rotate(RubikFaceType.Bottom, false);
            }
            if (Input.GetKeyUp(KeyCode.U))
            {
                Rotate(RubikFaceType.Back, false);
            }

            // SHUFFLE [

            if (_shuffleMode)
            {
                if (_shuffleCounter < _numberOfShuffles && _canMove)
                {
                    var mv = PuzzleManager.PuzzleData.puzzleField[_shuffleCounter];
//                    var mv = UnityEngine.Random.Range(0, _moveTypes.Length - 1);

                    if (mv >= _moveTypes.Length)
                    {
                        // todo: fix it
                        // error(), but continue because validation on hipr-restful
                        Debug.Log("Incorrect puzzle puzzleId=" + PuzzleManager.PuzzleData.puzzleId + "mv=" + mv);
                        mv = 0;
                    }

                    var type      = (RubikFaceType)_moveTypes.GetValue(mv);
                    var clockwise = (UnityEngine.Random.value <= 0.5f);
                    _isShuffling = true;

                    Rotate(type, clockwise, () =>
                    {
                        _shuffleCounter++;
                        _isShuffling = false;
                    });
                }
            }

            if (_shuffleMode && _shuffleCounter >= _numberOfShuffles)
            {
                GameTimerUpdater.StartTimer();
                _shuffleMode = false;
                LetsgoPopup.EnableFor(1);
                ControlsManager.CanMove = true;
            }

            // SHUFFLE ]
        }
Example #8
0
    // WIN [

    public IEnumerator CheckForComplete()
    {
        yield return(null);

        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)
                    {
                        Complete = false;
                    }
                }
            }

            yield return(null);
        }

        // if we are still complete then all the tiles are correct.
        if (Complete)
        {
            GameTimerUpdater.StopTimer();
            string msg       = Steganography.Decode(PuzzleImage);
            var    scoreTemp = CalculateScore(PuzzleMoves, (int)GameTimerUpdater.ElapsedSeconds);

            WaitingValidationPopup.gameObject.SetActive(true);

            PuzzleManager.ValidatePuzzleResult(PuzzleManager.PuzzleData.puzzleId, scoreTemp, msg, Moves, (isValid) =>
            {
                if (isValid)
                {
                    if (AudioSource == null)
                    {
                        AudioSource = GetComponent <AudioSource>();
                    }
                    AudioSource.PlayOneShot(VictorySound);

                    var score = CalculateScore(PuzzleMoves, (int)GameTimerUpdater.ElapsedSeconds);

                    CompletingText.text = "Nicely done! You scored " + score +
                                          "!\nBe sure to accept the transaction, or your score will not be added in the leaderboard!";

                    WaitingValidationPopup.gameObject.SetActive(false);
                    CompletingPopup.gameObject.SetActive(true);
                }
                else
                {
                    CompletingText.text = "Uhm, it seems you did not decrypted correctly this hash. But you can retry!";

                    CompletingPopup.gameObject.SetActive(true);
                }
            });
        }

        yield return(null);
    }