Need help with a high score program
Author |
Message |
whathaveidone
|
Posted: Fri Jun 14, 2013 1:59 pm Post subject: Need help with a high score program |
|
|
What is it you are trying to achieve?
<Create a working program that counts the amount of times a box has been clicked then records and organizes the data into a high score table>
What is the problem you are having?
<Can't get the counter to work.>
Describe what you have tried to solve this problem
<Got a friend that is better at turing than I am (We both are inexperienced with programming) he added a bunch of code that just further confused me and I am not really sure what to do.>
Please specify what version of Turing you are using
<4.1>
Description: |
|
Download |
Filename: |
High score program.t |
Filesize: |
4.19 KB |
Downloaded: |
160 Time(s) |
Description: |
|
Download |
Filename: |
High score program.t |
Filesize: |
4.19 KB |
Downloaded: |
92 Time(s) |
Description: |
|
Download |
Filename: |
High score program.t |
Filesize: |
4.19 KB |
Downloaded: |
151 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Zren
|
Posted: Fri Jun 14, 2013 2:46 pm Post subject: RE:Need help with a high score program |
|
|
Quote: <Can't get the counter to work.>
Which counter exactly?
~
procedure AAA
procedure AAB
var f1 : int
Try to be more descriptive when naming variables/functions/things.
Giving something a good name will make it easier for someone fresh to the code.
~
When learning something new (like file input/output), start a new program. Then, once you're familiar with the tools used, merge them into other programs.
|
|
|
|
|
|
whathaveidone
|
Posted: Mon Jun 17, 2013 12:34 pm Post subject: Re: RE:Need help with a high score program |
|
|
Zren @ Fri Jun 14, 2013 2:46 pm wrote: Quote: <Can't get the counter to work.>
Which counter exactly?
~
procedure AAA
procedure AAB
var f1 : int
Try to be more descriptive when naming variables/functions/things.
Giving something a good name will make it easier for someone fresh to the code.
~
When learning something new (like file input/output), start a new program. Then, once you're familiar with the tools used, merge them into other programs.
Procedure AAA is the timer I was originally going to use but then I decided that the program should end when the box reaches its destination instead so I guess it is rather useless. AAB is the procedure containing the box's movement around the screen. And I am not really sure what the variable f1 represents, all the highscore stuff was added in by a friend so I am not really sure what it represents. I am guessing that this code isn't salvageable and I should probably just start a new one right?
|
|
|
|
|
|
whathaveidone
|
Posted: Mon Jun 17, 2013 12:47 pm Post subject: Re: Need help with a high score program |
|
|
After editing out some of the useless stuff I was able to get to the highscore table that my friend made which gets rid of that problem yet I still am not sure how to get it so that when you click the sprite it adds to the score. Can anyone identify the problem here?
Turing: |
var x, y, b : int
var chars : array char of boolean
var score, streak : int := 0
var font : int := Font.New ("Calibri:20:bold")
var font2 : int := Font.New ("Calibri:20:bold")
var scorey : int := 550
var counter : int := 10
var boxx : int := 550
var boxy : int := 400
function ptinrect (h, v, x1, v1, x2, v2 : int) : boolean
result (h > x1 ) and (h < x2 ) and (v > v1 ) and (v < v2 )
end ptinrect
%Sprite Variables
var box : int
var box_sprite : int
type
highscore :
record
name : string
score : int
end record
var person : array 1 .. 10 of highscore
var f1 : int
var num : int
var temp : highscore
open : f1, "Highscore", read
for i : 1 .. 10
read : f1, person (i )
end for
close : f1
setscreen ("graphics:890;680")
Pic.ScreenLoad ("ambient2.bmp", 0, 0, picCopy)
Font.Draw ("Click the box as many times as possible", 10, 600, font, green)
Font.Draw ("It will circle the screen once, good luck!", 10, 570, font, green)
Font.Draw ("Click box below when ready.", 10, 540, font, green)
drawfillbox (420, 300, 510, 350, black)
drawfillbox (422, 302, 508, 347, grey)
Font.Draw ("Click!", 430, 320, font, black)
loop
buttonwait ("down", x, y, b, b )
if ptinrect (x, y, 422, 302, 508, 347) then
cls
exit
end if
end loop
setscreen ("graphics:700;480")
%Sprite Declarations
box := Pic.FileNew ("Box.bmp")
box_sprite := Sprite.New (box )
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxy + = - 1
if boxy = 50 then
exit
elsif boxy > 50 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxx + = - 1
if boxx = 50 then
exit
elsif boxx > 50 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxy + = 1
if boxy = 400 then
exit
elsif boxx < 400 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxx + = 1
if boxx = 550 then
exit
elsif boxx < 550 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
cls
setscreen ("graphics:850;700")
Pic.ScreenLoad ("background.jpg", - 45, - 80, picCopy)
for i : 1 .. 10
Font.Draw (person (i ).name, 380, scorey, font, white)
Font.Draw (intstr (person (i ).score ), 670, scorey, font, white)
scorey - = 47
end for
if score > person (10).score then
Font.Draw ("What is your name? Limit of 10 characters.", 10, 810, font, white)
Text.ColourBack (53)
loop
get person (10).name : *
exit when length (person (10).name ) <= 10
end loop
person (10).score := score
end if
for j : 2 .. 10
for i : 2 .. 10
if person (i ).score > person (i - 1).score then
temp := person (i )
person (i ) := person (i - 1)
person (i - 1) := temp
counter - = 1
end if
end for
end for
open : f1, "Highscore", read
for i : 1 .. 10
read : f1, person (i )
end for
close : f1
Pic.ScreenLoad ("16_abstract_light_ambient_wallpaper-wide.bmp", 800, 20, picCopy)
scorey := 550
for i : 1 .. 10
Font.Draw (person (i ).name, 380, scorey, font, white)
Font.Draw (intstr (person (i ).score ), 670, scorey, font, white)
scorey - = 47
end for
if score > person (10).score then
Font.Draw (person (counter ).name, 380, 550 - 47 * (counter - 1), font, 12)
Font.Draw (intstr (person (counter ).score ), 670, 550 - 47 * (counter - 1), font, 12)
end if |
Mod Edit:
Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
code: |
[syntax="turing"] ... code ... [/syntax]
[code] ... code ... [/code ]
|
|
|
|
|
|
|
Zren
|
Posted: Mon Jun 17, 2013 10:21 pm Post subject: RE:Need help with a high score program |
|
|
Your code needs way more comments.
Turing: |
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxy + = - 1
if boxy = 50 then
exit
elsif boxy > 50 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxx + = - 1
if boxx = 50 then
exit
elsif boxx > 50 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxy + = 1
if boxy = 400 then
exit
elsif boxx < 400 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
loop
mousewhere (x, y, b )
if ptinrect (x, y, boxx, boxy, 100, 58)
then
score + = 100
end if
boxx + = 1
if boxx = 550 then
exit
elsif boxx < 550 then
Sprite.Show (box_sprite )
Sprite.SetPosition (box_sprite, boxx, boxy, false)
end if
delay (8)
end loop
|
Notice how similar that code is? Perhaps you should move a single loop into a procedure, then have parameters for the things that are different.
~
So far as I can see, you are not saving (writing to file) the highscores. You ARE repeating code to read the highscores both at the begining before the... boxes move across the screen, and after you've sorted the highscores. Repeated code should go inside a procedure.
Check out the File I/O tutorial in the Turing Walkthrough to learn how to save the highscores. http://compsci.ca/v3/viewtopic.php?t=12972
~
Which "sprite" are you talking about? Are you talking about the box moving across the screen?
If I understand the code correctly, it is already incrementing the score if the mouse is over the box, regardless of the button state. If you want it to increment the score only when a mouse button is DOWN then you also need to compare mouse_b as well. If you want to only increment the score when the mouse has been clicked (pushed down, then released) then you need to remember the last button state and compare that as well.
~
var x, y, b : int
With context, we know that these refer to the mouse x,y and button state. However you use "x" and "y" elsewhere in the program to refer to other coordinates, so specifying them as mouse_x, mouse_y, mouse_b helps lessen the ambiguity.
|
|
|
|
|
|
|
|