随着时间改变椭圆的颜色

时间:2014-05-25 08:28:46

标签: windows-phone-8

我正在尝试制作一个wp8应用,告诉你在红绿灯变绿之前多久。有一个叫做go的函数。当在后台调用它时,不会比较所有4个车道上的汽车数量。第一次被称为它,它给你带有最大车辆的前两个车道,大多数车辆的m和第二个没有车辆的q。但随后无论何时调用它,它只给出一个车道和大多数车辆,并且在每个函数调用中,该值在m和q之间交替保存。在我的xaml上我有4个椭圆,其颜色我必须每15秒更换一次。我将在下面粘贴我的xaml.cs代码。 60秒后灯光没有正确改变,但它们在前60秒内完美运行。请帮我搞清楚。 l1,l2,l3和; 4是椭圆。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Threading;
using System.Windows.Threading;
using System.Windows.Media;



namespace TrafficGuru
{
    public partial class Page2 : PhoneApplicationPage
    {
        DispatcherTimer countDownTimer;
        int check;
        int gofncalledcount = 1;

        public void setclr()
        {
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();
            SolidColorBrush green = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
            SolidColorBrush red = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
            SolidColorBrush yellow = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
            l1.Fill = red;
            l2.Fill = red;
            l3.Fill = red;
            l4.Fill = red;

            if (gofncalledcount % 2 != 0)
            {
                if (global.m == 0)
                {
                    l1.Fill = green;
                    if (global.q == 1)
                    {
                        l2.Fill = yellow;
                        l3.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.q == 2)
                    {
                        l2.Fill = red;
                        l3.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.q == 3)
                    {
                        l2.Fill = red;
                        l3.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                if (global.m == 1)
                {
                    l2.Fill = green;
                    if (global.q == 0)
                    {
                        l1.Fill = yellow;
                        l3.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.q == 2)
                    {
                        l1.Fill = red;
                        l3.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.q == 3)
                    {
                        l1.Fill = red;
                        l3.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                else if (global.m == 2)
                {
                    l3.Fill = green;
                    if (global.q == 0)
                    {
                        l1.Fill = yellow;
                        l2.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.q == 1)
                    {
                        l1.Fill = red;
                        l2.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.q == 3)
                    {
                        l1.Fill = red;
                        l2.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                else if (global.m == 3)
                {
                    l4.Fill = green;
                    if (global.q == 0)
                    {
                        l1.Fill = yellow;
                        l2.Fill = red;
                        l3.Fill = red;
                    }
                    else if (global.q == 1)
                    {
                        l1.Fill = red;
                        l2.Fill = yellow;
                        l3.Fill = red;
                    }
                    else if (global.q == 2)
                    {
                        l1.Fill = red;
                        l2.Fill = red;
                        l3.Fill = yellow;
                    }
                }
            }
            else
            {
                if (global.q == 0)
                {
                    l1.Fill = green;
                    if (global.m == 1)
                    {
                        l2.Fill = yellow;
                        l3.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.m == 2)
                    {
                        l2.Fill = red;
                        l3.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.m == 3)
                    {
                        l2.Fill = red;
                        l3.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                if (global.q == 1)
                {
                    l2.Fill = green;
                    if (global.m == 0)
                    {
                        l1.Fill = yellow;
                        l3.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.m == 2)
                    {
                        l1.Fill = red;
                        l3.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.m == 3)
                    {
                        l1.Fill = red;
                        l3.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                else if (global.q == 2)
                {
                    l3.Fill = green;
                    if (global.m == 0)
                    {
                        l1.Fill = yellow;
                        l2.Fill = red;
                        l4.Fill = red;
                    }
                    else if (global.m == 1)
                    {
                        l1.Fill = red;
                        l2.Fill = yellow;
                        l4.Fill = red;
                    }
                    else if (global.m == 3)
                    {
                        l1.Fill = red;
                        l2.Fill = red;
                        l4.Fill = yellow;
                    }
                }
                else if (global.q == 3)
                {
                    l4.Fill = green;
                    if (global.n == 0)
                    {
                        l1.Fill = yellow;
                        l2.Fill = red;
                        l3.Fill = red;
                    }
                    else if (global.m == 1)
                    {
                        l1.Fill = red;
                        l2.Fill = yellow;
                        l3.Fill = red;
                    }
                    else if (global.m == 2)
                    {
                        l1.Fill = red;
                        l2.Fill = red;
                        l3.Fill = yellow;
                    }
                }

            }


        }
        public Page2()
        {
            InitializeComponent();

            setclr();


            tbl.Text = global.str;

            if (global.str == "YOUR LIGHT IS ON FOR : ")
            {
                check = 0;
            }
            if (global.str == "YOUR LIGHT WILL BE ON IN:")
            {
                check = 1;
            }
            if (global.str == "YOUR LIGHT WILL NOT BE ON FOR UNTIL ATLEAST " + global.x * 15 + " MORE SECS.YOU WILL GET AN UPDATE IN:")
            {
                check = 2;
            }
            countDownTimer = new DispatcherTimer();
            countDownTimer.Interval = new TimeSpan(0, 0, 0, 1);
            countDownTimer.Tick += new EventHandler(countDownTimerEvent);





            countDownTimer.Start();



            test.Content = "";

        }


        int count = global.cdt;
        int g = 0;

        void test_Click(object sender, EventArgs e) { }
        void countDownTimerEvent(object sender, EventArgs e)
        {
            g++;
            if (g==16 )
            {
                g = 0;
                global.go();
                gofncalledcount++;
                setclr();


            }
            test.Content = count + " Seconds";


            if (count > 0)
            {
                count--;
            }
            else if (count == 0)
            {
                count = global.cdt;
                countDownTimer.Stop();
                if (check == 0)
                {



                    test.Content = "STOP!!";
                    /*
                    NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.RelativeOrAbsolute));*/


                }
                else if (check == 1)
                {


                    test.Content = "GO!!!";/*
                NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.RelativeOrAbsolute));*/

                }

                else
                {

                    //setclr();

                    tbl.Text = global.str;
                    if (global.str == "YOUR LIGHT IS ON FOR : ")
                    {
                        check = 0;
                    }
                    if (global.str == "YOUR LIGHT WILL BE ON IN:")
                    {
                        check = 1;
                    }
                    if (global.str == "YOUR LIGHT WILL NOT BE ON FOR UNTIL ATLEAST " + global.x * 15 + " MORE SECS.YOU WILL GET AN UPDATE IN:")
                    {
                        check = 2;
                    }



                    countDownTimer.Start();



                    //NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.RelativeOrAbsolute));

                }
            }
        }
    }
}

0 个答案:

没有答案