Ejemplo n.º 1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            Continue = true;
            try
            {
                var name   = txtName.Text;
                var player = txtName.Text;

                if (name.Length == 0)
                {
                    MessageBox.Show("you did not enter the name!", "Name Empty",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    //verificacion con la base de datos por si esta repetido
                    var dt = ConnectionDB.ExecuteQuery("SELECT Name FROM PLAYER ");

                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr[0].ToString().Equals(txtName.Text))
                        {
                            MessageBox.Show("The name already exist", "name repeated",
                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                            Continue = false;
                            break;
                        }
                    }

                    //luego se inicia el juego
                    if (Continue == true)
                    {
                        ConnectionDB.ExecuteNonQuery("INSERT INTO PLAYER(Name) " +
                                                     $"VALUES('{txtName.Text}')");

                        player = txtName.Text;
                        GamePlatform game = new GamePlatform(player);
                        game.Show();
                    }
                    //Para un jugador previamente registrado
                    else
                    {
                        player = txtName.Text;
                        GamePlatform game = new GamePlatform(player);
                        game.Show();
                    }
                }
            }
            catch (Exception exceptionNoInfo)
            {
                MessageBox.Show("An error has ocurred :(");
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var name = txtName.Text;

            if (name.Length == 0)
            {
                MessageBox.Show("you did not enter the name!", "Name Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //verificacion con la base de datos por si esta repetido
                var dt = ConnectionDB.ExecuteQuery("SELECT Name " +
                                                   "FROM PLAYER");

                foreach (DataRow dr in dt.Rows)
                {
                    if (dr[0].ToString().Equals(txtName.Text))
                    {
                        MessageBox.Show("The name already exist", "name repeated",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        Continue = false;
                        break;
                    }
                }

                //luego se inicia el juego
                if (Continue == true)
                {
                    ConnectionDB.ExecuteNonQuery("INSERT INTO PLAYER(Name) " +
                                                 $"VALUES('{txtName.Text}')");
                    Game game = new Game();
                    game.Show();
                    this.Close();
                }
            }
        }
Ejemplo n.º 3
0
        //Function provides ball bounds inside platform
        private void bounceBall()
        {
            try
            {
                if (ball.Bottom > Height)
                {
                    GameData.lifes--;

                    repositionElements();
                    updateItems();

                    GameData.GameStarted = false;
                    GamePlatformTimer_Tick.Start();

                    if (GameData.lifes == 0)
                    {
                        GamePlatformTimer_Tick.Stop();
                        MessageBox.Show("Game over");
                        ConnectionDB.ExecuteNonQuery($"UPDATE PLAYER set score = {GameData.score} " +
                                                     $"where name = '{PlayerName}'");
                        ConnectionDB.ExecuteNonQuery($"INSERT INTO SCOREBOARD(name,score,dategame) " +
                                                     $"VALUES ('{PlayerName}',{GameData.score},NOW())");

                        this.Close();
                    }
                }

                if (ball.Left < 0 || ball.Right > Width)
                {
                    GameData.dirX = -GameData.dirX;
                    return;
                }

                if (ball.Top < 0)
                {
                    GameData.dirY = -GameData.dirY;
                    return;
                }

                if (ball.Bounds.IntersectsWith(picPaddle.Bounds))
                {
                    GameData.dirY = -GameData.dirY;
                }

                for (int i = 4; i >= 0; i--)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (cpb[i, j] != null && ball.Bounds.IntersectsWith(cpb[i, j].Bounds))
                        {
                            cpb[i, j].Hits--;

                            if (cpb[i, j].Hits == 0)
                            {
                                //Calling the function to increase the score
                                GameData.score = GameData.score + 150;
                                Controls.Remove(cpb[i, j]);
                                cpb[i, j] = null;
                            }
                            else if (cpb[i, j].Tag.Equals("blinded"))
                            {
                                cpb[i, j].BackgroundImage = Image.FromFile("../../Textures/Tileblindedbroken.png");
                            }

                            GameData.dirY = -GameData.dirY;

                            score.Text = "Score: " + GameData.score;
                            return;
                        }
                    }
                }
            }
            catch (Exception exceptionBallBounds)
            {
                MessageBox.Show("An error has ocurred with the ball bounds");
            }
        }