/// <summary>
        /// Set the score for this player.
        /// </summary>
        /// <param name="score">The score to set.</param>
#if UNITY_EDITOR
        public static void SetScore(int score)
        {
            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = SetScore: string
            // Value    = {"result": true}
            JavascriptInteractor.ProcessResultGlobal("SetScore#{\"result\": true}");
        }
        /// <summary>
        /// Retrieves the injected Metamask account.
        /// </summary>
        /// <returns>The account address.</returns>
#if UNITY_EDITOR
        public static void GetEndOfSeason()
        {
            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = GetEndOfSeason: string
            // Value    = {"time":1547510399000}: Unix Timestamp (long)
            JavascriptInteractor.ProcessResultGlobal("GetEndOfSeason#{\"time\":1547510399000}");
        }
Example #3
0
        /// <summary>
        /// Retrieves a puzzle hash from the blockchain.
        /// </summary>
#if UNITY_EDITOR
        public static void GetPuzzle(int a, int b)
        {
            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = GetPuzzle: string
            // Value    = {
            //              puzzleId: 1,                    => the puzzleId
            //              field: [0,7,3,4,1,2,6,8,5],     => the initial state of the puzzle
            //              hash: "HashMetricsHere"         => the hash to encode in the puzzle
            //            }: stringified JSON object

            GameType gameType = MetamaskManager._gameType;

            switch (gameType)
            {
            case GameType.SlidingTilePuzzle:
                JavascriptInteractor.ProcessResultGlobal("GetPuzzle#{\"plainTextMetrics\":\"\",\"metricsHash\":\"0xcc0babd1bdc475da63b327ea6e0e2fc5aaa844a2aa6190c8c1263cf6e8e8baa6\",\"params\":{},\"puzzleField\":[1,0,2,4,3,5,6,8,7],\"checkOwner\":true,\"puzzleId\":6}");
                break;

            case GameType.RubicsCube:
                // todo: fix
                JavascriptInteractor.ProcessResultGlobal("GetPuzzle#{\"id\":\"5d52ba1d795e1f7a4cfe5212\",\"plainTextMetrics\":\"\",\"metricsHash\":\"0x586abb2c8e1f4a1c09c9e0330d0afaad2446c165d76d360a214d0fa609f94eb0\",\"params\":{},\"puzzleField\":[1],\"checkOwner\":true,\"puzzleId\":3}");
                break;

            case GameType.MatchingCubes:
                // todo: fix
                JavascriptInteractor.ProcessResultGlobal("GetPuzzle#{\"plainTextMetrics\":\"\",\"metricsHash\":\"0xcc0babd1bdc475da63b327ea6e0e2fc5aaa844a2aa6190c8c1263cf6e8e8baa6\",\"params\":{},\"puzzleField\":[1,0,2,4,3,5,6,8,7],\"checkOwner\":true,\"puzzleId\":6}");
                break;

            case GameType.ColorGameFiveByFive:
                // todo: fix
                JavascriptInteractor.ProcessResultGlobal("GetPuzzle#{\"id\":\"5d53ce96d93e677f9602a0f2\",\"plainTextMetrics\":\"\",\"metricsHash\":\"0xc48688986d7b97ba2f2c7509ff498c63a0129737b41b1cc1e597b92431db4135\",\"params\":{},\"puzzleField\":[3,3],\"checkOwner\":true,\"puzzleId\":13}");
                break;
            }
        }
        /// <summary>
        /// Retrieves a puzzle hash from the blockchain.
        /// </summary>
#if UNITY_EDITOR
        public static void GetPuzzle()
        {
            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = GetPuzzle: string
            // Value    = {
            //              puzzleId: 1,                    => the puzzleId
            //              field: [0,7,3,4,1,2,6,8,5],     => the initial state of the puzzle
            //              hash: "HashMetricsHere"         => the hash to encode in the puzzle
            //            }: stringified JSON object
            JavascriptInteractor.ProcessResultGlobal("GetPuzzle#{\"plainTextMetrics\":\"\",\"metricsHash\":\"0xcc0babd1bdc475da63b327ea6e0e2fc5aaa844a2aa6190c8c1263cf6e8e8baa6\",\"params\":{},\"puzzleField\":[1,0,2,4,3,5,6,8,7],\"checkOwner\":true,\"puzzleId\":6}");
        }
        /// <summary>
        /// Get top scores.
        /// </summary>
        /// <param name="count">The amount of top scores to retrieve.</param>
#if UNITY_EDITOR
        public static void GetTopScores(int count)
        {
            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = GetTopScores: string
            // Value    =   [0xf55f45267258efbfcefb795a688630a26576635e, 9727],
            //              [0xf55f45267258efbfcefb795a688630a26576635e, 4574],
            //              [0xf55f45267258efbfcefb795a688630a26576635e, 15948],
            //              [0xf55f45267258efbfcefb795a688630a26576635e, 9425],
            //              [0x8f96f32db25b2d4fa0787d6e045630caaf2d09f7, 789]
            JavascriptInteractor.ProcessResultGlobal("GetTopScores#[0xf55f45267258efbfcefb795a688630a26576635e, 9727], [0xf55f45267258efbfcefb795a688630a26576635e, 4574], [0xf55f45267258efbfcefb795a688630a26576635e, 15948], [0xf55f45267258efbfcefb795a688630a26576635e, 9425], [0x8f96f32db25b2d4fa0787d6e045630caaf2d09f7, 789]");
        }
        /// <summary>
        /// Pushes the puzzle result to the smart contract for validation.
        /// </summary>
        /// <param name="resultHash">The resulting hash from the puzzle solving.</param>
#if UNITY_EDITOR
        public static void ValidatePuzzleResult(int puzzleId, int score, string resultHash, string movesSet)
        {
            // PARAMS HIPR GAME PASSES TO JAVASCRIPT
            // puzzleId: int        => the ID of the puzzle
            // score: int           => the score
            // resultHash: string   => the decoded
            // movesSet: string     => the set of moves performed by the player to solve the puzzle => [[1, 0], [2, 0], [2, 1], [2, 2]]

            // PARAMS THAT WEB3 JAVASCRIPT HAS TO PASS BACK TO HIPR
            // Key      = ValidatePuzzleResult: string
            // Value    = {"result": true}
            JavascriptInteractor.ProcessResultGlobal("ValidatePuzzle#{\"result\": true}");
        }
Example #7
0
        protected void Awake()
        {
            // Make sure this is only on instance
            if (instance == null)
            {
                instance = this;
            }
            else
            {
                Destroy(gameObject);
                // Leave before anymore code is executed
                return;
            }

            DontDestroyOnLoad(this);
        }