// Metodo que verifica si un jugador ya existe o no public static void VerifyPlayer(string nickname) { try { // Query que verifica si ya existe o no un usuario string queryUser = $"SELECT count(*) FROM players WHERE nickname = '{nickname}'"; var dt = Connection_DataBase.ExecuteQuery(queryUser); var dr = dt.Rows[0]; var players = Convert.ToString(dr[0]); if (players == "0") { try { if (MessageBox.Show("Parece que este usuario no esta registrado.\n�Desea registar un nuevo usuario?", "ARKANOID", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { AddPlayer(nickname); } else { MessageBox.Show("No se guardara un registro de la partida a realizar.", "ARKANOID", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { MessageBox.Show("Algo ha ocurrido mal...", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } 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); } } }
private void refreshData() { var dt = Connection_DataBase.ExecuteQuery("SELECT player_id FROM scores ORDER BY score DESC"); var st = Connection_DataBase.ExecuteQuery("SELECT score FROM scores ORDER BY score DESC"); if (dt.Rows.Count > 0) { if (dt.Rows.Count < 10) { for (int i = 0; i < dt.Rows.Count; i++) { // Agregando nicknames al UserControl var dr = dt.Rows[i]; var player_id = dr[0]; var tempDT = Connection_DataBase.ExecuteQuery($"SELECT nickname FROM players " + $"WHERE player_id = {player_id}"); dr = tempDT.Rows[0]; var nickname = dr[0].ToString(); Top10[i, 0] = new Label(); Top10[i, 0].Text = nickname; Top10[i, 0].Font = new Font("Microsoft YaHei", 20F); Top10[i, 0].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 0].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 0], 2, i + 2); // Agregando scores al UserControl dr = st.Rows[i]; var shownScore = dr[0].ToString(); Top10[i, 1] = new Label(); Top10[i, 1].Text = shownScore; Top10[i, 1].Font = new Font("Microsoft YaHei", 20F); Top10[i, 1].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 1].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 1], 4, i + 2); } for (int i = dt.Rows.Count; i < 10; i++) { // Llenando espacios que no se esten ocupando Top10[i, 0] = new Label(); Top10[i, 0].Text = "-----"; Top10[i, 0].Font = new Font("Microsoft YaHei", 16F); Top10[i, 0].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 0].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 0], 2, i + 2); Top10[i, 1] = new Label(); Top10[i, 1].Text = "--------"; Top10[i, 1].Font = new Font("Microsoft YaHei", 16F); Top10[i, 1].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 1].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 1], 4, i + 2); } } else { for (int i = 0; i < 10; i++) { // Agregando nicknames al UserControl var dr = dt.Rows[i]; var player_id = dr[0]; var tempDT = Connection_DataBase.ExecuteQuery($"SELECT nickname FROM players " + $"WHERE player_id = {player_id}"); dr = tempDT.Rows[0]; var nickname = dr[0].ToString(); Top10[i, 0] = new Label(); Top10[i, 0].Text = nickname; Top10[i, 0].Font = new Font("Microsoft YaHei", 20F); Top10[i, 0].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 0].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 0], 2, i + 2); // Agregando scores al UserControl dr = st.Rows[i]; var shownScore = dr[0].ToString(); Top10[i, 1] = new Label(); Top10[i, 1].Text = shownScore; Top10[i, 1].Font = new Font("Microsoft YaHei", 20F); Top10[i, 1].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 1].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 1], 4, i + 2); } } } else { for (int i = 0; i < 10; i++) { Top10[i, 0] = new Label(); Top10[i, 0].Text = "-----"; Top10[i, 0].Font = new Font("Microsoft YaHei", 16F); Top10[i, 0].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 0].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 0], 2, i + 2); Top10[i, 1] = new Label(); Top10[i, 1].Text = "--------"; Top10[i, 1].Font = new Font("Microsoft YaHei", 16F); Top10[i, 1].TextAlign = ContentAlignment.MiddleCenter; Top10[i, 1].Dock = DockStyle.Fill; tableLayoutPanel1.Controls.Add(Top10[i, 1], 4, i + 2); } } }
// 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; } } } }