private void paintApple() { switch (difficulty) { case "Medium": if (applesEaten % 5 == 0) { paintRotten(); } break; case "Hard": if (applesEaten % 3 == 0) { paintRotten(); } break; } newApple = new snakePart(random.Next(0, (int)gameGrid.Width / snakeSize), random.Next(0, (int)gameGrid.Height / snakeSize)); ImageBrush myBrush = new ImageBrush(); myBrush.ImageSource = new BitmapImage(new Uri("D:/pobrane/WPFsnejk/WPFsnejk/Resources/Images/apple.png")); newApple.ellipse.Fill = myBrush; apples.Add(newApple); gameGrid.Children.Add(newApple.ellipse); Grid.SetColumn(newApple.ellipse, newApple.X); Grid.SetRow(newApple.ellipse, newApple.Y); }
public snake() { head = new snakePart(20, 20); snakeParts = new List <snakePart>(); snakeParts.Add(new snakePart(19, 20)); snakeParts.Add(new snakePart(18, 20)); snakeParts.Add(new snakePart(17, 20)); }
private void paintRotten() { newRotten = new snakePart(random.Next(0, (int)gameGrid.Width / snakeSize), random.Next(0, (int)gameGrid.Height / snakeSize)); ImageBrush myBrush = new ImageBrush(); myBrush.ImageSource = new BitmapImage(new Uri("D:/pobrane/WPFsnejk/WPFsnejk/Resources/Images/trutka.png")); newRotten.ellipse.Fill = myBrush; rottens.Add(newRotten); gameGrid.Children.Add(newRotten.ellipse); Grid.SetColumn(newRotten.ellipse, newRotten.X); Grid.SetRow(newRotten.ellipse, newRotten.Y); }
private void ifAppleEaten() { for (int i = 0; i < apples.Count; i++) { if (snejk.head.X == apples[i].X && snejk.head.Y == apples[i].Y) { snakePart newPart = new snakePart(snejk.snakeParts[snejk.snakeParts.Count - 1].X, snejk.snakeParts[snejk.snakeParts.Count - 1].Y); gameGrid.Children.Add(newPart.ellipse); applesEaten++; snejk.snakeParts.Add(newPart); gameGrid.Children.Remove(apples[i].ellipse); apples.Remove(apples[i]); paintApple(); switch (difficulty) { case "Easy": score += 10; break; case "Medium": score += 25; break; case "Hard": score += 50; break; } scoreTextBlock.Text = score.ToString(); SoundPlayer snd = new SoundPlayer("D:/pobrane/WPFsnejk/WPFsnejk/Resources/Sounds/zjedzenie.wav"); snd.Play(); } } }