20150616完 一个测试注意力的小程序

首先添加一个类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;

namespace WpfApplication1
{
    public class ChangeColClass
    {
      
        public DispatcherTimer timerNormal;
        public DispatcherTimer timerError;

        public int Index = 0;

        public Button btnSent;//存储传过来的btn
        public Brush SourceColor;//存储原来按钮的颜色
        public void SetSourceColor(object obj)
        {
            SourceColor = ((Button)obj).Background;//获得按钮的原始颜色
        }

        public void errorCC(object objBtn)
        {
            btnSent = (Button)objBtn;

            StringBuilder sb = new StringBuilder();
            sb.Append("aa");

            timerError = new DispatcherTimer();
            timerError.Interval = TimeSpan.FromSeconds(0.023);
            timerError.Tick += timer_ErrorTick;
            timerError.Start();

            timerNormal = new DispatcherTimer();
            timerNormal.Interval = TimeSpan.FromSeconds(0.037);
            timerNormal.Tick += timer_NormalTick;
            timerNormal.Start();

        }

        public void timer_ErrorTick(object sender, EventArgs e)
        {
            Button btnTemp = btnSent;
            btnTemp.Background = Brushes.Red;
            //btnTemp.Foreground = Brushes.HotPink;//字体发生颜色变化

            Index++;
            if(Index>=30)
            {
                timerError.Stop();
                timerNormal.Stop();
                btnTemp.Background = SourceColor;
                //btnTemp.Foreground = Brushes.Black;//字体发生颜色变化
            }
 
        }

        public void timer_NormalTick(object sender, EventArgs e)
        {
            Button btnTemp = btnSent;
            btnTemp.Background = SourceColor;
            //btnTemp.Foreground = Brushes.Black;//字体发生颜色变化
        }

    }
}
接着添加一个窗口:


其XAML代码为:

<Window x:Class="TestYourConcentration.ScoreInstructionWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="成绩说明" Height="300" Width="300" Loaded="Window_Loaded">
    <Grid>
        <Label  Content="等级说明:" HorizontalAlignment="Left" Margin="23,10,0,0" VerticalAlignment="Top" Width="234"/>
        <Label Name="level1" Content="超常:  0~10s   注意力高度集中且反应超级迅速;" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level2" Content="A 等:  10~15s  注意力高度集中且反应迅速;" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level3" Content="B 等:  15~20s  注意力集中且反应灵敏;" HorizontalAlignment="Left" Margin="10,103,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level4" Content="C 等:  20~25s  注意力和反应正常;" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level5" Content="D 等:  25~30s  注意力不够集中且反应滞后;" HorizontalAlignment="Left" Margin="10,165,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level6" Content="E 等:  30~35s  注意力发散且反应迟缓;" HorizontalAlignment="Left" Margin="10,191,0,0" VerticalAlignment="Top" Width="272"/>
        <Label Name="level7" Content="失常:  35s~     需接受治疗;" HorizontalAlignment="Left" Margin="10,217,0,0" VerticalAlignment="Top" Width="272"/>

    </Grid>
</Window>
主窗口为:


其XAML代码为:

