﻿version
5.80
0
chessclock
1
5
0
0
0
16
0
0
7
1
0
0
1
1
0
0
0
0
0
0
238
268

0
0
0
Sub designer




addform(chessclock,"Chess Clock","",255,255,0)@
addnum(chessclock,starttime,165,45,60,5,120,255,255,255,True,True)@
addbutton(chessclock,ResetButton,20,235,200,23,"RESET",212,208,200,0,0,0,True,True,9)@
addlabel(chessclock,Tens2,205,195,25,35,"0",255,255,0,0,0,0,True,True,16)@
addlabel(chessclock,Secs2,160,195,50,40,"00",255,255,0,0,0,0,True,True,20)@
addlabel(chessclock,Mins2,110,195,50,40,"05",255,255,0,0,0,0,True,True,20)@
addlabel(chessclock,Hours2,60,195,50,40,"00",255,255,0,0,0,0,True,True,20)@
addlabel(chessclock,Tens,150,5,25,35,"0",255,255,0,0,0,0,True,True,16)@
addlabel(chessclock,Secs,105,5,50,40,"00",255,255,0,0,0,0,True,True,20)@
addlabel(chessclock,Mins,55,5,50,40,"05",255,255,0,0,0,0,True,True,20)@
addlabel(chessclock,Hours,5,5,50,40,"00",255,255,0,0,0,0,True,True,20)@
addtimer(chessclock,Timer1,2,3,100)@
addbutton(chessclock,P2Button,125,115,105,75,"P2",255,0,0,0,0,0,True,True,15)@
addbutton(chessclock,P1Button,10,45,105,75,"P1",0,255,128,0,0,0,True,True,15)@
End Sub
@EndOfDesignText@Sub Globals
	Turn=0
	running=false
End Sub

Sub App_Start
 Sip(False)
 Reset
 chessclock.show
End Sub

Sub P1Button_Click
 If turn=1 AND running Then
 	Turn=2
 	P1Button.Color=cGray
 	P2Button.Color=cPink
 Else
 	If turn=1 Then
  		Timer1.Enabled=True
 		ResetButton.Text="PAUSE"
 		starttime.Visible=false
	 	P1Button.Color=cCyan
		running=true
	End If
 End If
End Sub

Sub P2Button_Click
 If (turn=2 AND running) Then
 	Turn=1
 	P2Button.Color=cGray
 	P1Button.Color=cCyan
 Else
	If turn<>1 Then
  		Timer1.Enabled=True
 		ResetButton.Text="PAUSE"
 		starttime.Visible=false
		running=true
		If turn=0 Then
		 	Turn=1
 			P2Button.Color=cGray
 			P1Button.Color=cCyan
		Else
		 	P2Button.Color=cPink
		End If
	End If
 End If
End Sub

Sub Timer1_Tick
  If Turn=1 Then P1Run Else P2Run
End Sub

Sub P1Run
 If Tens.Text>0 Then
  Tens.Text=Tens.Text-1
 Else
   If Secs.Text>0 Then
   	Tens.Text="9":Secs.Text=Format(Secs.Text-1,"D2")
   Else
   	If Mins.Text>0 Then
		Tens.Text="9":Secs.Text="59":Mins.Text=Format(Mins.Text-1,"D2")
   	Else
    	If Hours.Text>0 Then
			Tens.Text="9":Secs.Text="59":Mins.Text="59":Hours.Text=Format(Hours.Text-1,"D2")
		Else
			StopRunning
			Msgbox("P1 Game Over")
			Sound("Notify.wav")
   		End If
	End If
   End If
 End If
End Sub

Sub P2Run
 If Tens2.Text>0 Then
  Tens2.Text=Tens2.Text-1
 Else
   If Secs2.Text>0 Then
   	Tens2.Text="9":Secs2.Text=Format(Secs2.Text-1,"D2")
   Else
   	If Mins2.Text>0 Then
		Tens2.Text="9":Secs2.Text="59":Mins2.Text=Format(Mins2.Text-1,"D2")
   	Else
    	If Hours2.Text>0 Then
			Tens2.Text="9":Secs2.Text="59":Mins2.Text="59":Hours2.Text=Format(Hours2.Text-1,"D2")
		Else
			StopRunning
			Msgbox("P2 Game Over")
			Sound("Notify.wav")
   		End If
	End If
   End If
 End If
End Sub

Sub StopRunning
    Timer1.Enabled=False
    running=false
    starttime.Visible=true
	ResetButton.Text="RESET"
End Sub

Sub Reset
 h=Int(starttime.Value/60)
 m=starttime.Value Mod 60

 Tens.Text="0"
 Secs.Text="00"
 Mins.Text=Format(m,"D2")
 Hours.Text=Format(h,"D2")

 Tens2.Text="0"
 Secs2.Text="00"
 Mins2.Text=Format(m,"D2")
 Hours2.Text=Format(h,"D2")
 
 P1Button.Color=cGray
 P2Button.Color=cPink
 Turn=0
End Sub

Sub ResetButton_Click
  If ResetButton.Text="PAUSE" Then
  	StopRunning
	If turn=1 Then P1Button.Color=cRed Else P2Button.Color=cRed
  Else
    Reset
  End If
End Sub