1. 程式人生 > >20150616完 一個測試注意力的小程式

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才能結束,並彈出成績說明