Snake Game in WPF

Image-1.jpg


Image-2.jpg

private void Window_KeyDown(object sender, KeyEventArgs e){
    if (e.Key == Key.Left)

    {               

        move = "Left";                    }
    if (e.Key == Key.Right)

    {

        move = "Right";              

    }           
    if (e.Key == Key.Up)

    {

        move = "Up";              

    }

    if (e.Key == Key.Down)    {
        move = "Down";              

    }}  

System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Click);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 75);

dispatcherTimer.Start();

if (move == "Left"){
    randomz();

    double e1l = Canvas.GetLeft(ellipse1);
//get

    double e1t = Canvas.GetTop(ellipse1);

    double e2l = Canvas.GetLeft(ellipse2);

    double e2t = Canvas.GetTop(ellipse2);

    double e3t = Canvas.GetTop(ellipse3);

    double e3l = Canvas.GetLeft(ellipse3);

    double e4t = Canvas.GetTop(ellipse4);

    double e4l = Canvas.GetLeft(ellipse4);

    double e5t = Canvas.GetTop(ellipse5);

    double e5l = Canvas.GetLeft(ellipse5);

    double e6t = Canvas.GetTop(ellipse6);

    double e6l = Canvas.GetLeft(ellipse6);

    double e7t = Canvas.GetTop(ellipse7);

    double e7l = Canvas.GetLeft(ellipse7);
    
              

    Canvas.SetLeft(ellipse1,  e1l-25);
//set                   

    Canvas.SetLeft(ellipse2, e1l);    Canvas.SetTop(ellipse2,e1t);                   

    Canvas.SetLeft(ellipse3,e2l);    Canvas.SetTop(ellipse3,e2t);
    Canvas.SetLeft(ellipse4,e3l);

    Canvas.SetTop(ellipse4,e3t);

    Canvas.SetLeft(ellipse5, e4l);

    Canvas.SetTop(ellipse5, e4t);

    Canvas.SetLeft(ellipse6, e5l);

    Canvas.SetTop(ellipse6, e5t);

    Canvas.SetLeft(ellipse7, e6l);

    Canvas.SetTop(ellipse7, e6t);

    Canvas.SetLeft(ellipse8, e7l);

    Canvas.SetTop(ellipse8, e7t);

}