丁半とは、さいころ二つを振って、その目の合計が偶数か奇数かを当てるゲームです。
まずは簡単な部分を作ってみましょう。
利用するのは、InputBox()関数、Rnd()関数、Mod演算子、If文、出力といったところです。
大雑把な手順はおよそ次のようになります(あくまでも例ですが)。
Randomize
user = Val(InputBox("予想が偶数ならば「0」を、奇数ならば「1」を入力してください"))
d1 = Int(Rnd(1) * 6 + 1)
d2 = Int(Rnd(1) * 6 + 1)
total = d1 + d2
amari = total Mod 2
If (user = 0 And amari = 0) Or (user = 1 And amari = 1) Then
Label1.Caption = "当たり"
Else
Label1.Caption = "外れ"
End If
Label2.Caption = d1
Label3.Caption = d2
Label4.Caption = total
Randomize
user = Val(InputBox("予想が偶数ならば「0」を、奇数ならば「1」を入力してください"))
d1 = Int(Rnd(1) * 6 + 1)
d2 = Int(Rnd(1) * 6 + 1)
total = d1 + d2
amari = total Mod 2
If (user = amari) Then
Label1.Caption = "当たり"
Else
Label1.Caption = "外れ"
End If
Label2.Caption = d1
Label3.Caption = d2
Label4.Caption = total
Randomize
user = Val(InputBox("予想が偶数ならば「0」を、奇数ならば「1」を入力してください"))
d1 = Int(Rnd(1) * 6 + 1)
d2 = Int(Rnd(1) * 6 + 1)
total = d1 + d2
amari = total Mod 2
If (user = 0 And amari = 0) Or (user = 1 And amari = 1) Then
Label1.Caption = "当たり"
Else
Label1.Caption = "外れ"
End If
Label2.Caption = d1
Label3.Caption = d2
Label4.Caption = total
Label2.Caption = d1
Label3.Caption = d2
Label4.Caption = total
If (user = 0) Then
Label5.Caption = "あながが予想したのは「偶数」"
Else
Label5.Caption = "あなたが予想したのは「奇数」"
End If
If (amari = 0) Then
Label6.Caption = "さいころは「偶数」"
Else
Label6.Caption = "さいころは「奇数」"
End If
Randomize
user = Val(InputBox("予想が偶数ならば「0」を、奇数ならば「1」を入力してください"))
d1 = Int(Rnd(1) * 6 + 1)
d2 = Int(Rnd(1) * 6 + 1)
total = d1 + d2
amari = total Mod 2
If (user = 0) Then
Label5.Caption = "あながが予想したのは「偶数」"
If (amari = 0) Then
Label1.Caption = "当たり"
Label6.Caption = "さいころは「偶数」"
Else
Label1.Caption = "外れ"
Label6.Caption = "さいころは「奇数」"
End If
Else
Label5.Caption = "あなたが予想したのは「奇数」"
If (amari = 0) Then
Label1.Caption = "外れ"
Label6.Caption = "さいころは「偶数」"
Else
Label1.Caption = "当たり"
Label6.Caption = "さいころは「奇数」"
End If
End If
Label2.Caption = d1
Label3.Caption = d2
Label4.Caption = total