Page 1 of 1

Game Clock DLL

Posted: Sun Jun 02, 2013 11:30 pm
by netmaestro
This is an oldschool analog chess clock, usable in any game that times the players.

Code: Select all

Import "chessclock.lib"
  CreateGameClock(a,b,c)
  CloseGameClock()
  PressClock(player)
EndImport

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(1, 30,210,80,20,"Pause")
ButtonGadget(2, 120,210,80,20,"Press White")
ButtonGadget(3, 210,210,80,20,"Press Black ")

CreateGameClock(WindowID(0),10,10)

pressclock(0)

Repeat
  EventID = WaitWindowEvent()
  Select EventID
    Case #PB_Event_CloseWindow
      If EventWindow()=0
        CloseWindow(0)
      EndIf
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          PressClock(0) ; Idle
        Case 2
          PressClock(1) ; White
        Case 3
          PressClock(2) ; Black
      EndSelect
    
  EndSelect
  
Until EventID=16

End
There's no time controls programmed into it at this point. Game in five minutes is what it sets itself to. There will be an infinite number of possibilities in setting it, with primary, secondary and tertiary time controls all selectable with your choice of moves for each time period.
For example, a common time control would be 40 moves in 2 hours followed by 20 moves in one hour followed by all remaining moves in one hour. Or, all moves in a given number of minutes, say 10 for each side or maybe 10 for one side and 5 for the stronger player. All I'm doing right now is getting feedback and identifying bugs. If you can try it out and help with that, it's much appreciated.

Here's the library:
http://www.lloydsplace.com/chessclock.dll
http://www.lloydsplace.com/chessclock.lib

Please let me know of any bugs or issues if you find them.

Re: Game Clock DLL

Posted: Mon Jun 03, 2013 2:43 pm
by ebs
netmaestro,

Very nice! I found one thing: Running PB 5.11 on Windows XP, I get this error when closing the window:

---------------------------
Purebasic13.exe - Application Error
---------------------------
The instruction at "0x100030f5" referenced memory at "0x0103ef18". The memory could not be "read".


Click on OK to terminate the program
---------------------------
OK
---------------------------

Regards,
Eric

Re: Game Clock DLL

Posted: Mon Jun 03, 2013 9:28 pm
by buddymatkona
It works great with Win7/64 5.11 (PB x86 only). :)

Re: Game Clock DLL

Posted: Mon Jun 03, 2013 9:28 pm
by davido
netmaestro: Is this only for x86.

It gives errors on my W7-64 PB511-64 system:

POLINK: error: Unresolved external symbol 'CreateGameClock'.
POLINK: error: Unresolved external symbol 'PressClock'.
POLINK: falal error: 2 unresolved externals().


1st edit:
buddymatkona: Thank you for your reply. Now I know!

Re: Game Clock DLL

Posted: Tue Jun 04, 2013 2:36 am
by citystate
if it was compiled under x86, it will only work with x86

any chance of a recompile for 64, nm?

Re: Game Clock DLL

Posted: Wed Jun 05, 2013 12:40 am
by netmaestro
Another upload will come tomorrow. I'll implement a CloseGameClock function to see if that helps with the ima on closing the window and I will also include a version targeting 64bit.

Re: Game Clock DLL

Posted: Thu Jun 13, 2013 10:37 am
by Kwai chang caine
No world to say ..... nearly i can touch it :shock:
Thanks a lot NetMaster 8)

Re: Game Clock DLL

Posted: Sat Jun 15, 2013 4:21 am
by Nituvious
I don't think this is correct...
It says it took me over 24 hours to solve my rubiks cube but when I looked out my window the sun was still shining!

Nice work, net! :P