IEnumerator GetText()
    {
        UnityWebRequest www = UnityWebRequest.Get("https://hiscore-keeper-server.herokuapp.com/scores");

        yield return(www.Send());

        if (www.isError)
        {
            Debug.Log(www.error);
        }
        else
        {
            HiScores myObject = JsonUtility.FromJson <HiScores>(www.downloadHandler.text);

            if (HiScoreAnimator != null)
            {
                HiScoreAnimator.SetTrigger("DataLoaded");
            }

            for (int i = 0; i < myObject.scores.Length; i++)
            {
                GameObject item   = (GameObject)GameObject.Instantiate(HiScoreTextPrefab, HiScoreUIParent);
                var        height = ((RectTransform)(item.transform)).rect.height;
                item.transform.localPosition    = new Vector3(10.0f, -10.0f - i * height, 0);
                item.transform.localScale       = new Vector3(1, 1, 1);
                item.GetComponent <Text>().text = myObject.scores[i].name;
                item.transform.GetChild(0).GetComponent <Text>().text = myObject.scores[i].value.ToString();
            }
        }
    }
 private void MountHiscoreScreen(string returnString)
 {
     Debug.Log("list: " + returnString);
     if (returnString.IndexOf("error") >= 0)
     {
         var srvError = JsonUtility.FromJson <ServerError>(returnString);
         Debug.Log(srvError.error);
     }
     else
     {
         HiScores EveryHiScore = JsonUtility.FromJson <HiScores>(returnString);
         if (EveryHiScore != null)
         {
             var TopTen = EveryHiScore.scores.OrderBy(score => score.top_score).Take(10).ToList <UserData>();
             for (int countPlayer = 0; countPlayer < TopTen.Count; countPlayer++)
             {
                 components[countPlayer + 1].DisplayValue(TopTen[countPlayer]);
             }
             for (int countEmpty = TopTen.Count; countEmpty < 10; countEmpty++)
             {
                 components[countEmpty + 1].Disable();
             }
         }
     }
 }
예제 #3
0
    IEnumerator GetText()
    {
        UnityWebRequest www = UnityWebRequest.Get("localhost:5000/scores");         //"https://highscore-server-tuure.herokuapp.com/"

        yield return(www.Send());

        if (www.isError)
        {
            Debug.Log(www.error);
        }
        else
        {
            // Show results as text
            Debug.Log(www.downloadHandler.text);
            HiScores hs = JsonUtility.FromJson <HiScores> (www.downloadHandler.text);

            Debug.Log(hs.scores.Length);
            foreach (HiScore h in hs.scores)
            {
                Debug.Log("name is " + h.name);
                Debug.Log("score is " + h.score);
            }

            // Or retrieve results as binary data
            byte[] results = www.downloadHandler.data;
        }
    }
예제 #4
0
 private void LoadHiScores()
 {
     hiScores = new HiScores();
     if (PlayerPrefs.HasKey("hiScore"))
     {
         hiScores.HiScore = PlayerPrefs.GetInt("hiScore");
     }
 }
            //====== public methods

            public HiScores ToHiScoresList()
            {
                var result = new HiScores(Capacity);

                List.ForEach(x => result.TryAdd(x.ToHiScoresEntry()));

                return(result);
            }
예제 #6
0
    // Start is called before the first frame update
    void Start()
    {
        _inst = this;

        Player[] allCharacters = GetComponentsInChildren <Player>();

        foreach (Player player in allCharacters)
        {
            m_playersMap[player.m_playerID] = player;
            m_playersList.Add(player);
        }

        if (m_hiScoreScreen != null)
        {
            m_hiScores = m_hiScoreScreen.GetComponentInChildren <HiScores>();
        }

        ChangeState(GAME_STATE.INIT);
    }
예제 #7
0
        public async Task <IActionResult> AccaoJogo(int gameid, PlayerAction action)
        {
            Jogo     JogoAtual  = RepositorioJogos.GetJogo(gameid);
            HiScores ScoreAtual = RepositorioHiScoresdbContext.GetScore(gameid);

            if (action != PlayerAction.Quit)
            {
                HttpClient client = NewGameHttpClient.Client;
                string     path   = "/api/Play";

                AtualizarJogoApiRequest aj = new AtualizarJogoApiRequest(gameid, action);
                string json = JsonConvert.SerializeObject(aj);

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, path);
                request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    return(Redirect("/"));
                }

                string json_r = await response.Content.ReadAsStringAsync();

                GameStateApi gs = JsonConvert.DeserializeObject <GameStateApi>(json_r);

                JogoAtual.AtualizarJogo(gs);
            }
            else
            {
                HttpClient client = NewGameHttpClient.Client;
                string     path   = "/api/Play";

                AtualizarJogoApiRequest aj = new AtualizarJogoApiRequest(gameid, action);
                string json = JsonConvert.SerializeObject(aj);

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, path);
                request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    return(Redirect("/"));
                }

                string json_r = await response.Content.ReadAsStringAsync();

                GameStateApi gs = JsonConvert.DeserializeObject <GameStateApi>(json_r);



                JogoAtual.MensagemAccao = "Desististe do Jogo";
                JogoAtual.CalcularBonus();
                JogoAtual.Desistiu      = true;
                JogoAtual.ResultadoJogo = ResultadoJogo.Desistiu;
                JogoAtual.Terminado     = true;
            }

            if (JogoAtual.Terminado && JogoAtual.Autonomo == false)
            {
                HiScores NovoScore = new HiScores();
                NovoScore.AtualizarScores(JogoAtual);
                RepositorioHiScoresdbContext.AdicionarScore(NovoScore);
            }
            if (JogoAtual.Autonomo == false)
            {
                return(View("JogoIniciado", JogoAtual));
            }
            else
            {
                return(View("JogoIniciadoAutonomo", JogoAtual));
            }
        }