private void timer1_Tick(object sender, EventArgs e) { if (if_game_active) { game_field.CreateGraphics().Clear(Color.Black); snake.Move(); snake.draw(game_field.CreateGraphics(), new SolidBrush(Color.Aqua)); fruit.draw_fruit(game_field.CreateGraphics(), new SolidBrush(Color.Red)); if (fruit.if_new_fruit(snake.x[0], snake.y[0])) { snake.add(); } if (snake.if_snake_alive() == false) { if_game_active = false; } } else { FontFamily fontFamily1 = new FontFamily("Arial"); Font f = new Font(fontFamily1, 15); Brush b = new SolidBrush(Color.Aqua); game_field.CreateGraphics().DrawString("Press the Start", f, b, 80, 135); } }
private void timer1_Tick(object sender, EventArgs e) { if (if_game_active) { field.CreateGraphics().Clear(Color.Green); snake.Move(); snake.Draw(field.CreateGraphics(), new SolidBrush(Color.Black)); fruit.draw_fruit(field.CreateGraphics(), new SolidBrush(Color.Red)); if (fruit.if_eaten(snake.tail_X[0], snake.tail_Y[0])) { try { snake.eat(); score = score + 10; timer1.Interval -= 1; } catch { MessageBox.Show("Slow down!"); } } if (snake.snake_alive() == false) { if_game_active = false; pauseToolStripMenuItem.Enabled = false; gameSpeedToolStripMenuItem.Enabled = false; MessageBox.Show("Your lose\nYour score: " + score); score = 0; } } else { FontFamily fontFamily = new FontFamily("Arial"); Font font = new Font(fontFamily, 25); Brush font_color = new SolidBrush(Color.Black); //field.CreateGraphics().DrawString("Press Start", font, font_color, 40, 105); } }