private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int id = (int)dataGridView1.CurrentRow.Cells[0].Value; RepositorioJogos repositorio = new RepositorioJogos(); Jogo jogo = repositorio.ObterPeloId(id); AlterarCadastroJogos alterarCadastroJogos = new AlterarCadastroJogos(jogo); alterarCadastroJogos.ShowDialog(); }
private void btnDeletar_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count <= 0) { MessageBox.Show("Selecione uma linha para deletar"); } else { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); DialogResult result = MessageBox.Show("Deseja mesmo Deletar?", "AVISO", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { RepositorioJogos repositorio = new RepositorioJogos(); repositorio.DeletarPeloId(id); AtualizarTabela(); } } }
private void AtualizarTabela() { RepositorioJogos repositorio = new RepositorioJogos(); List <Jogo> listaJogos = repositorio.ObterTodos(); dataGridView1.Rows.Clear(); for (int i = 0; i < listaJogos.Count; i++) { Jogo jogo = listaJogos[i]; string jaLancou = "Sim"; if (jogo.DataLancamento > DateTime.Now) { jaLancou = "Não"; } string precoTexto = $"R$ {jogo.Preco}"; dataGridView1.Rows.Add(new object[] { jogo.ID, jogo.Nome, precoTexto, jogo.Classificacao, jogo.Genero, jaLancou }); } }
private void btnCadastrar_Click(object sender, EventArgs e) { Jogo jogo = new Jogo(); if (txtNome.Text.Length < 2) { MessageBox.Show("Por favor, registre o nome do jogo"); txtNome.Focus(); return; } jogo.Nome = txtNome.Text; if (cbGenero.SelectedIndex == -1) { MessageBox.Show("Por favor, selecione um genero"); cbGenero.DroppedDown = true; return; } jogo.Genero = cbGenero.Text; try { jogo.Preco = Convert.ToDecimal(txtPreco.Text); if (jogo.Preco < 0) { MessageBox.Show("Somente números numeros iguais ou maior que 0"); txtPreco.Focus(); return; } } catch (Exception) { MessageBox.Show("Somente números"); txtPreco.Focus(); return; } if (cbClassificacao.SelectedIndex == -1) { MessageBox.Show("Escolha uma classificação"); cbClassificacao.DroppedDown = true; return; } jogo.Classificacao = cbClassificacao.Text; try { jogo.qtdEstoque = Convert.ToInt32(txtEstoque.Text); if (jogo.qtdEstoque < 0) { MessageBox.Show("A quantidade precisa ser maior que 0"); txtEstoque.Focus(); return; } } catch (Exception) { MessageBox.Show("Somente números!"); txtEstoque.Focus(); return; } jogo.DataLancamento = dtpDataLancamento.Value; RepositorioJogos repositorio = new RepositorioJogos(); repositorio.InserirRegistro(jogo); }
public async Task <IActionResult> CriarJogo(NovoJogo j) { if (ModelState.IsValid) { Jogo JogoNovo = new Jogo(j.Nome, j.PerfilTipo, j.Autonomo); List <RoundSummary> rsList = new List <RoundSummary>(); HttpClient client = NewGameHttpClient.Client; string path = "/api/NewGame"; NovoJogoApiRequest req = new NovoJogoApiRequest(j.Nome, j.PerfilTipo); string json = JsonConvert.SerializeObject(req); 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); JogoNovo.AtualizarJogo(gs); RepositorioJogos.AdicionarJogo(JogoNovo); if (JogoNovo.Autonomo == false) { return(View("JogoIniciado", JogoNovo)); } // SE FOR AUTONOMO fazer o ciclo while else { while (gs.RoundNumber < JogoNovo.Rondas && (JogoNovo.Terminado == false)) { HttpClient clientAuton = NewGameHttpClient.Client; path = "/api/Play"; AtualizarJogoApiRequest ajAuton = new AtualizarJogoApiRequest(JogoNovo.GameID, JogoNovo.TomarAccao); json = JsonConvert.SerializeObject(ajAuton); request = new HttpRequestMessage(HttpMethod.Post, path); request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); response = await clientAuton.SendAsync(request); if (!response.IsSuccessStatusCode) { return(Redirect("/")); } json_r = await response.Content.ReadAsStringAsync(); gs = JsonConvert.DeserializeObject <GameStateApi>(json_r); JogoNovo.AtualizarJogo(gs); RoundSummary rs = new RoundSummary(JogoNovo); rsList.Add(rs); //RoundSummary rs = new RoundSummary(JogoNovo, gs.RoundNumber); //RepositorioRondas.AdicionarRonda(rs); } if (gs.RoundNumber == JogoNovo.Rondas) { client = NewGameHttpClient.Client; path = "/api/Play"; AtualizarJogoApiRequest aja = new AtualizarJogoApiRequest(JogoNovo.GameID, PlayerAction.Quit); json = JsonConvert.SerializeObject(aja); request = new HttpRequestMessage(HttpMethod.Post, path); request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { return(Redirect("/")); } json_r = await response.Content.ReadAsStringAsync(); gs = JsonConvert.DeserializeObject <GameStateApi>(json_r); JogoNovo.CalcularBonus(); JogoNovo.Desistiu = true; JogoNovo.ResultadoJogo = ResultadoJogo.Desistiu; JogoNovo.Terminado = true; } RondaFinal rf = new RondaFinal(JogoNovo); rf.rsList = rsList; return(View("DadosJogoAutonomo", rf)); } } else { return(View()); } }
public IActionResult DadosJogo(int gameid) { Jogo JogoAtual = RepositorioJogos.GetJogo(gameid); return(View("DadosJogo", JogoAtual)); }
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)); } }