Computer Science Canada

help with my game- see how many times you can click the circle in a timelimit

Author:  turing1094 [ Thu Jun 10, 2010 6:08 pm ]
Post subject:  help with my game- see how many times you can click the circle in a timelimit

What is it you are trying to achieve?
I am trying to make a program where you can see how many times you can click the circle in a certain time limit. at the end it should tell the user there score


What is the problem you are having?
I'm not quiet sure why its not working, I think its something to do with the time



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
setscreen ("graphics:vga")
var count : int
var x, y : int
var button : int := 0
var timepassed : boolean := true
var timepassed1 : int := 0

Draw.FillOval (300, 200, 50, 50, blue)

loop
Mouse.Where (x, y, button)
if button = 1
then
count := count + 1

end if
timepassed1 := timepassed1 + 1


if timepassed1 > 1000
then
timepassed := true
end if
exit when timepassed = true
end loop

put "Your score is ", count


Turing:


<Add your code here>



Please help
i need this for tomorrow please post the code i need to use

Author:  Cezna [ Thu Jun 10, 2010 8:01 pm ]
Post subject:  RE:help with my game- see how many times you can click the circle in a timelimit

Since there is not delay of any sort, i just speeds through the loop 1000 times and exits.
Instead of adding one to the value of timepassed1 each time, I would recommend using:
Turing:


Even if you could click in time though, you have click := click + 1, but you don't give click an initial value anywhere.
You have to set it to 0 at the top.

Also, they are going to be able to just hold the mouse over the circle and hold the button down at it will keep registering.
For this, I recommend using a boolean variable to represent whether or not the mouse button is down, and only if it is not go into this part:

Turing:

if button = 1
            then
        count := count + 1

    end if


And then within that if statement, set the boolean variable to true (or false, whichever will represent that the mouse is being clicked), and only set it back to false if the button is released.
If you don't quite understand what I mean by this, I can try to explain it more clearly and in more detail.

Author:  turing1094 [ Thu Jun 10, 2010 9:17 pm ]
Post subject:  Re: help with my game- see how many times you can click the circle in a timelimit

Im still having some trouble

The code does not count how many times I click the circle:


setscreen ("graphics:vga")
var count : int := 0
var x, y : int
var button : int := 0
var timepassed : boolean := true
var timepassed1 : int := 0

Draw.FillOval (300, 200, 50, 50, blue)

loop
Mouse.Where (x, y, button)
if button = 1
then
count := count + 1

end if
Time.DelaySinceLast (1)


if timepassed1 > 1000
then
timepassed := true
end if
exit when timepassed = true
end loop

put "Your score is ", count


please help me correct the code

Author:  TerranceN [ Thu Jun 10, 2010 9:36 pm ]
Post subject:  RE:help with my game- see how many times you can click the circle in a timelimit

First of all the site has a nifty formatting tag:
code:

[syntax="Turing"]
% Your code here
[/syntax]


Anyway, look at this line:
Turing:
var timepassed : boolean := true


Then this line:
Turing:
exit when timepassed = true


Keep looking until you see what's wrong.

Next, timepassed will never increase, you need to add somewhere in your loop
Turing:
timepassed1 += 1


Finally, like Cezna said, since this only checks if the mouse is down, if you hold the mouse down it still counts as a click. For another way to fix this we need to know what the button was before, define a variable to store that. If it was not pressed before and now is, then count a click.

Hope that helps.

Author:  turing1094 [ Thu Jun 10, 2010 9:55 pm ]
Post subject:  Re: help with my game- see how many times you can click the circle in a timelimit

Im still really confused on what to do. Im a beginner, could u please just send me the whole code i really need it. The program is not working

Author:  TheGuardian001 [ Thu Jun 10, 2010 10:44 pm ]
Post subject:  Re: help with my game- see how many times you can click the circle in a timelimit

turing1094 @ Thu Jun 10, 2010 9:55 pm wrote:
Im still really confused on what to do. Im a beginner, could u please just send me the whole code i really need it. The program is not working


Ha. No.

Let's see if we can find the problem here:

code:

var timepassed : boolean := true

loop
exit when timepassed = true
end loop


How many times will that loop run? How often is timepassed not true?

And, as others stated, you actually have to check the values of x and y against your circle. Right now you only check if button = 1. You should also be checking for x and y being inside the circle. x must be greater than the circle's left edge, but less than the circle's right edge. y must be greater than the circle's bottom, but less than the circle's top.

Author:  Cezna [ Fri Jun 11, 2010 5:22 am ]
Post subject:  RE:help with my game- see how many times you can click the circle in a timelimit

To check if the mouse is inside the circle, you're going to need to use the formula for a circle, which is:

r ** 2 = x ** 2 + y ** 2

Also, people aren't going to do your work for you, they will help you understand something you are having trouble with, as the people here are doing an excellent job of, but they will not do it for you.

Author:  Unnamed.t [ Fri Jun 11, 2010 7:30 pm ]
Post subject:  Re: help with my game- see how many times you can click the circle in a timelimit

I have a suggestion for the way to count time in your program.

Instead of doing what your are right now, store the Time.Elapsed function in a variable. This is gonna give you the time the program has been running for.

Next you basically have to use Time.Elapsed in another variable to count the current running time. I hope you can try and figure this out for yourself Smile

When you subtract the current time with the start time, you will get how long the program has been running for. This is probably the most beneficial way of doing it. It is easy to exits after the time limit you have set and it doesn't mess around with your user input.

I have heard about the "clock ()" command, but i'm not sure if that'll be of any use or not. Just remember that Time.Elapsed counts in milliseconds.


: