vba [vba] 가위, 바위, 보 게임
페이지 정보
본문
지식인 답변하면서 잠깐 만들어 봤습니다.
기획력이 부족해서 ....
Option Explicit
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Const TIMER_INTERVAL As Long = 100
Const TIMER_ID As Long = 3100
Private rndValues As Variant
Private userValue As Integer
Private comIndex As Integer
Private myValue As Integer
Private Sub tmMethod()
'INTERVAL = 100 이므로 10회 당 약 1초
'// 타이머의 정확도는 INTERVAL과 tmMethod 진입 횟수로 조절
End Sub
Private Sub okMethod()
Stop_Timer
Dim comValue As Integer
Dim ckValue As Integer
comIndex = comIndex + 1
comValue = rndValues(comIndex)
Select Case userValue
Case 1
Select Case comValue
Case 1: ckValue = 1
Case 2: ckValue = 3
Case 3: ckValue = 2
End Select
Case 2
Select Case comValue
Case 1: ckValue = 2
Case 2: ckValue = 1
Case 3: ckValue = 3
End Select
Case 3
Select Case comValue
Case 1: ckValue = 3
Case 2: ckValue = 2
Case 3: ckValue = 1
End Select
End Select
If ckValue = 2 Then myValue = myValue + 1
Label1.Caption = Choose(ckValue, "무", "승", "패")
Label2.Caption = Choose(comValue, "가위", "바위", "보")
Caption = comIndex & "회 승률 " & Format((myValue / comIndex) * 100, "0.00""%""")
cmdEnabled
End Sub
Private Sub CommandButton1_Click()
ReDim rndValues(1 To 45)
Dim i As Integer, n As Integer, x As Integer
For i = 1 To 3
For n = 1 To 15
x = x + 1
rndValues(x) = i
Next
Next
rndValues = RandData(rndValues): rndValues = RandData(rndValues)
comIndex = 0: myValue = 0: cmdEnabled
' Start_Timer '// 사용자의 입력을 체크할려면 타이머를 이용
End Sub
Private Sub cmdEnabled()
CommandButton2.Enabled = comIndex < 45
CommandButton3.Enabled = comIndex < 45
CommandButton4.Enabled = comIndex < 45
End Sub
Function RandData(ByVal dv As Variant) As Variant
Dim j As Long, t As Variant, i As Long
For i = UBound(dv) To LBound(dv) Step -1
j = Application.RandBetween(LBound(dv), UBound(dv))
t = dv(i): dv(i) = dv(j): dv(j) = t
Next
RandData = dv
End Function
Private Sub CommandButton2_Click(): userValue = 1: okMethod: End Sub
Private Sub CommandButton3_Click(): userValue = 2: okMethod: End Sub
Private Sub CommandButton4_Click(): userValue = 3: okMethod: End Sub
Sub Start_Timer()
Stop_Timer
SetTimer Application.hWnd, TIMER_ID, TIMER_INTERVAL, AddressOf tmMethod
End Sub
Sub Stop_Timer()
KillTimer Application.hWnd, TIMER_ID
Application.StatusBar = False
End Sub
첨부파일
-
가이바이보.xlsm (812.1K)
0회 다운로드 | DATE : 2022-10-16 18:20:52
- 이전글[vba] Outlook 현재 활성화된 창의 제목 및 내용을 가져오는 방법 23.07.10
- 다음글[vba] 활성화된 엑셀창의 선택한 셀(Selection) / Selection 오류시 / TextBox를 활용한 지정한 영역 한글자씩 입력받기 22.10.16
댓글목록
등록된 댓글이 없습니다.