/// <summary>
        /// ослободување од меморија за сите потрошени објекти
        /// </summary>
        public void EndOfGame()
        {
            MyEnemies.Dispose();
            string query = "SELECT * FROM PlayerTable WHERE username = '******'";

            cmd = new SqlCeCommand(query, con);

            con.Open();
            rdr = cmd.ExecuteReader();
            rdr.Read();

            switch (gamemode)
            {
            case GameMode.Easy:
                int s1     = Convert.ToInt16(rdr[3]);
                int score1 = CollectedCoins + CollectedBananas * 10 + CounterKilledEvilMinions * 20;
                if (score1 > s1)
                {
                    cmd.CommandText = "UPDATE PlayerTable Set scoreL1=@scoreL1 where username=@username";
                    cmd.Parameters.AddWithValue("username", LogInForm.Username);
                    cmd.Parameters.AddWithValue("@scoreL1", score1);
                    cmd.ExecuteNonQuery();
                }
                break;

            case GameMode.Medium:
                int s2     = Convert.ToInt16(rdr[4]);
                int score2 = CollectedCoins + CollectedBananas * 10 + CounterKilledEvilMinions * 20;
                if (score2 > s2)
                {
                    cmd.CommandText = "UPDATE PlayerTable Set scoreL2=@scoreL2 where username=@username";
                    cmd.Parameters.AddWithValue("username", LogInForm.Username);
                    cmd.Parameters.AddWithValue("@scoreL2", score2);
                    cmd.ExecuteNonQuery();
                }
                break;

            case GameMode.Hard:
                int s3     = Convert.ToInt16(rdr[4]);
                int score3 = CollectedCoins + CollectedBananas * 10 + CounterKilledEvilMinions * 20 + CounterVectorKilled * 50;
                if (score3 > s3)
                {
                    cmd.CommandText = "UPDATE PlayerTable Set scoreL3=@scoreL3 where username=@username";
                    cmd.Parameters.AddWithValue("username", LogInForm.Username);
                    cmd.Parameters.AddWithValue("@scoreL3", score3);
                    cmd.ExecuteNonQuery();
                }
                break;


            default:
                break;
            }
            con.Close();
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            var code = 1;

            while (Convert.ToBoolean(code))
            {
                Console.WriteLine("1 - Draw shapes\n2 - Draw flags\n3 - WTF\n0 - Exit");
                Console.Write("Your choice : ");
                int.TryParse(Console.ReadLine(), out code);
                switch (code)
                {
                case 1:
                    Drawing();
                    Console.ReadKey(true);
                    break;

                case 2:
                    SecondTask();
                    Console.ReadKey(true);
                    break;

                case 3:
                    Console.WriteLine("I have no enemies.So I just overridden the methods");
                    MyEnemies a = new MyEnemies {
                        Name = "Lox"
                    };
                    MyEnemies b = new MyEnemies()
                    {
                        Name = "NeLox"
                    };
                    Console.WriteLine(a.ToString());
                    Console.WriteLine(a.GetHashCode());
                    var c = a.Equals(b);
                    Console.WriteLine(c);
                    Console.ReadKey(true);
                    break;

                case 0:
                    Environment.Exit(0);
                    break;
                }

                Console.Clear();
            }
        /// <summary>
        /// исцртување на главната панела (позадина, карактер, по потреба куршуми, непријатели, скорови ... итн)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(BckgrBitmap, Bckgr.startingX, 0, BckgrBitmap.Width, BckgrBitmap.Height);
            e.Graphics.DrawImage(Character.CurrentCharacterImage, Character.X, Character.Y);
            if (VisibleBullet)
            {
                BulletInjection.DrawInjection(e.Graphics);
            }
            MyEnemies.DrawEvilMinions(e.Graphics);
            Coins.Draw(e.Graphics);
            Bananas.Draw(e.Graphics);
            e.Graphics.DrawString("COINS: " + CollectedCoins.ToString(), font, brush, point);
            //e.Graphics.DrawString("FOOD: " + CollectedBananas.ToString(), font, brush, point2);
            this.DrawLifeAndKilledEM(e.Graphics);

            if (!VectorVillian.IsKilled && gamemode == GameMode.Hard)
            {
                VectorVillian.DrawVector(e.Graphics);
            }
        }
        public void PlayAgain()
        {
            jump.Play();
            Character.X           = 50;
            Character.MovingRight = true;
            Character.MovingLeft  = false;
            TurnedRight           = true;
            TurnedLeft            = false;
            Character.UpdateCharacterImage();
            MoveBackground = false;
            CanComeBack    = true;

            if (gamemode == GameMode.Easy)
            {
                Character.Y = 200;
            }
            else
            {
                Character.Y = 100;
            }

            MyEnemies.PlayAgain();
        }
        /// <summary>
        /// тајмерот проверува дали каракатерот дошол до фиксната точка, ако да
        /// го фиксира и притоа ја придвижува позадината согласно кон кој правец
        /// се движи играчот како би се створила илузија на движење на позадината.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TmrMoving_Tick(object sender, EventArgs e)
        {
            MovingTimer();


            if (counterShooting++ == 2)
            {
                ShootingTimer();
                counterShooting = 0;
                // + анимација на парички (се совпаѓа), мењање на моментална слика.
                Coins.UpdateImage();
                Coins.IsCollected(Character);
                Coins.IsntCollectedPassed();

                Bananas.IsCollected(Character);
                Bananas.IsntCollectedPassed();
            }

            if (counterKilling++ == 1)
            {
                counterKilling = 0;
                if (VisibleBullet)
                {
                    VisibleBullet = MyEnemies.IsEnemyKilled(BulletInjection);
                }
                CharLosesLife = MyEnemies.KillingCharacter(Character);
            }

            if (!endOfLevel)
            {
                if (counterMove++ == SpeedOfGame)
                {
                    counterMove = 0;
                    MyEnemies.UpdateEvilMinions();
                }

                if (counterAddEnemy++ == 60)
                {
                    counterAddEnemy = 0;
                    MyEnemies.AddEnemy();
                }
            }

            if (Character.Hit >= 3)
            {
                Character.Killed = true;
                this.TmrMoving.Stop();
                GameOver gm = new GameOver();
                gm.ShowDialog();
            }

            if (CollectedCoinsPlusLife == 50)
            {
                CollectedCoinsPlusLife = 0;
                Lifes++;
            }

            if (CharLosesLife)
            {
                PlayAgain();
                CharLosesLife = false;
            }

            if (endOfLevel)
            {
                TmrMoving.Stop();
                pnlWinning.Visible    = true;
                lblCongrats.Visible   = true;
                lblEndWinning.Visible = true;
                lblNextLevel.Visible  = true;
                this.DrawSavedGirl(pnlWinning.CreateGraphics());
                EndOfGame();
            }

            if ((++CounterVector == 200))
            {
                CounterVector = 0;
                if ((gamemode == GameMode.Hard) && (VectorCanShowUp))
                {
                    VectorVillian   = new Vector();
                    VectorCanShowUp = false;
                }
            }

            if (++CounterVectorMoving == 2)
            {
                CounterVectorMoving = 0;

                if (gamemode == GameMode.Hard && !VectorCanShowUp)
                {
                    VectorVillian.updatePosition();

                    if (VectorVillian.VectorAttacked(BulletInjection))
                    {
                        CounterVectorKilled++;
                        lblVector.Text  = "VECTOR DEFEATED " + CounterVectorKilled.ToString() + " TIMES !!";
                        VectorCanShowUp = true;
                    }
                }
            }

            if (gamemode == GameMode.Hard)
            {
                if (VectorVillian.X + VectorVillian.CurrentImage.Width < 0)
                {
                    VectorCanShowUp = true;
                }
            }



            Invalidate();
        }