示例#1
0
    // Get KiiCloud Bucket's score data.
    // Need already KiiCloud logined.
    public static int getHighScore()
    {
        if (KiiUser.CurrentUser == null)
        {
            return(0);
        }
        if (cachedHighScore > 0)
        {
            return(cachedHighScore);
        }
        KiiBucket bucket = Kii.Bucket(BUCKET_NAME);
        KiiQuery  query  = new KiiQuery(KiiClause.Equals(USER_KEY, KiiUser.CurrentUser.ID));

        query.SortByDesc(SCORE_KEY);
        query.Limit = 1;

        try {
            KiiQueryResult <KiiObject> result = bucket.Query(query);
            foreach (KiiObject obj in result)
            {
                int score = obj.GetInt(SCORE_KEY, 0);
                cachedHighScore = score;
                return(score);
            }
            Debug.Log("High score fetched");
            return(0);
        } catch (CloudException e) {
            Debug.Log("Failed to fetch high score: " + e.ToString());
            return(0);
        }

        /* Async version
         * bucket.Query(query, (KiiQueryResult<KiiObject> list, Exception e) =>{
         *      if (e != null)
         *      {
         *              Debug.Log ("Failed to fetch high score: " + e.ToString());
         *      } else {
         *              Debug.Log ("High score fetched");
         *              foreach (KiiObject obj in list) {
         *                      int score = obj.GetInt (SCORE_KEY, 0);
         *                      cachedHighScore = score;
         *                      getHighScore = score;
         *                      return;
         *              }
         *      }
         * });
         */
    }
示例#2
0
    public void Cancel()
    {
        Debug.Log("Cancel");
        bool      validate  = true;
        KiiObject obj       = KiiObject.CreateByUri(objUri);
        KiiBucket appBucket = Kii.Bucket("Games");
        String    id        = "";

        try {
            obj.Refresh();
            id = obj.GetString("_id");
        } catch (Exception e) {
            Debug.Log("Fallo refresh id game: " + e);
        }
        KiiQuery query = new KiiQuery(
            KiiClause.And(
                KiiClause.Equals("gameName", gameName.GetComponent <InputField>().text)
                , KiiClause.NotEquals("_id", id)
                )
            );

        appBucket.Count(query, (KiiBucket b, KiiQuery q, int count, Exception e) => {
            if (e != null)
            {
                validate = false;
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                navigationController.GoTo("ALERT_VIEW");
                return;
            }
            if (count > 0)
            {
                validate = false;
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Game name already exist");
                navigationController.GoTo("ALERT_VIEW");
                return;
            }
            if (ValidatedFields() && validate)
            {
                navigationController.Back();
            }
            else
            {
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Invalid inputs.");
                navigationController.GoTo("ALERT_VIEW");
            }
        });
    }
示例#3
0
    void OnEnable()
    {
        if (applicationController.sessionStarted)
        {
            KiiBucket appBucket = Kii.Bucket("Games");
            KiiQuery  query     = new KiiQuery(KiiClause.Equals("_owner", KiiUser.CurrentUser.ID));

            appBucket.Query(query, (KiiQueryResult <KiiObject> result, Exception e) => {
                if (e != null)
                {
                    Debug.Log(e);
                    applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                    navigationController.GoTo("ALERT_VIEW");
                    return;
                }
                foreach (KiiObject obj in result)
                {
                    GameObject gameBoxI;
                    gameBoxI = Instantiate(gameBox);
                    gameBoxI.SetActive(true);
                    gameBoxI.transform.SetParent(container.transform);
                    gameBoxI.transform.localScale = new Vector3(1, 1, 1);
                    gameBoxI.GetComponentsInChildren <Text> () [0].text = obj.GetString("gameName");
                    gameBoxI.GetComponentInChildren <Button>().onClick.AddListener(() => editViewController.GetComponent <EditViewController>().SetUri(obj.Uri));
                    gameBoxI.GetComponentInChildren <Button>().onClick.AddListener(() => navigationController.GoTo("EDIT_VIEW"));
                    //gameBox.GetComponentInChildren<RawImage>().texture = obj["icon"];
                }
                GameObject addGameBut;
                addGameBut = Instantiate(addGameButton);
                addGameBut.SetActive(true);
                addGameBut.transform.SetParent(container.transform);
                addGameBut.transform.localScale = new Vector3(1, 1, 1);
                addGameBut.GetComponentInChildren <Button>().onClick.AddListener(() => NewGame());
            });
        }
    }
