
-----------------------------------
whathaveidone
Fri Jun 14, 2013 1:59 pm

Need help with a high score program
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?


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
Mon Jun 17, 2013 12:34 pm

Re: RE:Need help with a high score program
-----------------------------------
 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)  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 ... 

[code] ... code ... [/code ]
[/code]

-----------------------------------
Zren
Mon Jun 17, 2013 10:21 pm

RE:Need help with a high score program
-----------------------------------
Your code needs way more comments.


    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.
