Computer Science Canada Horse Racing... AHHH |
Author: | dymd3z [ 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
Edited by Clayton: Guess what I added? |
Author: | program_x [ 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 |
Author: | Carey [ 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:
If you have any questions or it doesnt work just ask. |
Author: | dymd3z [ 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 |
Author: | Clayton [ 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 ![]() |
Author: | lilmizeminem [ Thu May 17, 2007 10:27 am ] |
Post subject: | Re: Horse Racing... AHHH |
When i treid running this program it didnt work for me. |