✔ 最佳答案
我沒有 pascal compiler, 就用 excel 的 vba 為你寫了這個 game. 程式如下:
Sub Macro1()
'
'
'
Range("a1:a30").ClearContents
Randomize
n = Int(Rnd() * 30) + 10
ar = 1
Cells(ar, 1) = "There are " & n & " matches."
ar = ar + 1
rep:
x = InputBox("How many matches (should be either 1 or 2) do you pick?")
If Not (x = 1 Or x = 2) Then GoTo rep
If n > 0 Then
r = n - x
Else
Cells(ar, 1) = "You lose."
End
End If
Cells(ar, 1) = "You pick " & x & " match(es). There are/is " & r & " match(es) left."
ar = ar + 1
If r <= 1 Then
Cells(ar, 1) = "You win."
End
End If
p = r Mod 3
If p = 0 Then
p = 2
GoTo rep1
End If
If p = 2 Then
p = 1
GoTo rep1
End If
If p = 1 Then p = WorksheetFunction.Min(Int(Rnd() * 2) + 1, r)
rep1:
n = r - p
Cells(ar, 1) = "The computer picks " & p & " match(es). There are/is " & n & " match(es) left."
ar = ar + 1
If n <= 1 Then
Cells(ar, 1) = "The computer wins."
End
End If
GoTo rep
End Sub
因 program 沒有太多 vba 的 特別 object, 要轉 pascal 也不會太難.
如想要這個 excel file, 可 e-mail 給我.