Sponsored Content
Full Discussion: Simple Chess Clock
Top Forums Programming Simple Chess Clock Post 302928074 by wisecracker on Monday 8th of December 2014 05:58:36 PM
Old 12-08-2014
I must be mis-interpreting your requirement...
How about this?
Code:
timer=0
count=0
totaltime=0
# 1 second delay with keyboard override.
delay()
{
	read -n1 -s -t1 keyboard
}
read -p "Press any key to start:- " -n1
while true
do
	keyboard=""
	delay
	timer=$((timer+1))
	count=$((count+1))
	totaltime=$((totaltime+1))
	echo "Total elapsed time = $totaltime."
	if [ "$keyboard" == "q" ] || [ "$keyboard" == "Q" ]
	then
		echo "Quit..."
		exit 0
	fi
	if [ "$keyboard" == "r" ] || [ "$keyboard" == "R" ]
	then
		read -p "Reset! Press any key to start:- " -n1
		timer=0
		count=0
		totaltime=0
	fi
	if [ "$keyboard" == "s" ] || [ "$keyboard" == "S" ]
	then
		echo "Start timer..."
		count=$timer
		timer=0
	fi
	if [ "$keyboard" == "f" ] || [ "$keyboard" == "F" ]
	then
		echo "Finish timer..."
		echo "Number of seconds = $timer..."
		echo "Timer count = $count..."
		timer=0
	fi
done

Results:-
Code:
AMIGA:barrywalker~/Desktop/Code/Shell> ./timer.sh
Press any key to start:- 
Total elapsed time = 1.
Total elapsed time = 2.
Total elapsed time = 3.
Start timer...
Total elapsed time = 4.
Total elapsed time = 5.
Finish timer...
Number of seconds = 2...
Timer count = 5...
Total elapsed time = 6.
Total elapsed time = 7.
Total elapsed time = 8.
Start timer...
Total elapsed time = 9.
Total elapsed time = 10.
Total elapsed time = 11.
Total elapsed time = 12.
Total elapsed time = 13.
Finish timer...
Number of seconds = 5...
Timer count = 8...
Total elapsed time = 14.
Total elapsed time = 15.
Quit...
AMIGA:barrywalker~/Desktop/Code/Shell> _

 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

chess perl program questions

Hello guys, While going over the book, I ran into this chess program and I have few questions 1) on line 40), why is not $chessboard-> ) ??? 40 unless (defined $chessboard->) { 2) 20 foreach my $i (reverse (0..7)) { #Row 1 #!/usr/bin/perl -w 2 # 3 # 4 5 ... (1 Reply)
Discussion started by: hankooknara
1 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Chess at the UNIX Forums.

Just to let you know, we have installed Chess at the UNIX forums: Chess Club - The UNIX Forums (0 Replies)
Discussion started by: Neo
0 Replies

3. UNIX for Dummies Questions & Answers

A Simple Clock, Well Maybe Not That Simple...

The attachment says it all really... It is a DEMO at a glance digital readout using the "date" command to make it useful... For a Mocbook Pro 13", OSX 10.7.5, but may well work on Linux variants too. Enjoy... #!/bin/bash # # Clock.sh # A bash DEMO to create a 6 x 7 character set... (4 Replies)
Discussion started by: wisecracker
4 Replies

4. What is on Your Mind?

Chess Players: Which Online Resources (and Software) Do You Use and Why?

Hi Chess Players, Which Online Resources (and Software) Do You Use and Why? As for me, I use chessgames.com and chessbase.com; but currently I'm using chessgames.com the most; I like exploring openings in the chessgames.com opening explorer. For analysis on the desktop (Mac) or iPhone I... (8 Replies)
Discussion started by: Neo
8 Replies

5. What is on Your Mind?

How to Play Chess in Facebook Messenger

Have you ever wondered to play chess while you chat with your friends? Facebook has made this possible. FB keeps coming up with more and more new ideas for its users but this time it is a more intellectual one. Facebook has built a build-in-functionality in Facebook messenger, in which you just... (0 Replies)
Discussion started by: Neo
0 Replies
SDL_AddTimer(3) 						 SDL API Reference						   SDL_AddTimer(3)

NAME
SDL_AddTimer- Add a timer which will call a callback after the specified number of milliseconds has elapsed. SYNOPSIS
#include "SDL.h" SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); CALLBACK
/* type definition for the "new" timer callback function */ typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param); DESCRIPTION
Adds a callback function to be run after the specified number of milliseconds has elapsed. The callback function is passed the current timer interval and the user supplied parameter from the SDL_AddTimer call and returns the next timer interval. If the returned value from the callback is the same as the one passed in, the periodic alarm continues, otherwise a new alarm is scheduled. To cancel a currently running timer call SDL_RemoveTimer with the timer ID returned from SDL_AddTimer. The timer callback function may run in a different thread than your main program, and so shouldn't call any functions from within itself. You may always call SDL_PushEvent, however. The granularity of the timer is platform-dependent, but you should count on it being at least 10 ms as this is the most common number. This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system. If you wanted to set a flag signaling a frame update at 30 frames per second (every 33 ms), you might set a timer for 30 ms (see example below). If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init. RETURN VALUE
Returns an ID value for the added timer or NULL if there was an error. EXAMPLES
my_timer_id = SDL_AddTimer((33/10)*10, my_callbackfunc, my_callback_param); SEE ALSO
SDL_RemoveTimer, SDL_PushEvent SDL
Tue 11 Sep 2001, 23:01 SDL_AddTimer(3)
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy