我正在尝试为 Windows Phone 8 开发一个简单的 SimonSays 应用程序。
为了使序列对用户可见,我使用了一个tasti
填充了键索引的数组 (),以及一个for
检查数组并使按钮变暗的循环。
我写了这段代码:
int livello = 1;
double opac = 0.3;
void IniziaGioco()
{
DispatcherTimer timer5 = new DispatcherTimer();
timer5.Interval = new TimeSpan(0, 0, 0, 1);
timer5.Start();
for (int i = 0; i < livello; i++)
{
switch (tasti[i])
{
case 1:
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
timer.Tick += new EventHandler(DiventaOpaco1);
Button1.Opacity = opac;
SuonoBottone1.Play();
timer.Start();
timer5.Start();
break;
case 2:
DispatcherTimer timer2 = new DispatcherTimer();
timer2.Interval = new TimeSpan(0, 0, 0, 0, 300);
timer2.Tick += new EventHandler(DiventaOpaco2);
Button2.Opacity = opac;
SuonoBottone2.Play();
timer2.Start();
timer5.Start();
break;
case 3:
DispatcherTimer timer3 = new DispatcherTimer();
timer3.Interval = new TimeSpan(0, 0, 0, 0, 300);
timer3.Tick += new EventHandler(DiventaOpaco3);
Button3.Opacity = opac;
SuonoBottone3.Play();
timer3.Start();
timer5.Start();
break;
case 4:
DispatcherTimer timer4 = new DispatcherTimer();
timer4.Interval = new TimeSpan(0, 0, 0, 0, 300);
timer4.Tick += new EventHandler(DiventaOpaco4);
Button4.Opacity = opac;
SuonoBottone4.Play();
timer4.Start();
timer5.Start();
break;
}
}
timer1
timer2
timer3
并timer4
以正确的方式正常工作并调暗按钮。
我想用timer5
它来让我的代码在使下一个按钮变暗之前“等待”1秒钟,但它不起作用,因为按钮同时变暗。
计时器是最好的方法吗?如何使我的代码工作?