private static void AddPlayer(string nickname) { try { // Query para insertar un jugador string NonQuery = $"INSERT INTO players(nickname) VALUES('{nickname}');"; Connection_DataBase.ExecuteNonQuery(NonQuery); MessageBox.Show("�Jugador registrado exitosamente!", "ARKANOID", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("�Siga adelante!", "ARKANOID", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception e) { if (e is UnableToConnectException) { MessageBox.Show(e.Message, "Arkanoid", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Ha ocurrido un error...", "ARKANOID", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// Metodo que se encarga para los rebotes de la pelota private void ReboundBall() { if (ball.Bottom > Height) { Timer.Stop(); GameData.GameLives(); MessageBox.Show("Ha perdido..." + "\nCuenta con " + GameData.lives + " vidas restantes"); if (GameData.lives == 0) { MessageBox.Show("Ha perdido...\nFin de la partida"); //Agregar puntaje a la Base de Datos var dt = Connection_DataBase.ExecuteQuery($"SELECT player_id FROM players WHERE nickname = '{GameData.Nickname}'"); if (!dt.ExtendedProperties.Values.Count.Equals(0) && !dt.Rows.Count.Equals(0)) { var dr = dt.Rows[0]; var player_id = Convert.ToInt32(dr[0].ToString()); Connection_DataBase.ExecuteNonQuery($"INSERT INTO scores(player_id, score)" + $" VALUES({player_id}, {GameData.Score})"); } GameData.GameRestart(); onLose?.Invoke(); } LiveCount.Text = "Vidas: " + GameData.lives.ToString(); GameData.GameStarted = false; RepositionElements(); Timer.Start(); } if (ball.Left < 0 || ball.Right > Width) { GameData.dirX = -GameData.dirX; return; } if (ball.Bounds.IntersectsWith(PictureBox.Bounds)) { GameData.dirY = -GameData.dirY; } for (int i = 4; i >= 0; i--) { for (int j = 0; j < 10; j++) { if (ball.Bounds.IntersectsWith(CustomPictureBox[i, j].Bounds) && Controls.Contains(CustomPictureBox[i, j])) { CustomPictureBox[i, j].Hits--; if (CustomPictureBox[i, j].Hits == 0) { Controls.Remove(CustomPictureBox[i, j]); GameData.BrokenBricks++; GameData.Score += (GameData.BrokenBricks * 10) + 100; Score.Text = GameData.Score.ToString(); } GameData.dirY = -GameData.dirY; return; } } } }