public List <HiScores> Post([FromBody] JogoArgs j)
 {
     if (j.nomejogador != null)
     {
         List <HiScores> mj = RepositorioHiScoresdbContext.MelhoresJogos(j.n, j.nomejogador);
         return(mj);
     }
     else
     {
         List <HiScores> mjtodos = RepositorioHiScoresdbContext.GetTop(j.n);
         return(mjtodos);
     }
 }
        public IActionResult HiScores()
        {
            List <HiScores> melhoresJogos = RepositorioHiScoresdbContext.GetTop(10);

            return(View(melhoresJogos));
        }
        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));
            }
        }