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

Username:   Password: 
 RegisterRegister   
 Horse Racing... AHHH
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dymd3z




PostPosted: Mon May 07, 2007 8:02 am   Post subject: Horse Racing... AHHH

I'm trying to make a horse racing game between 5 horses where the winner is random each time. I just need to make the finish line... I'm trying if statements for the winner butttt its not working. Any ideas? Here is what I have thus far

Turing:

var x1 : int := 0
var x2 : int := 0
var x3 : int := 0
var x4 : int := 0
var x5 : int := 0
var horse1 : int := Pic.FileNew ("horse1.bmp")
var horse2 : int := Pic.FileNew ("horse2.bmp")
var horse3 : int := Pic.FileNew ("horse3.bmp")
colourback (black)
cls



process first
    loop
        x1 := x1 + Rand.Int (1, 10)
        Pic.Draw (horse1, x1, 10, picMerge)
        delay (100)
        Draw.FillBox (x1, 10, x1 + 32, 42, black)
        x1 := x1 + Rand.Int (1, 10)
        Pic.Draw (horse2, x1, 10, picMerge)
        delay (100)
        Draw.FillBox (x1, 10, x1 + 32, 42, black)
        x1 := x1 + Rand.Int (1, 10)
        Pic.Draw (horse3, x1, 10, picMerge)
        delay (100)
        Draw.FillBox (x1, 10, x1 + 32, 42, black)
    end loop
end first

process second
    loop
        x2 := x2 + Rand.Int (1, 10)
        Pic.Draw (horse1, x2, 80, picMerge)
        delay (100)
        Draw.FillBox (x2, 80, x2 + 32, 112, black)
        x2 := x2 + Rand.Int (1, 10)
        Pic.Draw (horse2, x2, 80, picMerge)
        delay (100)
        Draw.FillBox (x2, 80, x2 + 32, 112, black)
        x2 := x2 + Rand.Int (1, 10)
        Pic.Draw (horse3, x2, 80, picMerge)
        delay (100)
        Draw.FillBox (x2, 80, x2 + 32, 112, black)
    end loop
end second

process third
    loop
        x3 := x3 + Rand.Int (1, 10)
        Pic.Draw (horse1, x3, 160, picMerge)
        delay (100)
        Draw.FillBox (x3, 160, x3 + 32, 192, black)
        x3 := x3 + Rand.Int (1, 10)
        Pic.Draw (horse2, x3, 160, picMerge)
        delay (100)
        Draw.FillBox (x3, 160, x3 + 32, 192, black)
        x3 := x3 + Rand.Int (1, 10)
        Pic.Draw (horse3, x3, 160, picMerge)
        delay (100)
        Draw.FillBox (x3, 160, x3 + 32, 192, black)
    end loop
end third

process fourth
    loop
        x4 := x4 + Rand.Int (1, 10)
        Pic.Draw (horse1, x4, 240, picMerge)
        delay (100)
        Draw.FillBox (x4, 240, x4 + 32, 272, black)
        x4 := x4 + Rand.Int (1, 10)
        Pic.Draw (horse2, x4, 240, picMerge)
        delay (100)
        Draw.FillBox (x4, 240, x4 + 32, 272, black)
        x4 := x4 + Rand.Int (1, 10)
        Pic.Draw (horse3, x4, 240, picMerge)
        delay (100)
        Draw.FillBox (x4, 240, x4 + 32, 272, black)
    end loop
end fourth

process fith
    loop
        x5 := x5 + Rand.Int (1, 10)
        Pic.Draw (horse1, x5, 320, picMerge)
        delay (100)
        Draw.FillBox (x5, 320, x5 + 32, 352, black)
        x5 := x5 + Rand.Int (1, 10)
        Pic.Draw (horse2, x5, 320, picMerge)
        delay (100)
        Draw.FillBox (x5, 320, x5 + 32, 352, black)
        x5 := x5 + Rand.Int (1, 10)
        Pic.Draw (horse3, x5, 320, picMerge)
        delay (100)
        Draw.FillBox (x5, 320, x5 + 32, 352, black)
    end loop