示例#4
0
    void llenarPartidas()
    {
        string[] creatorstring = new string[20];
        string[] numberofplayersstring = new string[20];
        string[] puzzlesizestring = new string[20];
        string[] powerupsstring = new string[20];
        string[] goTopicURLstring = new string[20];
        int x = 0;
        //Genera las filas de la lista de partidas disponibles
        // Las columnas estan ya diseñadas.
        KiiQuery query = new KiiQuery(
                  KiiClause.And(
                        KiiClause.Equals(key4, "false"),
                        KiiClause.NotEquals(key9, mystats.idplayer)
                      )
                  );

        // Alternatively, you can also do:
        // Kii.Bucket("myBuckets").Query(null, (...));
        Kii.Bucket("Global").Query(query, (KiiQueryResult<KiiObject> result, Exception e) =>
        {
            float exis = -(200f * 0.0016f);
            float eye = -(200f * 0.0016f) + calculaHuecos;
            GameObject worldObject = Instantiate(WorldMatches, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
            world[0] = worldObject;
            worldObject.transform.parent = scroll.transform;
            worldObject.SetActive(true);
            if (e != null)
            {
                // handle error
                return;
            }
            foreach (KiiObject obj in result)
            {
                numberofplayersstring[x] = (string)obj[key8];
                creatorstring[x] = (string)obj[key9];
                puzzlesizestring[x] = (string)obj[key10];
                powerupsstring[x] = (string)obj[key11];
                goTopicURLstring[x] = (string)obj[key12];
                lista[x] = obj;
                int p = x + 1;
                Debug.Log("Este es el Uri de la partida "+ p +": " + obj.Uri.ToString());
                x++;
            }
            Debug.Log("Partidas disponibles encontradas: " + x);
            listaOld = new GameObject[x];
            for (int y = 0; y < x; y++)
            {

                eye = eye - (100f * 0.0016f);
                GameObject childObject = Instantiate(match, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                childObject.transform.parent = scroll.transform;
                listaOld[y] = childObject;
                if (y == x - 1)
                {
                    calculaHuecos = eye;
                }

            }
            for (int i = 0; i < x; i++)
            {
                GameObject creator = listaOld[i].transform.FindChild("Creator").gameObject;
                GameObject numberofplayers = listaOld[i].transform.FindChild("NumberOfPlayers").gameObject;
                GameObject puzzlesize = listaOld[i].transform.FindChild("PuzzleSize").gameObject;
                GameObject powerups = listaOld[i].transform.FindChild("PowerUps").gameObject;
                GameObject unirse = listaOld[i].transform.FindChild("Check").gameObject;
                GameObject nocheck = listaOld[i].transform.FindChild("SafeCheck").gameObject;
                nocheck.SetActive(false);
                GameObject idJsonPArtidas = listaOld[i].transform.FindChild("jsonID").gameObject;
                GameObject goTopicURL = listaOld[i].transform.FindChild("topicURL").gameObject;
                UILabel creatorlabel = creator.GetComponent<UILabel>();
                UILabel numberofplayerslabel = numberofplayers.GetComponent<UILabel>();
                UILabel puzzlesizelabel = puzzlesize.GetComponent<UILabel>();
                UILabel powerupslabel = powerups.GetComponent<UILabel>();
                UILabel idjonLabel = idJsonPArtidas.GetComponent<UILabel>();
                UILabel topicURLlabel = goTopicURL.GetComponent<UILabel>();
                creatorlabel.text = "" + creatorstring[i] + "";
                numberofplayerslabel.text = "" + numberofplayersstring[i] + "";
                puzzlesizelabel.text = "" + puzzlesizestring[i] + "";
                powerupslabel.text = "" + powerupsstring[i] + "";
                idjonLabel.text = "" + lista[i].Uri.ToString() + "";
                topicURLlabel.text = "" + lista[i][key12] + "";
            }
        });
        /*if (callBack.take1.Count < 2)
        {
            notfound.SetActive(true);
        }
        else
        {
            float exis = -(200f * 0.0016f);
            float eye = -(200f * 0.0016f) + calculaHuecos;
            lista = new GameObject[callBack.take1.Count];
            for (int x = 0; x < callBack.take1.Count + 1; x++)
            {
                if (x == 0)
                {
                    GameObject worldObject = Instantiate(WorldMatches, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                    world[0] = worldObject;
                    worldObject.transform.parent = scroll.transform;
                    worldObject.SetActive(true);
                }
                else
                {
                    eye = eye - (100f * 0.0016f);
                    GameObject childObject = Instantiate(match, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                    childObject.transform.parent = scroll.transform;
                    lista[x - 1] = childObject;
                    if (x == callBack.take1.Count - 1)
                    {
                        calculaHuecos = eye;
                    }
                }
            }
            for (int i = 0; i < callBack.take1.Count; i++)
            {
                GameObject creator = lista[i].transform.FindChild("Creator").gameObject;
                GameObject numberofplayers = lista[i].transform.FindChild("NumberOfPlayers").gameObject;
                GameObject puzzlesize = lista[i].transform.FindChild("PuzzleSize").gameObject;
                GameObject powerups = lista[i].transform.FindChild("PowerUps").gameObject;
                GameObject unirse = lista[i].transform.FindChild("Check").gameObject;
                GameObject idJsonPArtidas = lista[i].transform.FindChild("jsonID").gameObject;
                UILabel creatorlabel = creator.GetComponent<UILabel>();
                UILabel numberofplayerslabel = numberofplayers.GetComponent<UILabel>();
                UILabel puzzlesizelabel = puzzlesize.GetComponent<UILabel>();
                UILabel powerupslabel = powerups.GetComponent<UILabel>();
                UILabel idjonLabel = idJsonPArtidas.GetComponent<UILabel>();
                jsonObj = callBack.take1[i].GetJsonDoc();
                string creatorstring = getinfo.sacarinfo(key9, jsonObj);
                string numberofplayersstring = getinfo.sacarinfo(key8, jsonObj);
                string puzzlesizestring = getinfo.sacarinfo(key10, jsonObj);
                string powerupsstring = getinfo.sacarinfo(key11, jsonObj);
                string jsonId = callBack.take1[i].GetDocId();
                creatorlabel.text = "" + creatorstring + "";
                Debug.Log(creatorstring);
                numberofplayerslabel.text = "" + numberofplayersstring + "";
                puzzlesizelabel.text = "" + puzzlesizestring + "";
                powerupslabel.text = "" + powerupsstring + "";
                idjonLabel.text = "" + jsonId + "";
            }
        }
        searching.text = "";
        }*/
        searching.text = "";
    }
示例#5
0
    public void joinmatch()
    {
        searching.text = "Joining match...";
        /*
        UIButton linea = UIButton.current;
        GameObject lin = linea.gameObject;
        GameObject padre = lin.transform.parent.gameObject;
        GameObject enemyhijo = padre.transform.FindChild("Creator").gameObject;
        GameObject idhijo = padre.transform.FindChild("jsonID").gameObject;
        UILabel enemyLabel = enemyhijo.GetComponent<UILabel>();
        UILabel idLabel = idhijo.GetComponent<UILabel>();
        string enemyString = enemyLabel.text;
        string idString = idLabel.text;
        mystats.idplayer2 = enemyString;
        mystats.idjson = idString;
        */
        // Prepare the target bucket to be queried
        KiiBucket bucket = KiiUser.CurrentUser.Bucket(mystats.idplayer + "SaveGames");

        // Define query conditions
        KiiQuery query = new KiiQuery(
          KiiClause.Equals(gamekey2, mystats.yourIdJson)
        );

        // Query the bucket
        bucket.Query(query, (KiiQueryResult<KiiObject> result, Exception e) =>
        {
            if (e != null)
            {
                Debug.LogError("Error: " + e.ToString());
                // handle error
                return;
            }
            foreach (KiiObject obj in result)
            {
                Debug.Log("ARCHIVO SAVEGAME ENCONTRADO.");
                /*
                Dictionary<string, object> jsonDoc = new Dictionary<string, object>();
                jsonObj = savedGames.take1[0].GetJsonDoc();
                */
                mystats.idjson = (string) obj[gamekey1];
                mystats.yourIdJson = (string) obj[gamekey2];
                mystats.oponente = (string) obj[gamekey54];
                for (int x = 1; x < 17; x++)
                {
                    string temp = "casilla" + x;
                    mystats.puzzles.pieces[x - 1] = bool.Parse((string) obj["casilla"+x]);
                }
                for (int y = 1; y < 5; y++)
                {
                    for (int z = 0; z < 2; z++)
                    {
                        if (z == 0)
                        {
                            mystats.puzzles.drawer[y - 1, z] = float.Parse((string) obj["cajon" + y]);
                        }
                        if (z == 1)
                        {
                            mystats.puzzles.drawer[y - 1, z] = float.Parse((string) obj["rotcajon"+y]);
                        }
                    }
                }
                mystats.puzzles.cpiece[0] = float.Parse((string) obj[gamekey23]);
                mystats.puzzles.npiece[0] = float.Parse((string) obj[gamekey24]);
                mystats.puzzles.cpiece[1] = float.Parse((string) obj[gamekey45]);
                mystats.puzzles.npiece[1] = float.Parse((string) obj[gamekey46]);
                for (int t = 1; t < 17; t++)
                {
                    mystats.puzzles.deck[t - 1] = int.Parse((string) obj["deck"+t]);
                }
                mystats.jugador = (string) obj[gamekey47];
                mystats.puzzles.t = int.Parse((string) obj[gamekey48]);
                mystats.puzzles.r = int.Parse((string) obj[gamekey49]);
                mystats.puzzles.maxDeckValue = int.Parse((string) obj[gamekey50]);
                mystats.puzzles.puzzleID = int.Parse((string) obj[gamekey51]);
                mystats.puzzles.myprogress = int.Parse((string) obj[gamekey52]);
                mystats.puzzles.myoppprogress = int.Parse((string) obj[gamekey53]);
                mystats.aQuienLeTOCA = (string)obj[gamekey56];
                mystats.alreadyBegun = true;
                StartCoroutine(join());
            }
        });
    }
示例#6
0
    public void buscar()
    {
        //Busca una partida vacia
        // Prepare the target bucket to be queried
        KiiBucket bucket = Kii.Bucket("Global");

        // Define query conditions
        KiiQuery query = new KiiQuery(
            KiiClause.Equals("Full","True")
        );

        // Fine-tune your query results
        query.Limit = 1;

        // Query the bucket
        bucket.Query(query, (KiiQueryResult<KiiObject> result, Exception e) =>
        {
            if (e != null)
            {
                Debug.LogError("Query Object failed: " + e.ToString());
                // handle error
                return;
            }
            foreach (KiiObject obj in result)
            {
                obj.GetUri(objectUri);
                Debug.Log("Uri del objeto: " + objectUri);
                string turno = (string)obj[key2];
                string turnoplayer = (string)obj[key3];
                string idjugador1 = (string)obj[key9];

                //Updating match information.
                KiiObject obj2 = KiiObject.CreateByUri(new Uri(objectUri));
                obj2.Refresh((KiiObject obj3, Exception e2) =>
                {
                    if (e2 != null)
                    {
                        Debug.LogError("Retreving Object failed: " + e2.ToString());
                        // handle error
                        return;
                    }
                    //Update following information
                    value1 = round.ToString();
                    value2 = turno;
                    value3 = turnoplayer;
                    value4 = full;
                    value5 = mystats.idplayer;
                    value9 = idjugador1;

                    obj3[key1] = value1;
                    obj3[key2] = value2;
                    obj3[key3] = value3;
                    obj3[key4] = value4;
                    obj3[key5] = value5;
                    obj3[key6] = value6;
                    obj3[key7] = value7;
                    obj3[key8] = value8;
                    obj3[key9] = value9;
                    obj3[key10] = value10;
                    obj3[key11] = value11;
                    obj3.SaveAllFields(false, (KiiObject updatedObj, Exception e3) =>
                    {
                        if (e3 != null)
                        {
                            Debug.LogError("Update Object failed: " + e3.ToString());
                            // handle error
                        }
                        else
                        {
                            //TENEMOS QUE SEGUIR AQUI: IMPLEMENTAR KII TOPICS
                            mystats.idplayer2 = key9;
                            Debug.Log("Match information upadted successfully.");
                        }
                    });
                });
            }
        });
        /*
        storageService = sp.BuildStorageService();
        storageService.FindDocumentByKeyValue(dbName, collectionName, key4, validador, callBack);
        nomatch = 0;
        check = true;
        */
    }