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

Username:   Password: 
 RegisterRegister   
 User stopping the clock... how?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
element4l




PostPosted: Thu Sep 27, 2007 8:28 pm   Post subject: User stopping the clock... how?

Hi guys, I'm a student just starting out with Turing in 11th grade. I have a final 30% exam to do, and have 3 weeks to do it. My assignment is to make an RPG.

Here's my problem:
There's a clock that goes from 1:00 AM to 12:00 AM and I need the user to press a key (ie. ENTER) to stop the clock. After that, I can figure out the rest, but so you get the idea, there will be a health variable changed according to the time the user stopped it at. 6:30 is the optimal time to stop it.

I've read that procedures and delays are "bad" but they're both required in the assignment.
I've just started out, so here's my first bit of code (the part I'd like for user input to stop the clock is in the last procedure):

var age, health : int
var username : string
var job : string

procedure info
put "What's you're first name and age?"
get username
get age
end info

procedure schoolJob
if age <= 20 then
job := "school"
else
job := "your job"
end if
put "You have to get up at 6:30 am to get to ", job, "."
end schoolJob


procedure wakeup
for hour : 1 .. 24
delay (500)
put hour, ":00"
delay (500)
put hour, ":30"
end for
end wakeup

info
schoolJob
wakeup

(I changed a few variables into english to make it more understandable because it was in french, I'm from Ontario)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Sep 27, 2007 8:56 pm   Post subject: Re: User stopping the clock... how?

element4l @ Thu Sep 27, 2007 8:28 pm wrote:
it was in french, I'm from Ontario

Last time I checked, Ontario was mostly English speaking... though that's besides the point.

You want to check for user input between "put hour" statements. Since you have two statements in the same loop, you'd have to do this twice in the loop (oh oh, redundancy).

The preferred method to check the keyboard state is with Input.KeyDown, though because you have delays this will likely not work well. You could use hasch to check the input buffer and read input with getch.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Nick




PostPosted: Thu Sep 27, 2007 8:58 pm   Post subject: RE:User stopping the clock... how?

first of all who told u procedures and delays are bad? cause they're not... they're necassary
second instead of delaying (500) delay somethign smaller like (10) and make this
Turing:

var time:int
for hour:1..24
if hasch then
time:=hour
exit
end if
put hour, ":30"
end for
end wakeup
element4l




PostPosted: Thu Sep 27, 2007 9:46 pm   Post subject: RE:User stopping the clock... how?

Thanks both of you, I can't believe how fast the replies came.

Quote:

first of all who told u procedures and delays are bad? cause they're not... they're necassary

I've read posts and like almost half of them say procedures are bad and stuff, it doesn't really matter though, I just wanted to mention it because I didn't want people wasting their time telling me to take out the procedures like all the others.

Quote:

Last time I checked, Ontario was mostly English speaking...


Yea, but in Ottawa, it's very bilingual

Thanks again, I'll most likely be coming back to the forums in a few days
Carey




PostPosted: Fri Oct 05, 2007 12:07 pm   Post subject: RE:User stopping the clock... how?

Do you mean processes? processes are defiantly bad. Procedures are very usefull though...
Bored




PostPosted: Sat Oct 06, 2007 8:04 pm   Post subject: Re: User stopping the clock... how?

Just as an aside, many people say that processes are bad, but I must disagree. Process in turing are definately implemented poorly making them very limited in good uses, but that dosen't make them "bad" persay. However they way most people try to use processes is bad and the situations people usually try to use them in are the wrong time.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: