Chess Clock - 0.01
My chess clock broke, so I wrote a new one (for use with a laptop).
Sean J McKiernan
My chess clock broke so I wrote a new one.
It is intended to be used with a laptop. The buttons of the mouse pad are intended to serve as the two players' timer buttons.
- The clock supports both delay and increment timing options.
- Use the presets already loaded or create your own and save them.
- The left and right mouse buttons correspond to the two players.
- Hit spacebar one time to pause the timer. Resume by having the player who's turn it isn't hit his timer button (i.e. his mouse pad button).
- Reset the clock by pressing spacebar three times consecutively.
If you would like to modify the time-control hold spacebar for 2 seconds while the clock is in the reset state.
This will cause the first digit of each display to blink. Use the mouse buttons to modify the timer (each corresponding to its side of the display)
and press spacebar to change to the next digit. Once you have set all four digits you will be able to add delay and increment time if desired.
Once you have set all the digits to the desired state pressing spacebar again will return you to the starting state displaying the new time-control.
Loading and Saving Presets:
This program allows you to save up to ten custom presets. The presets are stored on the numbers 1-0 on your keyboard (not the keypad).
Simply press the number where your desired preset is stored while the clock is in its reset state and it will load that time-control.
To save your own custom preset, set the clock as described above in 'Setting' and then press and hold the number on which you would like to store that time-control.
After 2 seconds the display screens will flash and the new time-control will overwrite the previous time-control that was mapped to that key.
(There is a function in the program called "ChessClock.factory_reset" that will restore the original presets. To trigger this 'factory_reset' you must uncomment
the line calling this function within ChessClock's __init__ function. After the program has run remember to go back and recomment the line.)
To those of you not familiar with actual chess clocks the controls may seem odd.
I have written it as such mainly for two reasons. Firstly you do not want the clock to
be accidentally reset mid-game. And secondly, I modeled the controls off of a very common
type of chess clock that only has three buttons total (but a million features).
Also, I should mention that I did in fact write this program for my own use so I wanted the controls to be somewhat intuitive for other fellow chess players.
Pygame.org account Comments
josmiley 2011-12-22 15:26:23
500 lines ?
you would gain by using a font for the display ...
Mekire 2011-12-22 15:44:19
Most of the length is in getting the delay/increment logic and setting/preset saving to work as desired. I doubt using a font as opposed to a sheet would save that much.
Using the sprite sheet allows me to do things like use glowing digits and such that a font wouldn't if I desire.
Either way, I didn't try to make it short, only functional. I've never really seen the point in intentionally trying to make code as short as possible.