Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private List<Point> snakePoints = new List <Point>();
- private Point startingPoint = new Point(100, 100);
- private Point currentPosition = new Point();
- private int direction = 0; //Steuerung mit Pfeiltasten (8,4,6,2)
- public MainWindow()
- {
- InitializeComponent();
- DispatcherTimer timer = new DispatcherTimer();
- timer.Tick += new EventHandler(timer_Tick);
- timer.Interval = new TimeSpan(10000);
- timer.Start();
- this.KeyDown += new KeyEventHandler(OnButtonKeyDown);
- PaintSnake(startingPoint);
- currentPosition = startingPoint;
- Random rdm = new Random();
- Point food = new Point();
- food.X = rdm.Next(Width);
- food.Y = rdm.Next(Height);
- if (snake.hea)
- {
- }
- }
- private void Drawing()
- {
- }
- private void placeFood()
- {
- throw new NotImplementedException();
- }
- private void paintBonus()
- {
- }
- private void PaintSnake(Point currentPosition)
- {
- //##### Check, ob die Schlange in sich selbst fährt#####
- if (snakePoints.Contains(currentPosition))
- {
- GameOver();
- }
- int xNew = Convert.ToInt32(startingPoint);
- int yNew = Convert.ToInt32(startingPoint);
- Ellipse newEllipse = new Ellipse();
- newEllipse.Fill= Brushes.Red;
- newEllipse.Width = 6; //Stärke des Schlangenkörpers
- newEllipse.Height = 6; //Stärke des Schlangenkörpers
- Canvas.SetBottom(newEllipse, currentPosition.Y);
- Canvas.SetLeft(newEllipse, currentPosition.X);
- generateFood();
- int count = paintCanvas.Children.Count;
- paintCanvas.Children.Add(newEllipse); //Ellipse auf Zeichenfläche einhängen
- snakePoints.Add(currentPosition);
- //########## Länge der Schlange begrenzen ##########
- int length = 100;
- if (count >length)
- {
- paintCanvas.Children.RemoveAt(count - length - 1);
- snakePoints.RemoveAt(count - length);
- }
- double punkte = Convert.ToInt32(lblpunkte.Content);
- }
- private void generateFood()
- {
- if (true)
- {
- }
- }
- public partial class Food : Window
- {
- static Random random = new Random();
- Ellipse foodshape = new Ellipse();
- public Food (Canvas paintcanvas)
- {
- foodshape.Height = 5;
- foodshape.Width = 5;
- foodshape.Fill = Brushes.Blue;
- }
- }
- private void GameOver()
- {
- MessageBox.Show("You lose. Game over!");
- this.Close();
- }
- private void OnButtonKeyDown(object sender, KeyEventArgs e)
- {
- int oldDirection = directtion;
- switch (e.Key)
- {
- case Key.Down:
- direction = 2;
- break;
- case Key.Up:
- direction = 8;
- break;
- case Key.Left:
- direction = 4;
- break;
- case Key.Right:
- direction = 6;
- break;
- }
- }
- private void timer_Tick(object sender, EventArgs e)
- {
- switch (direction)
- {
- case 8: //up
- currentPosition.Y += 1;
- PaintSnake(currentPosition);
- break;
- case 2: //down
- currentPosition.Y -= 1;
- PaintSnake(currentPosition);
- break;
- case 4: //left
- currentPosition.X -= 1;
- PaintSnake(currentPosition);
- break;
- case 6: //right
- currentPosition.X += 1;
- PaintSnake(currentPosition);
- break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement