Example #1
0
        private void zalogujBTN_Click(object sender, EventArgs e)
        {
            string login = loginTB.Text;
            string haslo = hasloTB.Text;

            SqlConnection cnn = new SqlConnection(@"Server=DESKTOP-2I2V4OF;
                                                             Database=DatabaseApp;
                                                             Trusted_Connection=True;");

            cnn.Open();
            //zlicz ilość wystąpień danego rekordu jeśli login i hasło są takie jak wpisał użytkownik
            String     sql     = "select count(*) from users where login ='******' and password ='******'";
            SqlCommand command = new SqlCommand(sql, cnn);

            int sqlIle = (int)command.ExecuteScalar();

            if (sqlIle > 0)//umożliwienie zalogowania się jeśli ilość zliczonych rekordów jest większa od zera
            {
                UserMain um = new UserMain(login);
                um.Show();
                logowanieInfoLBL.Text = "";
                this.Visible          = false;
            }
            else
            {
                logowanieInfoLBL.Text      = "Błędne dane logowania";
                logowanieInfoLBL.BackColor = Color.IndianRed;
            }
            cnn.Close();
        }
Example #2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            scoreLBL.Text = "Wynik: " + score.ToString();

            //sterowanie
            if (goLeft)
            {
                tank.Left -= tankSpeed;
            }
            if (goRight)
            {
                tank.Left += tankSpeed;
            }

            //animacja lecących pocisków
            foreach (Control bullet in this.Controls)
            {
                if (bullet is PictureBox && (string)bullet.Tag == "bullet")
                {
                    bullet.Top -= 20;
                }
                if (bullet.Top < this.Height - 495)
                {
                    this.Controls.Remove(bullet);
                }
            }

            //zdarzenie gry czołg zetknie się z potworem
            foreach (Control tank in this.Controls)
            {
                foreach (Control monster in this.Controls)
                {
                    if (tank is PictureBox && (string)tank.Tag == "tank")
                    {
                        if (monster is PictureBox && (string)monster.Tag == "monster")
                        {
                            if (monster.Bounds.IntersectsWith(tank.Bounds))
                            {
                                timer.Stop();
                                MessageBox.Show("Potwory są zbyt blisko ciebie. \n" +
                                                "Zdobyłeś " + score + " puntków.", "Koniec gry");
                                SqlConnection cnn = new SqlConnection(@"Server=DESKTOP-2I2V4OF;
                                                             Database=DatabaseApp;
                                                             Trusted_Connection=True;");
                                cnn.Open();
                                String     sql     = "update users set score = score + @addScore where login = +'" + loginTB.Text + "'";
                                SqlCommand command = new SqlCommand(sql, cnn);
                                command.Parameters.AddWithValue("addScore", score);
                                command.ExecuteNonQuery();
                                cnn.Close();

                                UserMain um = new UserMain(loginTB.Text);
                                um.Show();
                                this.Close();
                            }
                        }
                    }
                }
            }

            //zdarzenie gdy pocisk trafi potwora
            foreach (Control bullet in this.Controls)
            {
                foreach (Control monster in this.Controls)
                {
                    if (bullet is PictureBox && (string)bullet.Tag == "bullet")
                    {
                        if (monster is PictureBox && (string)monster.Tag == "monster")
                        {
                            if (bullet.Bounds.IntersectsWith(monster.Bounds))
                            {
                                score++;
                                this.Controls.Remove(bullet);
                                this.Controls.Remove(monster);
                                makeMonster();
                                if (score > 5)
                                {
                                    makeMonster();
                                    tankSpeed = 7;
                                }
                                if (score > 35)
                                {
                                    tankSpeed = 10;
                                }
                            }
                        }
                    }
                }
            }

            //zdarzenie gdy czołg wyjedzie poza plansze
            if (tank.Location.X > 858 || tank.Location.X < -40)
            {
                timer.Stop();
                DialogResult result = MessageBox.Show("Grasz dalej?", "Nie uciekaj z placu boju!", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    this.Hide();
                    Shooter s = new Shooter(loginTB.Text);
                    s.Show();
                }
                else
                {
                    this.Hide();
                    UserMain um = new UserMain(loginTB.Text);
                    um.Show();
                }
            }
        }
Example #3
0
        int countBox = 0; //ilość obiektów która spadła z mapy
        private void timer_Tick(object sender, EventArgs e)
        {
            scoreLBL.Text = score.ToString();
            //mechanizm poruszania się
            if (goLeft)
            {
                player.Left = player.Left - 5;
            }
            if (goRight)
            {
                player.Left = player.Left + 5;
            }
            if (goUp)
            {
                player.Top = player.Top - 5;
            }
            if (goDown)
            {
                player.Top = player.Top + 5;
            }
            foreach (Control x in this.Controls)
            {
                if (x is PictureBox && (string)x.Tag == "box1" || (string)x.Tag == "box2" || (string)x.Tag == "box3")
                {
                    if (player.Bounds.IntersectsWith(x.Bounds)) //jeśli gracz wpadnie w spadający obiekt
                    {
                        timer.Stop();
                        MessageBox.Show("Zdobyłeś " + score + " punktów", "Gratulacje");
                        SqlConnection cnn = new SqlConnection(@"Server=DESKTOP-2I2V4OF;
                                                             Database=DatabaseApp;
                                                             Trusted_Connection=True;");
                        cnn.Open();
                        String     sql     = "update users set score = score + @addScore where login = +'" + loginTB.Text + "'";
                        SqlCommand command = new SqlCommand(sql, cnn);
                        command.Parameters.AddWithValue("addScore", scoreLBL.Text);
                        command.ExecuteNonQuery();
                        cnn.Close();

                        UserMain um = new UserMain(loginTB.Text);
                        um.Show();
                        this.Close();
                    }
                }
                if (x is PictureBox && (string)x.Tag == "box1")
                {                             //operacje na pierwszym spadającym obiekcie
                    x.Top = x.Top + boxSpeed; //spadanie obiektu
                    if (x.Top - x.Height > 500)
                    {                         //po spadnęciu ponownie pojawia się u góry w losowym miejscu
                        x.Top  = this.ClientSize.Width - rand.Next(500, 600);
                        x.Left = this.ClientSize.Width - rand.Next(20, 480);
                        countBox++;
                        score++;
                    }
                }
                if (x is PictureBox && (string)x.Tag == "box2" && countBox > 2)
                {//pojawienie się kolejnego obiektu
                    pictureBox2.Visible = true;
                    x.Top = x.Top + boxSpeed;
                    if (x.Top - x.Height > 500)
                    {
                        x.Top  = this.ClientSize.Width - rand.Next(500, 600);
                        x.Left = this.ClientSize.Width - rand.Next(20, 480);
                        score++;
                    }
                }
                if (x is PictureBox && (string)x.Tag == "box3" && countBox > 10)
                {//pojawienie się kolejnego obiektu
                    pictureBox3.Visible = true;
                    x.Top = x.Top + boxSpeed;
                    if (x.Top - x.Height > 500)
                    {
                        x.Top  = this.ClientSize.Width - rand.Next(500, 500);
                        x.Left = this.ClientSize.Width - rand.Next(20, 480);
                        score++;
                    }
                }
                //zwiększanie szybkości spadania obiektów z góry
                if (countBox > 5)
                {
                    boxSpeed = 10;
                    if (countBox > 10)
                    {
                        boxSpeed = 13;
                        if (countBox > 25)
                        {
                            boxSpeed = 17;
                            if (countBox > 40)
                            {
                                boxSpeed = 21;
                                if (countBox > 60)
                                {
                                    boxSpeed = 24;
                                }
                            }
                        }
                    }
                }
                //zdarzenia jeśli gracz wyjdzie poza obszar planszy
                if (player.Location.Y > 605 - player.Height || player.Location.Y < 10 - player.Height ||
                    player.Location.X > 495 - player.Width || player.Location.X < 6 - player.Width)
                {
                    timer.Stop();
                    DialogResult result = MessageBox.Show("Grasz dalej?", "Nie uciekaj z planszy!", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        this.Hide();
                        Dodger d = new Dodger(loginTB.Text);
                        d.Show();
                        break;
                    }
                    else
                    {
                        this.Hide();
                        UserMain um = new UserMain(loginTB.Text);
                        um.Show();
                        break;
                    }
                }
            }
        }
Example #4
0
        private void timer_Tick(object sender, EventArgs e)
        {
            scoreLBL.Text = score--.ToString();
            player.Top    = player.Top + jumpSpeed; //umieszczenie gracza na mape, spada na platforme
            //mechanizm poruszania się
            if (jump && force < 0)
            {
                jump = false;
            }
            if (goLeft)
            {
                player.Left = player.Left - 5;
            }
            if (goRight)
            {
                player.Left = player.Left + 5;
            }
            if (jump)
            {
                jumpSpeed = -12;
                force     = force - 1;
            }
            else
            {
                jumpSpeed = 12;
            }
            foreach (Control x in this.Controls)
            {
                if (x is PictureBox && (string)x.Tag == "platform")
                {
                    if (player.Bounds.IntersectsWith(x.Bounds) && !jump) //jeśli gracz dotknie platformy to stanie na niej
                    {
                        force      = 8;
                        player.Top = x.Top - player.Height;
                    }
                }
                if (x is PictureBox && (string)x.Tag == "coin")
                {
                    if (player.Bounds.IntersectsWith(x.Bounds) && !jump) //jeśli gracz dotknie bonusu 'pieniążka'
                    {
                        this.Controls.Remove(x);
                        score = score + 130;
                    }
                }
            }

            if (player.Location.Y > 580) // jeśli spadnie z planszy
            {
                timer.Stop();
                DialogResult result = MessageBox.Show("Grasz dalej?", "Spadłeś z planszy", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    this.Hide();
                    Jumper j = new Jumper(loginTB.Text);
                    j.Show();
                }
                else
                {
                    this.Hide();
                    UserMain um = new UserMain(loginTB.Text);
                    um.Show();
                    this.Close();
                }
            }
            if (scoreLBL.Text == 0.ToString())
            {
                timer.Stop();
                DialogResult result = MessageBox.Show("Niestety idzie Ci za wolno, nie dostaniesz punktów za tą próbę, nawet tych ujemnych. \n" +
                                                      "Możesz spróbować jeszcze raz.", "Brakło ci czasu", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    this.Hide();
                    Jumper j = new Jumper(loginTB.Text);
                    j.Show();
                }
                else
                {
                    this.Hide();
                    UserMain um = new UserMain(loginTB.Text);
                    um.Show();
                    this.Close();
                }
            }
            if (player.Bounds.IntersectsWith(door.Bounds)) //jeśli gracz dojdzie na mete
            {
                timer.Stop();
                MessageBox.Show("Wygrałeś! Zdobyłeś " + scoreLBL.Text + " punktów!", "Gratulacje");

                SqlConnection cnn = new SqlConnection(@"Server=DESKTOP-2I2V4OF;
                                                             Database=DatabaseApp;
                                                             Trusted_Connection=True;");
                cnn.Open();
                String     sql     = "update users set score = score + @addScore where login = +'" + loginTB.Text + "'";
                SqlCommand command = new SqlCommand(sql, cnn);
                command.Parameters.AddWithValue("addScore", scoreLBL.Text);
                command.ExecuteNonQuery();
                cnn.Close();

                UserMain um = new UserMain(loginTB.Text);
                um.Show();
                this.Close();
            }
        }