<Window x:Class="TestYourConcentration.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ResizeMode="NoResize"
        Title="注意力测试" Height="633.859" Width="530.511" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
    <Grid Margin="0,0,0,34">
        <Grid HorizontalAlignment="Left" Margin="0,68,0,-24" Width="523">
            <Button Name="btn11" Content="" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn11_Click" />
            <Button Name="btn12" Content="" HorizontalAlignment="Left" Margin="110,10,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn12_Click"/>
            <Button Name="btn13" Content="" HorizontalAlignment="Left" Margin="210,10,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn13_Click"/>
            <Button Name="btn14" Content="" HorizontalAlignment="Left" Margin="310,10,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn14_Click"/>
            <Button Name="btn15" Content="" HorizontalAlignment="Left" Margin="410,10,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn15_Click"/>
            <Button Name="btn21" Content="" HorizontalAlignment="Left" Margin="10,110,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn21_Click" />
            <Button Name="btn22" Content="" HorizontalAlignment="Left" Margin="110,110,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn22_Click"/>
            <Button Name="btn23" Content="" HorizontalAlignment="Left" Margin="210,110,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn23_Click"/>
            <Button Name="btn24" Content="" HorizontalAlignment="Left" Margin="310,110,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn24_Click"/>
            <Button Name="btn25" Content="" HorizontalAlignment="Left" Margin="410,110,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn25_Click"/>
            <Button Name="btn31" Content="" HorizontalAlignment="Left" Margin="10,210,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn31_Click"/>
            <Button Name="btn32" Content="" HorizontalAlignment="Left" Margin="110,210,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn32_Click"/>
            <Button Name="btn33" Content="" HorizontalAlignment="Left" Margin="210,210,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn33_Click"/>
            <Button Name="btn34" Content="" HorizontalAlignment="Left" Margin="310,210,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn34_Click"/>
            <Button Name="btn35" Content="" HorizontalAlignment="Left" Margin="410,210,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn35_Click"/>
            <Button Name="btn41" Content="" HorizontalAlignment="Left" Margin="10,310,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn41_Click"/>
            <Button Name="btn42" Content="" HorizontalAlignment="Left" Margin="110,310,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn42_Click"/>
            <Button Name="btn43" Content="" HorizontalAlignment="Left" Margin="210,310,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn43_Click"/>
            <Button Name="btn44" Content="" HorizontalAlignment="Left" Margin="310,310,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn44_Click"/>
            <Button Name="btn45" Content="" HorizontalAlignment="Left" Margin="410,310,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn45_Click"/>
            <Button Name="btn51" Content="" HorizontalAlignment="Left" Margin="10,410,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn51_Click"  />
            <Button Name="btn52" Content="" HorizontalAlignment="Left" Margin="110,410,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn52_Click"/>
            <Button Name="btn53" Content="" HorizontalAlignment="Left" Margin="210,410,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn53_Click"/>
            <Button Name="btn54" Content="" HorizontalAlignment="Left" Margin="310,410,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn54_Click"/>
            <Button Name="btn55" Content="" HorizontalAlignment="Left" Margin="410,410,0,0" VerticalAlignment="Top" Width="100" Height="100" FontSize="72" Click="btn55_Click"/>
        </Grid>
        <Button Content="耗时说明" Name="Instruments" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="82" Height="52" FontSize="16" Click="Instruments_Click"/>
        <Label Content="用时:" HorizontalAlignment="Left" Margin="255,12,0,0" VerticalAlignment="Top" Width="69" Height="40" TextOptions.TextHintingMode="Fixed" FontSize="20"/>
        <Label Content="." HorizontalAlignment="Left" Margin="388,12,0,0" VerticalAlignment="Top" Width="18" FontSize="20"/>
        <Label Content="秒" HorizontalAlignment="Left" Margin="453,12,0,0" VerticalAlignment="Top" Width="51" FontSize="20"/>
        <Button Content="开始" Name="btnStart" HorizontalAlignment="Left" Margin="111,10,0,0" VerticalAlignment="Top" Width="98" Height="52" FontSize="16" Click="btnStart_Click"/>
        <Label Content="0" HorizontalContentAlignment="Right" Name="lbSecond" HorizontalAlignment="Left" Margin="335,12,0,0" VerticalAlignment="Top" Height="40" Width="52" FontSize="20"  />
        <Label Content="0" HorizontalContentAlignment="Left" x:Name="lbMillSecond" HorizontalAlignment="Left" Margin="408,12,0,0" VerticalAlignment="Top" Height="40" Width="26" FontSize="20"/>

    </Grid>
</Window>
相应的cs实现代码为:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using WpfApplication1;

