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

Username:   Password: 
 RegisterRegister   
 Timer in game Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
FailWhale




PostPosted: Sat Jan 15, 2011 7:03 pm   Post subject: Timer in game Problem

Hey everyone, I'm in Grade 10 at the moment and I'm making a game right now. I'm having troubles making the loop exit when 10 seconds pass. help please?

code:

setscreen ("graphics:850;600")

put "Welcome to Super Awesome Guitar Game!"
put ""
put "The game is simple: strum the guitar by pressing space."
put ""
put "You must strum the guitar a certain amount of times before the song ends in order to complete the level."
put "If you fail to do so, you lose!!"
put ""
put "Please do not cheat the game by holding the space bar; it's no fun that way. :("
put ""
put "Type in the difficulty you wish to start with (1-10 in inreasing difficulty) then press enter to start!"

var idiff : int

get idiff

var itimes, ineeded : int
var ckey : string(1)

ineeded := 500*idiff
itimes := 0
cls


loop
var itime : int := Time.Elapsed()
exit when itimes = ineeded or itime = 10000
put itimes
put ineeded
getch (ckey)
if ord (ckey) = 32 then
itimes := itimes + 1
end if
cls
end loop

if itimes = ineeded then
put "Nice"
else
put "You Failed"
end if




Thanks!
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 15, 2011 7:26 pm   Post subject: RE:Timer in game Problem

code:

exit when itimes = ineeded or itime = 10000
put itimes
put ineeded

I like how you are printing the values out -- it makes it easier to see what values were used to check if it's time to exit.

So, when is that condition true?
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  [ 2 Posts ]
Jump to:   


Style:  
Search: