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

Username:   Password: 
 RegisterRegister   
 adding a counter to the game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jason27131




PostPosted: Sun Feb 01, 2009 3:47 pm   Post subject: adding a counter to the game

Ok, the problem I'm having right now is that I'm making a dart game program. Its really simple right now, but the thing is, I can't add a counter in the program to show the user how many darts they have left, and how much points they got so far. I tried to use put and Draw.Cls in the loop, but all that does is make the screen flash every few seconds, and doesn't even show the counters. I need help.

Heres the code.


code:
import GUI
%The Welcoming screen
Music.PlayFileLoop ("back.mp3")
var font1, font2 : int
font1 := Font.New ("serif:25")
font2 := Font.New ("serif:10")
Font.Draw ("The Dart Game", maxx div 3, maxy div 2, font1, red)
Font.Draw ("You get 20 darts", maxx div 3, maxy div 3, font1, red)
delay (3000)
cls

setscreen ("graphics")

var powerincrease : int := 22
var x, y, button : int
var darts : int := 20
var acore : int := 0

procedure hard
    cls
    Font.Draw ("Power Bar", 10, 5, font2, black)
    View.Update
    View.Set ("offscreenonly")
    drawfilloval (maxx div 2, maxy div 2, 180, 180, 27)
    drawfilloval (maxx div 2, maxy div 2, 140, 140, 64)
    drawfilloval (maxx div 2, maxy div 2, 120, 120, 92)
    drawfilloval (maxx div 2, maxy div 2, 80, 80, 69)
    drawfilloval (maxx div 2, maxy div 2, 60, 60, 0)
    drawfilloval (maxx div 2, maxy div 2, 15, 15, 33)
    drawfilloval (maxx div 2, maxy div 2, 5, 5, 101)
    drawfillbox (10, 21, maxx div 16, 22, red)
    loop
        loop
            View.Update
            delay (3)
            powerincrease := powerincrease + 2
            Mouse.Where (x, y, button)
            if hasch then
                if whatdotcolor (x, powerincrease) = 27 then
                    acore := acore + 0
                elsif whatdotcolor (x, powerincrease) = 64 then
                    acore := acore + 5
                elsif whatdotcolor (x, powerincrease) = 92 then
                    acore := acore + 10
                elsif whatdotcolor (x, powerincrease) = 69 then
                    acore := acore + 15
                elsif whatdotcolor (x, powerincrease) = 0 then
                    acore := acore + 20
                elsif whatdotcolor (x, powerincrease) = 33 then
                    acore := acore + 25
                elsif whatdotcolor (x, powerincrease) = 101 then
                    acore := acore + 30
                elsif whatdotcolor (x, powerincrease) = red then
                    acore := acore + 50
                end if
                Music.PlayFile ("arrow.wav")
                drawfilloval (x, powerincrease, 2, 2, black)
                Music.SoundOff
                Input.Flush
                darts := darts - 1
            end if
            drawfillbox (10, 22, maxx div 16, powerincrease, red)
            View.Update
            exit when powerincrease >= maxy - 10
            exit when darts = 0
        end loop
        loop
            View.Update
            drawfillbox (10, 22, maxx div 16, powerincrease, white)
            powerincrease := 22
            View.Update
            drawfillbox (10, 22, maxx div 16, powerincrease, white)
            View.Update
            exit when powerincrease = 22
        end loop
        exit when darts = 0
    end loop
    cls
    Font.Draw ("GAME OVER", maxx div 3, maxy div 2, font1, red)
    put "Your score is: ", acore
    if acore >= 200 then
        Music.PlayFile ("unbelievable.wav")
    end if
    View.Update
end hard
cls
View.Update

procedure easy
    cls
    View.Set ("offscreenonly")
    drawfilloval (maxx div 2, maxy div 2, 180, 180, 27)
    drawfilloval (maxx div 2, maxy div 2, 140, 140, 64)
    drawfilloval (maxx div 2, maxy div 2, 120, 120, 92)
    drawfilloval (maxx div 2, maxy div 2, 80, 80, 69)
    drawfilloval (maxx div 2, maxy div 2, 60, 60, 0)
    drawfilloval (maxx div 2, maxy div 2, 15, 15, 33)
    drawfilloval (maxx div 2, maxy div 2, 5, 5, 101)
    drawfillbox (10, 21, maxx div 16, 22, red)
    var powerincrease : int := 22
    var x, y, button : int
    var darts : int := 20
    var acore : int := 0

    loop
        Font.Draw ("Power Bar", 10, 5, font2, black)
        View.Update
        loop
            locate (maxrow, maxcol)
            View.Update
            delay (3)
            powerincrease := powerincrease + 2
            Mouse.Where (x, y, button)
            if hasch then
                if whatdotcolor (x, powerincrease) = 27 then
                    acore := acore + 0
                elsif whatdotcolor (x, powerincrease) = 64 then
                    acore := acore + 5
                elsif whatdotcolor (x, powerincrease) = 92 then
                    acore := acore + 10
                elsif whatdotcolor (x, powerincrease) = 69 then
                    acore := acore + 15
                elsif whatdotcolor (x, powerincrease) = 0 then
                    acore := acore + 20
                elsif whatdotcolor (x, powerincrease) = 33 then
                    acore := acore + 25
                elsif whatdotcolor (x, powerincrease) = 101 then
                    acore := acore + 30
                elsif whatdotcolor (x, powerincrease) = red then
                    acore := acore + 50
                end if
                drawfilloval (x, powerincrease, 2, 2, black)
                Music.PlayFile ("arrow.wav")
                drawfilloval (x, powerincrease, 2, 2, black)
                Music.SoundOff
                Input.Flush
                darts := darts - 1
            end if
            drawfillbox (10, 22, maxx div 16, powerincrease, red)
            delay (3)
            View.Update
            exit when powerincrease >= maxy - 10
            exit when darts = 0
        end loop
        loop
            View.Update
            drawfillbox (10, 22, maxx div 16, powerincrease, white)
            powerincrease := 22
            View.Update
            drawfillbox (10, 22, maxx div 16, powerincrease, white)
            View.Update
            exit when powerincrease = 22
        end loop
        exit when darts = 0
    end loop
    cls
    Font.Draw ("GAME OVER", maxx div 3, maxy div 2, font1, red)
    put "Your score is: ", acore
    if acore >= 200 then
        Music.PlayFile ("unbelievable.wav")
    end if
    View.Update
end easy
cls
View.Update


put "Instructions"
put "------------"
put " "
put " "
put "You get 20 darts, and the point of the game is to get as"
put "high as a score as possible."
put "Use your mouse to aim horizontally, and the power bar to aim vertically."
put "Where the bar stops is where the dart ends up."
put "The most outer ring is 0 points, the ring inside is 5,"
put "then the next one is 10, and so on and so forth. The middle circle is 50 points."
put "Press any key to shoot the dart"
put "Have fun!"

var button1 : int := GUI.CreateButton (maxx div 2, maxy div 4, 0, "Hard Difficulty", hard)
var button2 : int := GUI.CreateButton (maxx div 2, maxy div 3, 0, "Easy Difficulty", easy)

loop
    exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
zero-impact




PostPosted: Sat Feb 07, 2009 12:22 pm   Post subject: RE:adding a counter to the game

What you are going to need to do is use Font.Draw. The thing is Font.Draw only accepts strings, so in order to show your score you will have to convert it to a string using Font.Draw(intstr (score)....)
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: