//Gets triggered when program is build or on pbCanvas.Invalidate(); private void pbCanvas_Paint(object sender, PaintEventArgs e) { Graphics canvas = e.Graphics; List <Brush> renkler = new List <Brush> //buyuk yiyeceklerin rengi { Brushes.YellowGreen, Brushes.OrangeRed }; if (timerRedSnakeEffect.Enabled == true) //buyuk yiyecegi yeyince yilan efekti { counter2++; } if (!Settings.GameOver) { //Set colour of snake Brush snakeColor; //Draw Snake for (int i = 0; i < Snake.Count; i++) { if (i == 0) //Eger kafaysa { snakeColor = Brushes.DarkSlateGray; //Draw head } else //Eger govde ise { if (timerRedSnakeEffect.Enabled == true && counter2 < 22) { Random rnd = new Random(); snakeColor = renkler[rnd.Next(0, 2)]; } else if (counter2 == 22) //Efektin zamani bitti ise { timerRedSnakeEffect.Stop(); counter2 = 0; snakeColor = Brushes.Green; } else { snakeColor = Brushes.Green; //Yoksa } } //Draw Snake canvas.FillEllipse(snakeColor, new Rectangle(Snake[i].X * Settings.Width, Snake[i].Y * Settings.Height, Settings.Width, Settings.Height)); //Draw Food canvas.FillEllipse(foodColor, new Rectangle(food.X * Settings.Width, food.Y * Settings.Height, Settings.Width, Settings.Height)); if (Settings.Level == 3) { for (int k = 0; k <= 416; k += 16) { canvas.FillEllipse(Brushes.Black, new Rectangle(0, k, Settings.Width, Settings.Height)); canvas.FillEllipse(Brushes.Black, new Rectangle(k, 0, Settings.Width, Settings.Height)); } for (int j = 0; j <= 400; j += 16) { canvas.FillEllipse(Brushes.Black, new Rectangle(416, j, Settings.Width, Settings.Height)); canvas.FillEllipse(Brushes.Black, new Rectangle(j, 384, Settings.Width, Settings.Height)); } } if (Settings.Level == 2 || Settings.Level == 3) { for (int a = 96; a <= 320; a += 16) { canvas.FillEllipse(Brushes.Black, new Rectangle(a, 96, Settings.Width, Settings.Height)); canvas.FillEllipse(Brushes.Black, new Rectangle(a, 288, Settings.Width, Settings.Height)); for (int b = 64; b <= 320; b += 16) { canvas.FillEllipse(Brushes.Black, new Rectangle(48, b, Settings.Width, Settings.Height)); canvas.FillEllipse(Brushes.Black, new Rectangle(368, b, Settings.Width, Settings.Height)); } } } if (Settings.isItThousandMultiplier == true) { Random rnd = new Random(); if (counter < period && counter != 0) { canvas.FillEllipse(renkler[rnd.Next(0, 2)], new Rectangle(largeFood.X * Settings.Width, largeFood.Y * Settings.Height, Settings.Width2, Settings.Height2)); } else { largeFood.X = 1000; largeFood.Y = 1000; counter = 0; } } } } else { if (isFirstRunningRecord) { isFirstRunningRecord = false; db.UserRecord(); rc = DB.currentUser.Record; if (DB.newRecord) { player.SoundLocation = "newrecord.wav"; } else { player.SoundLocation = "game-over.wav"; } player.Play(); } lblGameOver.Text = "Game over.\nYour score: " + Settings.Score + "\nYour record: " + rc.ToString() + "\n\n\nTo play again press ENTER,\nTo exit press ESC."; lblUsername.Text = "Well played \n" + DB.currentUser.Username + " !"; lblGameOver.Show(); lblUsername.Show(); if (isFirstRunning) { isFirstRunning = false; } } }