2016-06-20 3 views
0

내가 메모리 게임을 만들고 있어요를 재설정하고 나는 그들이 일치하지 않는 경우 드 이미지를 다시 타이머를 설정해야하지만, 다시 사진을 설정하는 작동하지 않습니다 숨겨진 :메모리 게임 타이머 카드

//set images 
if (clickedLabel != null) 
{ 
    var Index = Convert.ToInt32(clickedLabel.Tag); 
    clickedLabel.Image = icons[Index]; 

    //Check first clicked 
    if (firstClicked == null) 
    { 
     firstClicked = clickedLabel; 
     return; 
    } 

    secondClicked = clickedLabel; 

    timer1.Start(); 
} 

방법 timer1_Tick는 :

//Timer 
private void timer1_Tick(object sender, EventArgs e) 
{ 
    timer1.Stop(); 

    firstClicked = null; 
    secondClicked = null; 
} 
+0

* "문제가 해결되지 않았습니다"*는 적절한 문제 설명이 아닙니다. 작동하지 않는 것은 무엇입니까? 그것은 무엇을합니까, 그리고 당신이 그것을 기대했던 것과 어떻게 비교합니까? –

답변

0

이 작동 할 수 있습니다 :

class YourClass 
{ 
    System.Timers.Timer aTimer; 
    void YourMethod() 
    { 
     //code 
     if (clickedLabel != null) 
     { 
      var Index = Convert.ToInt32(clickedLabel.Tag); 
      clickedLabel.Image = icons[Index]; 

      //Check first clicked 
      if (firstClicked == null) 
      { 
      firstClicked = clickedLabel; 
      return; 
     } 

     secondClicked = clickedLabel; 

     SetTimer(); 
    } 

    private static void SetTimer() 
    { 
     //System.Timers.Timer aTimer; at the beginning of your class 
     aTimer = new System.Timers.Timer (2000); //the time you want in milliseconds 
     aTimer.Elapsed += OnTimedEvent; 
     aTimer.AutoReset = false; 
     aTimer.Enabled = true; 
    } 
} 

자동 리셋이 거짓 의지로 설정 Elapsed 이벤트 트리거를 한 번만 만듭니다. 그런 다음, 그 이벤트에서 원하는 것을하십시오.

private static void OnTimedEvent (Object source, ElapsedEventArgs e) 
{ 
    firstClicked = null; 
    secondClicked = null; 
} 

더 이상 필요하지 않을 때 aTimer에 중지 및 배출 방법을 사용할 수 있습니다.

또한 질문을 올릴 때 좀 더 구체적이어야하며 필요한 도움을 받아야합니다.

+0

어디에서 aTimer를 System.Timers.Timer aTimer에 넣어야합니까? 허용하지 않으므로 – Rexon222

+0

업데이트 된 답변보기 – YumeYume