Ejemplo n.º 1
0
 //--------------------------------------------------------------------------------
 //--------------------------- GAME OVER AND REPLAY -------------------------------
 //--------------------------------------------------------------------------------
 private void GameOver()
 {
     RoadMover.Stop();
     Score_Timer.Stop();
     Enemy1_Mover.Stop();
     Enemy2_Mover.Stop();
     Enemy3_Mover.Stop();
     Coin1_Mover.Stop();
     Coin2_Mover.Stop();
     Coin3_Mover.Stop();
     End_Text.Visible        = true;
     Replay_Button.Visible   = true;
     MainMenu_Button.Visible = true;
     using (StreamWriter sw = File.AppendText(filePath))
     {
         sw.WriteLine($"{Form6_GetName.playerName},{score}");
         sw.Close();
     }
 }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------
        //-------------------------------- ROAD GAME -------------------------------------
        //--------------------------------------------------------------------------------
        private void RoadMover_Tick(object sender, EventArgs e)
        {
            //--------------------------- ROAD MOVEMENT ----------------------------------
            for (int i = 0; i < road.Length; i++)
            {
                road[i].Top += speed;
                if (road[i].Top >= ActiveForm.Height)
                {
                    road[i].Top = -road[i].Height;
                }
            }

            //-------------------------- SPEED INCREMENT ---------------------------------
            if (score > level2 && score <= level3)
            {
                speed = 5;
                level = 2;
            }
            if (score > level3 && speed <= speedToNextArea)
            {
                speed++;
                level = 3;
                Score_Timer.Stop();
                Enemy1_Mover.Stop();
                Enemy2_Mover.Stop();
                Enemy3_Mover.Stop();
                Coin1_Mover.Stop();
                Coin2_Mover.Stop();
                Coin3_Mover.Stop();
                Left_mover.Stop();
                Right_mover.Stop();
                EnemyCar1.Visible = false;
                EnemyCar2.Visible = false;
                EnemyCar3.Visible = false;
                Coin1.Visible     = false;
                Coin2.Visible     = false;
                Coin3.Visible     = false;
                Grandpa_Mover.Start();
                GrandpaCar.Visible = true;
            }

            //---------------------------- COOKIE START ----------------------------------
            if (score > cookiesSpawn && score <= level3)
            {
                Coin1.Visible = true;
                Coin2.Visible = true;
                Coin3.Visible = true;
                Coin1_Mover.Start();
                Coin2_Mover.Start();
                Coin3_Mover.Start();
            }

            //------------------ SHOWS LEVEL --------------------------------------------
            Level_Text.Text = $"Level {level}";

            //------------------------- CAR INTERSECTS ----------------------------------
            if (Car.Bounds.IntersectsWith(EnemyCar1.Bounds))
            {
                GameOver();
            }
            if (Car.Bounds.IntersectsWith(EnemyCar2.Bounds))
            {
                GameOver();
            }
            if (Car.Bounds.IntersectsWith(EnemyCar3.Bounds))
            {
                GameOver();
            }

            //----------------------------- COIN INTERSECTS -----------------------------
            if (Car.Bounds.IntersectsWith(Coin1.Bounds))
            {
                coins++;
                score          += pointsPerCookie;
                Coins_Text.Text = $"Cookies {coins}";
                Score_Text.Text = $"Score {score:#,###}";
                int x = (int)Math.Ceiling(rnd.NextDouble() * coinsX);
                int y = 0;
                Coin1.Location = new Point(x, y);
            }
            if (Car.Bounds.IntersectsWith(Coin2.Bounds))
            {
                coins++;
                score          += pointsPerCookie;
                Coins_Text.Text = $"Cookies {coins}";
                Score_Text.Text = $"Score {score:#,###}";
                int x = (int)Math.Ceiling(rnd.NextDouble() * coinsX);
                int y = 0;
                Coin2.Location = new Point(x, y);
            }
            if (Car.Bounds.IntersectsWith(Coin3.Bounds))
            {
                coins++;
                score          += pointsPerCookie;
                Coins_Text.Text = $"Cookies {coins}";
                Score_Text.Text = $"Score {score:#,###}";
                int x = (int)Math.Ceiling(rnd.NextDouble() * coinsX);
                int y = 0;
                Coin3.Location = new Point(x, y);
            }
        }