Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Extremely Urgent!!! I need help with putting a timer...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
koolmoe




PostPosted: Tue Jan 21, 2003 2:50 pm   Post subject: Extremely Urgent!!! I need help with putting a timer...

Hey guys i attached my pacman game so far, and i really need to kno how to add in a timer....Because i want it so that you hafta collect all the dots before time runs out. Please i need this information by today, because my project is due VERY SOON!! I'd really really REALLY appreciate ur help...THx in AdvAnce!

------------------------------------------------------------------------------------
also any comments or tips will be helpful!



pacmanedit.t
 Description:

Download
 Filename:  pacmanedit.t
 Filesize:  19.94 KB
 Downloaded:  512 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 21, 2003 4:10 pm   Post subject: (No subject)

code:
var timeStart, timeNow : int
var c:string
var timePassed:boolean := false

process T()
wallclock(timeStart)
loop
delay(1000)
wallclock(timeNow)
locate(1,1)
put 10 - (timeNow - timeStart)

exit when timeNow - timeStart >10
end loop
timePassed:=true
put "time's up!"
end T

fork T


this is basically a timer...

Here's how you can put that into your program. You use wallclock() at the beginning of the level to get the start time. Then every time you go through a loop (doesn't matter which one, as long as it keeps on running throughout the whole level... such as movement loop, or better yet some process such as enemy AI which is independant of pacman movement) you wallclock again to find out current time.

Right after that you find the difference between start time and now time and if its greater then timer allowed for level, then its "time up" 8)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Catalyst




PostPosted: Tue Jan 21, 2003 4:10 pm   Post subject: (No subject)

For a timer you can use clock it gives the time since the program started in ms. ( clock ("variable to use here")) You can use this to make a timer

For example like 20 seconds

code:


var time:int

loop

clock (time)
locate (1,1)
put 20-(time/1000)

end loop



koolmoe




PostPosted: Tue Jan 21, 2003 5:25 pm   Post subject: for the clock..

how do you do an exit when statement?
koolmoe




PostPosted: Tue Jan 21, 2003 5:42 pm   Post subject: timer works and everything but...

THe timer works, but it interferes with my pacman movement...my pacman moves at the same speed as the timer....i want my pacman to move faster than the timer What's going on? please help!
azndragon




PostPosted: Tue Jan 21, 2003 6:42 pm   Post subject: (No subject)

code:
var word : string
loop
put "Enter a word, type exit to stop."
get word
exit when word = "stop"
end loop
Tony




PostPosted: Tue Jan 21, 2003 7:12 pm   Post subject: (No subject)

make sure you don't put delays into timer...

I used delays in the example to count time and wallclock to varify time.

You just need to use wallclock (or clock) to find out the time elapsed and compare to your requirements.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
koolmoe




PostPosted: Tue Jan 21, 2003 8:43 pm   Post subject: to tony

hey did you look at my code? because i'm not sure where to insert the timer..where i put it, the timer interferes with my pacman movement. For example, if the timer goes down by seconds, then pacman will move with 1 second delays between...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 21, 2003 8:46 pm   Post subject: (No subject)

then you're using the timer wrong...

you don't use the command delay() and you don't put timer in its own loop.

You use wallclock to find the time the level started, then you add wallclock inside already existing movement loop to find the time at which each movement takes place. Then you check how much time passed.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
koolmoe




PostPosted: Wed Jan 22, 2003 9:53 pm   Post subject: oh alright...

hey can you tell me like explain to me what the process T function does? because i may have to expain it to my teacher..also, what i'm thinking is that the wallclock (startimerunning) corresponds with the internal clock of the computer?
Tony




PostPosted: Thu Jan 23, 2003 5:10 pm   Post subject: (No subject)

yes, wallclock does corespond with internal computer clock. It gives you time in seconds passed since 1/1/1970

here's an explanation for the process:

process T() - declear process
wallclock(timeStart) - find the time process started
loop - start program's loop
delay(1000) - wait for a second. this is not needed, it just saves resources
wallclock(timeNow) - get current time
locate(1,1) - locates where output will be
put 10 - (timeNow - timeStart) - counts down the time left to reach 10

exit when timeNow - timeStart >10 - exits loop when over 10s passed
end loop
timePassed:=true - sets boolean variable to true so that other parts of the program can use this variable to see if process ended or not
put "time's up!" - says that process finished
end T - ends process block

fork T - calls the process to start



I hope this helps 8)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
koolmoe




PostPosted: Fri Jan 24, 2003 2:19 pm   Post subject: awesome man!

yea thx man that helped A LOT! it was kool of you to help me out and take ur time thx dude!
Tony




PostPosted: Fri Jan 24, 2003 6:07 pm   Post subject: (No subject)

Very Happy you're welcome
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: