0

저는 Visual Basic 2010에서 슬롯 머신을 에뮬레이션하는 프로그램이 있습니다.계속하기 위해 타이머가 끝날 때까지 대기

먼저 1에서 9까지 3 개의 난수를 생성하고 "회전"을 시뮬레이션하고 싶을 때 슬롯 머신의 이미지가 화면에 나타나는 루프를 통과하기로 결정했습니다. 이 루프가 끝나면 사용자는 1 ~ 9 개의 숫자가 생성 된 해당 그림을 가져와야합니다.

그래서 가장 좋은 아이디어는 타이머를 설정하고 예를 들어 100 간격을두고 시작하고 각 틱마다 화면의 임의의 이미지를 표시하는 것입니다.

그러나 타이머를 시작하면 호출되는 주 기능과 평행을 이루는 것처럼 보입니다. XD가 유익한 지 모르겠습니다. 자신에 대한 더 나은 모습 :

'CALCULATE WINNING RESULT 
valor1 = GeneraAleatorio(1, 9) -> This custom function returns a random number 
valor2 = GeneraAleatorio(1, 9) 
valor3 = GeneraAleatorio(1, 9) 

Timer1.Enabled = True 

'NOW I PUT THE WINNING PICTURES THAT CORRESPOND WITH THE NUMBERS 
ColocaImagen(1, valor1) -> Another custom made function, takes the position (1 to 3) and an image (1 to 9) 
ColocaImagen(2, valor2) 
ColocaImagen(3, valor3) 

'END GAME 
End()   -> or whatever 

내 timer_tick 기능이 있습니다 :

내가 = 사실 timer1.enabled를 호출 할 때,이 두 가지를 계속 보인다
If tiempo >= 4000 Then 
     Timer1.Enabled = False  ' -> To make it stop when it reaches 4000 (4 seconds) 

    ElseIf tiempo <= 3900 Then 

     ColocaImagen(1, GeneraAleatorio(1, 9)) 
     ColocaImagen(2, GeneraAleatorio(1, 9)) 
     ColocaImagen(3, GeneraAleatorio(1, 9)) 

     If tiempo >= ProgressBar.Minimum & tiempo <= ProgressBar.Maximum Then 
      ProgressBar.Value = tiempo   
     End If 

     tiempo = tiempo + 100     'Tiempo is "time" in Spanish, it increases 100 every 100ms 
    End If 

:이 프로그램은 틱 기능을 입력, 또한 타이머가 끝날 때까지 기다리지 않고 게임이 끝날 때까지갑니다.

것은 (Timer1.Enabled가) {} // 유지되지만 : 나는 다음 올바른 사진을 표시하고,이 시도 내가 원하는 작업을 실행 또는 MSGBOX 또는 뭔가

답변

0

그냥 서브 루틴을 만들 pinkfloydx33하고 통화가 타이머에 도달하면 4000 뭔가 있는지 확인 이게 너에게 도움이 될거야.

Public Class Form1 

    Dim valor1 As Integer 
    Dim valor2 As Integer 
    Dim valor3 As Integer 


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
     If Timer1.Enabled Then Exit Sub 
     'CALCULATE WINNING RESULT 
     valor1 = GeneraAleatorio(1, 9) 
     valor2 = GeneraAleatorio(1, 9) 
     valor3 = GeneraAleatorio(1, 9) 
     Timer1.Enabled = True 

    End Sub 

    Public Sub ShowFinalResult() 
     'NOW I PUT THE WINNING PICTURES THAT CORRESPOND WITH THE NUMBERS 
     ColocaImagen(1, valor1) 
     ColocaImagen(2, valor2) 
     ColocaImagen(3, valor3) 
    End Sub 

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick 
     Static tiempo As Integer 
     Timer1.Enabled = False 
     If tiempo >= 4000 Then 
      tiempo = 0 
      ShowFinalResult() 

     ElseIf tiempo <= 3900 Then 

      ColocaImagen(1, GeneraAleatorio(1, 9)) 
      ColocaImagen(2, GeneraAleatorio(1, 9)) 
      ColocaImagen(3, GeneraAleatorio(1, 9)) 

      tiempo = tiempo + 100 

      If tiempo >= ProgressBar1.Minimum And tiempo <= ProgressBar1.Maximum Then ProgressBar1.Value = tiempo 

      Timer1.Enabled = True 
     End If 

    End Sub 

End Class 
+0

고마워! 나는 당신의 조언을 따르기로 결정했고, 플레이어가 승리했는지 여부 (어쩌면 나중에 포인트 제도로 바꿀 것입니다) 어떤 행동을하거나 다른 하위 칸을 부르십시오. – fernandopcg

+0

@fernandopcg 도움이되기를 기쁘게 생각합니다. –

0

을 보여주는 4 초 통과 할 타이머가 끝날 때까지 블로킹

'CALCULATE WINNING RESULT 
valor1 = GeneraAleatorio(1, 9) -> This custom function returns a random number 
valor2 = GeneraAleatorio(1, 9) 
valor3 = GeneraAleatorio(1, 9) 

Timer1.Enabled = True 

While (Timer1.Enabled) {} // Will keep blocking until the timer sets Enabled to false 

'NOW I PUT THE WINNING PICTURES THAT CORRESPOND WITH THE NUMBERS 
ColocaImagen(1, valor1) -> Another custom made function, takes the position (1 to 3) and an image (1 to 9) 
ColocaImagen(2, valor2) 
ColocaImagen(3, valor3) 

'END GAME 
End()   -> or whatever 

타이머를 시작해도 프로그램이 중지되고 대기하지 않습니다. 또한

:

그것의 내부 수면없이 CPU를 먹는 것 루프 동안

-

+1

while 루프는 – pinkfloydx33

+0

좋은 지적, 내가 내 대답에 그 메모를 만들려고 그 안에 절전없이 CPU를 먹을 것이다. 소품! –

+0

그래, 그건 그 CPU 사용을 제외하면 좋았을 텐데. (나는 타이머를 시작할 때 나의 기능을 끝내기로 결심했고 다른 것을 멈추기로 결정했다.) – fernandopcg

관련 문제