end fith

fork first
fork second
fork third
fork fourth
fork fith

if first = x + 100 then
    exit
elsif second = x + 100 then
    exit
elsif third = x + 100 then
    exit
elsif fourth = x + 100 then
    exit
elsif fith = x + 100 then
    exit
end if


Edited by Clayton: Guess what I added?
Sponsor
Sponsor
Sponsor
sponsor
program_x




PostPosted: Mon May 07, 2007 1:27 pm   Post subject: Re: Horse Racing... AHHH

ic... i would go about it little differently

first, i would make an array to hold the horeses data(such as where they are)

second, i would only one process but give it paramters (such as which horse it takes care of) and call it five times

third, i would make a variable called win, and tell that process to stop when it either sees that win is true, or the horse it controls is at the end

anyway, keep going at it, good start
Carey




PostPosted: Tue May 08, 2007 9:20 am   Post subject: Re: Horse Racing... AHHH

DO NOT USE PROCESSES UNLESS ABSOLUTELY NECCESARY!!!

Try this and see if it works:
Turing:

setscreen ("offscreenonly") %for smoother animation

var picnum : real := 1
var horse : array 1 .. 5 of int
var pics : array 1 .. 3 of int
var win : boolean := false


for i : 1 .. 3
    pics (i) := Pic.FileNew ("horse" + intstr (i) + ".bmp") %declare pictures
end for

for i : 1 .. 5
    horse (i) := 0  %starting x value
end for

