private void MyPanel_Paint(object sender, PaintEventArgs e) { int radius = 5; Pen myPen = new Pen(Color.Green, 5); SolidBrush myBrush = new SolidBrush(Color.Green); Graphics graphics = e.Graphics; for (int i = 0; i < snake.SnakeLength(); i++) { if (snake.GetPosY(i) != 0) { graphics.DrawEllipse(myPen, snake.GetPosX(i) - radius, snake.GetPosY(i) - radius, radius + radius, radius + radius); graphics.FillEllipse(myBrush, snake.GetPosX(i) - radius, snake.GetPosY(i) - radius, radius + radius, radius + radius); } } myPen = new Pen(Color.Red, 5); myBrush = new SolidBrush(Color.Red); if (drawApple == 1) { graphics.DrawEllipse(myPen, apple.GetPosx() - radius, apple.GetPosY() - radius, radius + radius, radius + radius); graphics.FillEllipse(myBrush, apple.GetPosx() - radius, apple.GetPosY() - radius, radius + radius, radius + radius); } graphics.Dispose(); myBrush.Dispose(); }
public Boolean VerifyHit(Snake snake, Apple apple) { if ((apple.GetPosx() - 10) <= snake.GetPosX(0) && snake.GetPosX(0) <= (apple.GetPosx() + 10) && (apple.GetPosY() - 10) <= snake.GetPosY(0) && snake.GetPosY(0) <= (apple.GetPosY() + 10)) { return(true); } else { return(false); } }