namespace TestYourConcentration
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public int II;//属性,控制0到25;
        string[] strArray = new string[25];
       
        int[] globalArray = new int[25];

        string strL1 = "超常:  0~10s   注意力高度集中且反应超级迅速;\n再来一次吧!";
        string strL2 = "A 等:  10~15s  注意力高度集中且反应迅速;\n再来一次吧!";
        string strL3 = "B 等:  15~20s  注意力集中且反应灵敏;\n再来一次吧!";
        string strL4 = "C 等:  20~25s  注意力和反应正常;\n再来一次吧!";
        string strL5 = "D 等:  25~30s  注意力不够集中且反应滞后;\n再来一次吧!";
        string strL6 = "E 等:  30~35s  注意力发散且反应迟缓;\n再来一次吧!";
        string strL7 = "失常:  35s~     需接受治疗;\n再来一次吧!";
        public MainWindow()
        {
            InitializeComponent();
        }

        int globalIndex = 0;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            II = 0;

            int[] array = new int[25];

            lbMillSecond.Foreground = Brushes.Red;//更改label的文本的颜色
            lbSecond.Foreground = Brushes.Red;

            Random r = new Random();

            /******************随机产生1~25且不重复的数字,存储进array数组******************/
            for (int i = 0; i < 5; ++i)
                for (int j = 0; j < 5; j++)
                {
                    int temp = r.Next(1, 26);
                    while (!array.Contains(temp))//如果数组不包含该元素
                    {
                        array[i * 5 + j] = temp;
                    }
                    while (array.Contains(temp))//如果已经包含该元素
                    {
                        temp = r.Next(1, 26);//重新生成随机数
                        if (!array.Contains(temp))//如果重新生成的随机数不存在
                        {
                            array[i * 5 + j] = temp;
                            break;
                        }
                        else //重新生成的随机数已经存在
                            continue;
                    }
                }
            Array.Copy(array, globalArray, array.Length);

            //给按钮赋值
            btn11.Content = array[0]; 
            btn12.Content = array[1]; 
            btn13.Content = array[2]; 
            btn14.Content = array[3]; 
            btn15.Content = array[4]; 
            btn21.Content = array[5]; 
            btn22.Content = array[6]; 
            btn23.Content = array[7]; 
            btn24.Content = array[8]; 
            btn25.Content = array[9]; 
            btn31.Content = array[10];
            btn32.Content = array[11];
            btn33.Content = array[12];
            btn34.Content = array[13];
            btn35.Content = array[14];
            btn41.Content = array[15];
            btn42.Content = array[16];
            btn43.Content = array[17];
            btn44.Content = array[18];
            btn45.Content = array[19];
            btn51.Content = array[20];
            btn52.Content = array[21];
            btn53.Content = array[22];
            btn54.Content = array[23];
            btn55.Content = array[24];
       
            globalIndex = Array.IndexOf(array, 25);

            for (int i = 1,j=0; i <=25; i++)
            {
                strArray[j++] = Array.IndexOf(array, i).ToString();
                //strArray存储了从1到25的索引,例如1的索引是10,则btn31存储的就是1
            }

        }

        //为了便于管理计时器,在此设置为全局变量
        DispatcherTimer wpfTimer = new System.Windows.Threading.DispatcherTimer();

        int index = 100;//初始化一个索引的位置,值为除了0与24之间的数,防止意外

        int iRestartCount = 0;
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
          II = 0;

            int[] array = new int[25];
            if (btnStart.Content.ToString() == "重新开始")
            {
                /*************Add*************/
                //string strBtnName = "";
                Random r = new Random();

                //随机产生1~25且不重复的数字
                for (int i = 0; i < 5; ++i)
                    for (int j = 0; j < 5; j++)
                    {
                        int temp = r.Next(1, 26);
                        while (!array.Contains(temp))//如果数组不包含该元素
                        {
                            array[i * 5 + j] = temp;
                        }
                        while (array.Contains(temp))//如果已经包含该元素
                        {
                            temp = r.Next(1, 26);//重新生成随机数
                            if (!array.Contains(temp))//如果重新生成的随机数不存在
                            {
                                array[i * 5 + j] = temp;
                                break;
                            }
                            else //重新生成的随机数已经存在
                                continue;
                        }

                    }
                Array.Copy(array, globalArray, array.Length);

                //给按钮赋值
                btn11.Content = array[0]; 
                btn12.Content = array[1]; 
                btn13.Content = array[2]; 
                btn14.Content = array[3]; 
                btn15.Content = array[4]; 
                btn21.Content = array[5]; 
                btn22.Content = array[6]; 
                btn23.Content = array[7]; 
                btn24.Content = array[8]; 
                btn25.Content = array[9]; 
                btn31.Content = array[10];
                btn32.Content = array[11];
                btn33.Content = array[12];
                btn34.Content = array[13];
                btn35.Content = array[14];
                btn41.Content = array[15];
                btn42.Content = array[16];
                btn43.Content = array[17];
                btn44.Content = array[18];
                btn45.Content = array[19];
                btn51.Content = array[20];
                btn52.Content = array[21];
                btn53.Content = array[22];
                btn54.Content = array[23];
                btn55.Content = array[24];
                
                globalIndex = Array.IndexOf(array, 25);

                for (int i = 1, j = 0; i <= 25; i++)
                {
                    strArray[j++] = Array.IndexOf(array, i).ToString();
                    //strArray存储了从1到25的索引,例如1的索引是10,则btn31存储的就是1
                }

                /*************Add*************/

                iRestartCount++;//记录点击重新开始的次数

                //将开始的计时器关闭
                wpfTimer.Stop();
                wpfTimer.Tick -= new EventHandler(dispatcherTimer_Tick);

                //重新置为0
                second = 0;
                tick = 0;
                lbMillSecond.Content = "0";
                lbSecond.Content = "0";
                if (iRestartCount >= 1)
                {
                    wpfTimer.Tick -= new EventHandler(RestartDispatcherTimer_Tick);
                }

                //启用重新开始的计时器
                wpfTimer.Tick += new EventHandler(RestartDispatcherTimer_Tick);
                //wpfTimer.Interval = new TimeSpan(0, 0, 1);
                wpfTimer.Interval = TimeSpan.FromMilliseconds(100);//以毫秒为单位
                //wpfTimer.Interval = TimeSpan.FromSeconds(0.1);
                wpfTimer.Start();

            }

            if (btnStart.Content.ToString() == "开始")
            {
                wpfTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                wpfTimer.Interval = TimeSpan.FromMilliseconds(100);//以毫秒为单位
                wpfTimer.Start();
            }

            //只需要找到25,如果25被点击了,则停止计时
            index = globalIndex;//index记录了25的索引
            btnStart.Content = "重新开始";
        }


        int second = 0;
        int tick = 0;
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            tick++;
            lbMillSecond.Content = tick;

            if ((tick != 0) && (Convert.ToInt32(tick) % 9 == 0))
            {
                second++;
                lbSecond.Content = second;
                tick = 0;
            }
        }

        private void RestartDispatcherTimer_Tick(object sender, EventArgs e)
        {
            tick++;
            lbMillSecond.Content = tick;

            if ((tick != 0) && (Convert.ToInt32(tick) % 9 == 0))
            {
                second++;
                lbSecond.Content = second;
                tick = 0;
            }
        }


        /********************循环判断25是否被点击***********************/
        private void btn11_Click(object sender, RoutedEventArgs e)
        {
            if(II==globalArray[0]-1)
            {
                II++;
                if (index == 0)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
           
        }

        private void btn12_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[1] - 1)
            {
                II++;
                if (index == 1)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
            
        }

        private void btn13_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[2] - 1)
            {
                II++;
                if (index == 2)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }

        }

        private void btn14_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[3] - 1)
            {
                II++;
                if (index == 3)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn15_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[4] - 1)
            {
                II++;
                if (index == 4)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn21_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[5] - 1)
            {
                II++;
                if (index == 5)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn22_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[6] - 1)
            {
                II++;
                if (index == 6)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn23_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[7] - 1)
            {
                II++;
                if (index == 7)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn24_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[8] - 1)
            {
                II++;
                if (index == 8)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }

        }

        private void btn25_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[9] - 1)
            {
                II++;
                if (index == 9)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn31_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[10] - 1)
            {
                II++;
                if (index == 10)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn32_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[11] - 1)
            {
                II++;
                if (index == 11)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn33_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[12] - 1)
            {
                II++;
                if (index == 12)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn34_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[13] - 1)
            {
                II++;
                if (index == 13)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn35_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[14] - 1)
            {
                II++;
                if (index == 14)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn41_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[15] - 1)
            {
                II++;
                if (index == 15)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn42_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[16] - 1)
            {
                II++;
                if (index == 16)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn43_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[17] - 1)
            {
                II++;
                if (index == 17)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }

        }

        private void btn44_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[18] - 1)
            {
                II++;
                if (index == 18)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn45_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[19] - 1)
            {
                II++;
                if (index == 19)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn51_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[20] - 1)
            {
                II++;
                if (index == 20)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn52_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[21] - 1)
            {
                II++;
                if (index == 21)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn53_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[22] - 1)//点对按钮了
            {
                II++;
                if (index == 22)//如果是25
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn54_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[23] - 1)
            {
                II++;
                if (index == 23)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void btn55_Click(object sender, RoutedEventArgs e)
        {
            if (II == globalArray[24] - 1)
            {
                II++;
                if (index == 24)
                {
                    wpfTimer.Stop();
                    ShowScore(lbSecond.Content.ToString(), lbMillSecond.Content.ToString());
                }
            }
            else
            {
                ChangeColClass ccc = new ChangeColClass();
                ccc.SetSourceColor(sender);
                ccc.errorCC(sender);
            }
        }

        private void Instruments_Click(object sender, RoutedEventArgs e)
        {
            ScoreInstructionWindow siw = new ScoreInstructionWindow();
            siw.Show();
        }

        
        /// <summary>
        /// 封装了一个显示成绩的方法
        /// </summary>
        /// <param name="strSec">传入的秒数</param>
        /// <param name="strMillSec">传入的毫秒数</param>
        public void ShowScore(string strSec,string strMillSec)
        {
            double timeConsume = Convert.ToInt32(strSec) + Convert.ToInt32(strMillSec) * 1.0 / 10.0;

            if (timeConsume >= 0 && timeConsume <= 10.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL1,"说明");
            }
            else if (timeConsume > 10.0 && timeConsume <= 15.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL2, "说明");
            }
            else if (timeConsume > 15.0 && timeConsume <= 20.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL3, "说明");
            }
            else if (timeConsume > 20.0 && timeConsume <= 25.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL4, "说明");
            }
            else if (timeConsume > 25.0 && timeConsume <= 30.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL5, "说明");
            }
            else if (timeConsume > 30.0 && timeConsume <= 35.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL6, "说明");
            }
            else if (timeConsume > 35.0)
            {
                MessageBox.Show("耗时:" + lbSecond.Content + "秒" + lbMillSecond.Content + "毫秒" + "\n本次成绩说明:\n" + strL7, "说明");
            }
            else
            {
                MessageBox.Show("未知错误!\n请联系程序作者!");
            }
        }
      
    }
}
运行效果如下图:

点错了会闪现红色

从1点到25才能结束,并弹出成绩说明



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值