Little Bonus: Just Like Chess Clock...
1. Create new workbook.
2. Create new VBA-module .
3. Copy VBA-code below and then paste it into module.
4. Activate any worksheet in your new workbook.
5. Press Alt+F8 and run macro "setCountdownTimers".
6. Use Ctrl+F1 as stopper for "left player" (player 1) - this key will stop player1 clock and run player2 clock.
7. Use Ctrl+F12 as stopper for "right player" (player 2) - this key will stop player2 clock and run player1 clock.
8. Use any of these two combinations of keys for restarting the game after the previous game is over.
9. After final "game" press Alt+F8 and run macro "restoreKeys" to return Ctrl+F1 and Ctrl+F12 to theirs normal Excel meanings.
PHP:
Dim isFirstEntry1 As Boolean
Dim isFirstEntry2 As Boolean
Sub setCountdownTimers()
Cells.Interior.ColorIndex = xlNone
Range("A1").Value = "Player 1"
Range("C1").Value = "Player 2"
Range("A2").Value = 10
Range("B2").Value = "<=>"
Range("C2").Value = 10
Range("B2").NumberFormat = "@"
Range("A1:C2").HorizontalAlignment = xlCenter
Application.OnKey "^{F1}", "keyPressedByPlayer1"
Application.OnKey "^{F12}", "keyPressedByPlayer2"
End Sub
Sub keyPressedByPlayer2()
If InStr(Range("B2").Value, "Loser") > 0 Then
Call setCountdownTimers
Exit Sub
End If
If Range("B2").Value <> "<=" Then
Range("B2").Value = "<="
Range("B2").HorizontalAlignment = xlLeft
isFirstEntry1 = True
Call runPlayer1
End If
End Sub
Sub keyPressedByPlayer1()
If InStr(Range("B2").Value, "Loser") > 0 Then
Call setCountdownTimers
Exit Sub
End If
If Range("B2").Value <> "=>" Then
Range("B2").Value = "=>"
Range("B2").HorizontalAlignment = xlRight
isFirstEntry2 = True
Call runPlayer2
End If
End Sub
Sub runPlayer1()
If Range("B2").Value = "<=" Then
If Range("A2").Value > 0 Then
Application.OnTime Now + TimeValue("00:00:01"), "runPlayer1"
If Not isFirstEntry1 Then
Range("A2").Value = Range("A2").Value - 1
Else
isFirstEntry1 = False
End If
Else
Cells.Interior.ColorIndex = 6 'Yellow '
Range("B2").Value = "<= Loser"
End If
End If
End Sub
Sub runPlayer2()
If Range("B2").Value = "=>" Then
If Range("C2").Value > 0 Then
Application.OnTime Now + TimeValue("00:00:01"), "runPlayer2"
If Not isFirstEntry2 Then
Range("C2").Value = Range("C2").Value - 1
Else
isFirstEntry2 = False
End If
Else
Cells.Interior.ColorIndex = 3 'Red '
Range("B2").Value = "Loser =>"
End If
End If
End Sub
Sub restoreKeys()
Application.OnKey "^{F1}"
Application.OnKey "^{F12}"
End Sub