loop
    picnum += 0.05 %change this value for a slower or faster pic animation
    if picnum >= 3.5 then     %so when rounding, it doesnt go to 4 and get an array out of bounds error
        picnum := 1
    end if
    for i : 1 .. 5
        horse (i) += Rand.Int (1, 10) %add a value to the horses
        %draws the horse at the x coordinate specified and at a spaces out y value
        %so the horses arent on top of each other.
        %it draws the picture based on the variable picnum. this creates an animation effect
        Pic.Draw (pics (round (picnum)), horse (i), i * 50 - 50, picMerge)
        %if you havent got a winner, check to see if any of the horses are at the finish line
        if win = false then
            if horse (i) > maxx - Pic.Width (pics (round (picnum))) then %maxx - Pic.Width (pi... is the finish line
                put "Horse ", i, " wins the race!"
                win := true
            end if
        end if
    end for
    View.Update
    if win = true then
        exit
    end if
    cls
end loop


If you have any questions or it doesnt work just ask.
dymd3z




PostPosted: Thu May 17, 2007 8:07 am   Post subject: RE:Horse Racing... AHHH

I eventually got it completed. Here she is:

var win : int := 0
var choice : string
var x1 : int := 0
var x2 : int := 0
var x3 : int := 0
var x4 : int := 0
var x5 : int := 0
var horse1 : int := Pic.FileNew ("horse1.bmp")
var horse2 : int := Pic.FileNew ("horse2.bmp")
var horse3 : int := Pic.FileNew ("horse3.bmp")
var gamestarted : boolean := false
colourback (black)
cls
color (white)

process first
loop
x1 := x1 + Rand.Int (1, 10)
Pic.Draw (horse1, x1, 10, picMerge)
delay (100)
Draw.FillBox (x1, 10, x1 + 32, 42, black)
x1 := x1 + Rand.Int (1, 10)
Pic.Draw (horse2, x1, 10, picMerge)
delay (100)
Draw.FillBox (x1, 10, x1 + 32, 42, black)
x1 := x1 + Rand.Int (1, 10)
Pic.Draw (horse3, x1, 10, picMerge)
delay (100)
Draw.FillBox (x1, 10, x1 + 32, 42, black)
exit when x1 > 600 or win not= 0
end loop
if win = 0 then
win := 1
gamestarted := false
put "Horse 1 wins."
end if
end first

process second
loop
x2 := x2 + Rand.Int (1, 10)
Pic.Draw (horse1, x2, 80, picMerge)
delay (100)
Draw.FillBox (x2, 80, x2 + 32, 112, black)
x2 := x2 + Rand.Int (1, 10)
Pic.Draw (horse2, x2, 80, picMerge)
delay (100)
Draw.FillBox (x2, 80, x2 + 32, 112, black)
x2 := x2 + Rand.Int (1, 10)
Pic.Draw (horse3, x2, 80, picMerge)
delay (100)
Draw.FillBox (x2, 80, x2 + 32, 112, black)
exit when x2 > 600 or win not= 0
end loop
if win = 0 then
win := 2
gamestarted := false
put "Horse 2 wins."
end if
end second

process third
loop
x3 := x3 + Rand.Int (1, 10)
Pic.Draw (horse1, x3, 160, picMerge)
delay (100)
Draw.FillBox (x3, 160, x3 + 32, 192, black)
x3 := x3 + Rand.Int (1, 10)
Pic.Draw (horse2, x3, 160, picMerge)
delay (100)
Draw.FillBox (x3, 160, x3 + 32, 192, black)
x3 := x3 + Rand.Int (1, 10)
Pic.Draw (horse3, x3, 160, picMerge)
delay (100)
Draw.FillBox (x3, 160, x3 + 32, 192, black)
exit when x3 > 600 or win not= 0
end loop
if win = 0 then
win := 3
gamestarted := false
put "Horse 3 wins."
end if
end third

process fourth
loop
x4 := x4 + Rand.Int (1, 10)
Pic.Draw (horse1, x4, 240, picMerge)
delay (100)
Draw.FillBox (x4, 240, x4 + 32, 272, black)
x4 := x4 + Rand.Int (1, 10)
Pic.Draw (horse2, x4, 240, picMerge)
delay (100)
Draw.FillBox (x4, 240, x4 + 32, 272, black)
x4 := x4 + Rand.Int (1, 10)
Pic.Draw (horse3, x4, 240, picMerge)
delay (100)
Draw.FillBox (x4, 240, x4 + 32, 272, black)
exit when x4 > 600 or win not= 0
end loop
if win = 0 then
win := 4
gamestarted := false
put "Horse 4 wins."
end if
end fourth

process fith
loop
x5 := x5 + Rand.Int (1, 10)
Pic.Draw (horse1, x5, 320, picMerge)
delay (100)
Draw.FillBox (x5, 320, x5 + 32, 352, black)
x5 := x5 + Rand.Int (1, 10)
Pic.Draw (horse2, x5, 320, picMerge)
delay (100)
Draw.FillBox (x5, 320, x5 + 32, 352, black)
x5 := x5 + Rand.Int (1, 10)
Pic.Draw (horse3, x5, 320, picMerge)
delay (100)
Draw.FillBox (x5, 320, x5 + 32, 352, black)
exit when x5 > 600 or win not= 0
end loop
if win = 0 then
win := 5
gamestarted := false
put "Horse 5 wins."
end if
end fith

loop
if gamestarted = false then
gamestarted := true
fork first
fork second
fork third
fork fourth
fork fith
end if
delay (100)
if gamestarted = false and win not= 0 then
put "Do you want to play again?"
get choice
if choice = "Yes" or choice = "yes" then
x1 := 0
x2 := 0
x3 := 0
x4 := 0
x5 := 0
win := 0
cls
else
exit
end if
end if
end loop
Clayton




PostPosted: Thu May 17, 2007 8:20 am   Post subject: RE:Horse Racing... AHHH

Hmm... I'm still seeing the use of processes where they don't need to be used. I suggest you take a gander at this and reconsider your use of processes. Also, I didn't really look at your code thoroughly, but I'm seeing a lot of repeated code. Procedures with parameters are amazing things Wink
lilmizeminem




PostPosted: Thu May 17, 2007 10:27 am   Post subject: Re: Horse Racing... AHHH

When i treid running this program it didnt work for me.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: