//-------------------------------------------------------------------------------- //--------------------------- GAME OVER AND REPLAY ------------------------------- //-------------------------------------------------------------------------------- private void GameOver() { Space_Mover.Stop(); Score_Mover.Stop(); EnemyCookies_Mover.Stop(); EnemyCookies2_Mover.Stop(); CookieFuel1_Mover.Stop(); CookieFuel2_Mover.Stop(); CookieFuel3_Mover.Stop(); CookieBunch_Mover.Stop(); LaserSpeed_Mover.Stop(); CookiesFuel_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(); } }
private void Space_Mover_Tick(object sender, EventArgs e) { //--------------------------- SPACE MOVEMENT ---------------------------------- //for (int i = 0; i < space.Length; i++) //{ // space[i].Top += speed*2; // if (space[i].Top >= ActiveForm.Height) // { // space[i].Top = -space[i].Height; // } //} //-------------------------- SPEED INCREMENT --------------------------------- if (score > level4 && score <= level5) { level = 4; EnemyCookie_7.Visible = true; EnemyCookie_8.Visible = true; EnemyCookie_9.Visible = true; EnemyCookie_10.Visible = true; EnemyCookie_11.Visible = true; EnemyCookie_12.Visible = true; EnemyCookies2_Mover.Start(); } if (score > level5 && score <= level6) { level = 5; speed = 4; } //------------------ SHOWS LEVEL -------------------------------------------- Level_Text.Text = $"Level {level}"; //------------------------- ENEMY COOKIE INTERSECTS ---------------------------------- if (Car_Space.Bounds.IntersectsWith(EnemyCookie_1.Bounds)) { if (EnemyCookie_1.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_2.Bounds)) { if (EnemyCookie_2.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_3.Bounds)) { if (EnemyCookie_3.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_4.Bounds)) { if (EnemyCookie_4.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_5.Bounds)) { if (EnemyCookie_5.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_6.Bounds)) { if (EnemyCookie_6.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_7.Bounds)) { if (EnemyCookie_7.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_8.Bounds)) { if (EnemyCookie_8.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_9.Bounds)) { if (EnemyCookie_9.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_10.Bounds)) { if (EnemyCookie_10.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_11.Bounds)) { if (EnemyCookie_11.Visible == true) { GameOver(); } } if (Car_Space.Bounds.IntersectsWith(EnemyCookie_12.Bounds)) { if (EnemyCookie_12.Visible == true) { GameOver(); } } //------------------------- LASER INTERSECTS ---------------------------------- if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_1.Bounds)) { if (EnemyCookie_1.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_1.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_2.Bounds)) { if (EnemyCookie_2.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_2.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_3.Bounds)) { if (EnemyCookie_3.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_3.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_4.Bounds)) { if (EnemyCookie_4.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_4.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_5.Bounds)) { if (EnemyCookie_5.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_5.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_6.Bounds)) { if (EnemyCookie_6.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_6.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_7.Bounds)) { if (EnemyCookie_7.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_7.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_8.Bounds)) { if (EnemyCookie_8.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_8.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_9.Bounds)) { if (EnemyCookie_9.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_9.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_10.Bounds)) { if (EnemyCookie_10.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_10.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_11.Bounds)) { if (EnemyCookie_11.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_11.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } if (Car_Laser.Bounds.IntersectsWith(EnemyCookie_12.Bounds)) { if (EnemyCookie_12.Visible == true) { score += pointsPerEnemy; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * enemyCookieX); int y = 0; EnemyCookie_12.Location = new Point(x, y); Laser_Mover.Stop(); Car_Laser.Top = Car_Space.Location.Y; Car_Laser.Left = Car_Space.Left + halfCarWidth; Car_Laser.Visible = false; } } //----------------------------- COOKIE INTERSECTS ----------------------------- if (Car_Space.Bounds.IntersectsWith(Cookie_1.Bounds)) { cookieFuel += 5; score += pointsPerCookie; Cookies_Text.Text = $"Cookies {cookieFuel}"; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * cookieX); int y = 0; Cookie_1.Location = new Point(x, y); } if (Car_Space.Bounds.IntersectsWith(Cookie_2.Bounds)) { cookieFuel += 5; score += pointsPerCookie; Cookies_Text.Text = $"Cookies {cookieFuel}"; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * cookieX); int y = 0; Cookie_2.Location = new Point(x, y); } if (Car_Space.Bounds.IntersectsWith(Cookie_3.Bounds)) { cookieFuel += 5; score += pointsPerCookie; Cookies_Text.Text = $"Cookies {cookieFuel}"; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * cookieX); int y = 0; Cookie_3.Location = new Point(x, y); } if (Car_Space.Bounds.IntersectsWith(Cookie_Bunch.Bounds)) { cookieFuel += 50; score += pointsPerCookie * 10; Cookies_Text.Text = $"Cookies {cookieFuel}"; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * cookieX); int y = 0; Cookie_Bunch.Location = new Point(x, y); } if (Car_Space.Bounds.IntersectsWith(SpeedUp_Laser.Bounds)) { speedUPLevel++; score += pointsPerCookie * 10; Score_Text.Text = $"Score {score:#,###}"; int x = (int)Math.Ceiling(rnd.NextDouble() * cookieX); int y = 0; SpeedUp_Laser.Location = new Point(x, y); } if (cookieFuel == 0) { GameOver(); } }