Computer Science Canada Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) |
Author: | TuringStudent1322 [ Sun Jan 20, 2013 5:47 pm ] | ||
Post subject: | Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) | ||
What is it you are trying to achieve? Make a working game. Specifically exit a loop when a picture reaches a certain location. What is the problem you are having? Loop won't exit when picture reaches location. Describe what you have tried to solve this problem I've attempted for about two days several methods. I've looked at several tutorials etc on this website and others. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1.1 |
Author: | TuringStudent1322 [ Sun Jan 20, 2013 6:25 pm ] |
Post subject: | Re: Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) |
This is urgent, the game is due tomorrow /: |
Author: | Insectoid [ Sun Jan 20, 2013 6:35 pm ] | ||
Post subject: | RE:Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) | ||
Where does runnerx1's value ever change? |
Author: | TuringStudent1322 [ Sun Jan 20, 2013 6:49 pm ] | ||
Post subject: | Re: RE:Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) | ||
Insectoid @ Sun Jan 20, 2013 6:35 pm wrote:
Where does runnerx1's value ever change? Good point ![]() runnerx1 was supposed to represent the x1 value of my picture and when the picture passes the line you would lose since an opponent crossed the line before you. |
Author: | TuringStudent1322 [ Sun Jan 20, 2013 11:08 pm ] |
Post subject: | Re: Need help with a game ASAP (Exiting a loop when a picture reaches a certain location) |
UPDATE! I got everything I want working guys. The only thing I am STILL stuck on is to exit the loop when the red runner reaches the finish before the user and also I'd like the game to return to the mainscreen after the race is over if the user chooses to play again. Other than that I'm good to go! ![]() setscreen ("graphics") var titlefont : int := Font.New ("Arial:40") var wordfont : int := Font.New ("Times New Roman:25") var anykey : string (1) var x, randword : int var guess, word, selection : string var wordcounter, usercounter, skill: int := 0 var runnerpic : int := Pic.FileNew ("runner1.bmp") var runnerpic2 : int := Pic.FileNew ("runner2.bmp") var runnerpic3 : int := Pic.FileNew ("runner3.bmp") var runnerpic4 : int := Pic.FileNew ("runner4.bmp") var win : boolean var lose : boolean var currenttime : int var starttime : int := Time.Elapsed var runnerx : int := 10 var runnery : int := 45 var radius : int := 5 procedure mainscreen View.Set ("nocursor, nooffscreenonly") Draw.FillBox (0, 0, maxx, maxy, black) Font.Draw ("TYPE RACE!", 150, 310, titlefont, brightgreen) colourback (black) colour (brightgreen) locate (9, 4) put "Story: George is a top Olympic runner, however just before the Olympics he" locate (10, 32) put "injured himself!" locate (13, 4) put "Rules: Type in the words which appear on the screen accurately as fast as" locate (14, 26) put "possible to help George win!" locate (25, 24) put "Press anykey to start! Good luck!" runnerpic := Pic.Scale (runnerpic, 50, 50) Pic.Draw (runnerpic, 500, 75, picMerge) runnerpic2 := Pic.Scale (runnerpic2, 50, 50) Pic.Draw (runnerpic2, 375, 75, picMerge) runnerpic3 := Pic.Scale (runnerpic3, 50, 50) Pic.Draw (runnerpic3, 225, 75, picMerge) runnerpic4 := Pic.Scale (runnerpic4, 50, 50) Pic.Draw (runnerpic4, 100, 75, picMerge) end mainscreen procedure difficulty View.Set ("nocursor, nooffscreenonly") Draw.FillBox (0, 0, maxx, maxy, black) Font.Draw ("Choose your difficulty:", 5, 360, wordfont, brightgreen) Font.Draw ("EASY", 150, 280, wordfont, brightgreen) Font.Draw ("MEDIUM", 150, 230, wordfont, brightgreen) Font.Draw ("HARD", 150, 180, wordfont, brightgreen) colourback (black) colour (brightgreen) locate (20, 2) put "Press 1 for EASY. Press 2 for MEDIUM. Press 3 for HARD." get selection if selection = "1" then skill := -40 elsif selection = "2" then skill := skill else skill := 25 end if end difficulty procedure user (runner, speed, g, a : int) for i : a .. a + 10 Pic.Draw (runner, 10 + i, 10 + g, picMerge) delay (speed) Draw.FillBox (10 + i, 10 + g, 10 + i + 50, g + 35, black) end for Pic.Draw (runner, 10 + a + 30, 10 + g, picMerge) end user procedure game loop open : x, "GameData1.t", get for y : 1 .. randword get : x, skip get : x, word end for Draw.FillBox (maxx - 10, 10, maxx - 30, 160, white) Draw.FillBox (maxx, 170, 0, 180, brightgreen) if wordcounter = 19 then win := true cls exit end if % if whatdotcolour (maxx - 20, 45) = black then % lose := true % cls % exit % end if if Math.Distance (maxx - 20, 45, runnerx, runnery) < radius * 2 then lose := true cls exit end if locate (24, 50) Font.Draw (word, 290, 300, wordfont, brightgreen) locatexy (290, 350) get guess if guess = word then wordcounter := wordcounter + 1 usercounter := usercounter + 1 cls user (runnerpic, 10, 115, usercounter * 30) randword := Rand.Int (1, 800) else wordcounter := wordcounter usercounter := usercounter color (brightred) locate (9, 39) Font.Draw (word, 290, 300, wordfont, brightred) put word delay (500) colour (brightgreen) cls end if close : x end loop end game process race (runner, speed, g : int) for y : 1 .. 580 Pic.Draw (runner, 10 + y, 10 + g, picMerge) delay (speed) Draw.FillBox (10 + y, 10 + g, 10 + y + 50, g + 35, black) exit when wordcounter = 19 end for end race process music loop Music.PlayFile ("Game Music.mp3") end loop end music fork music mainscreen getch (anykey) cls difficulty cls Draw.FillBox (0, 0, maxx, maxy, black) Font.Draw ("ON YOUR MARK!", 113, 200, titlefont, brightgreen) delay (1000) cls Font.Draw ("GET SET!", 200, 200, titlefont, brightgreen) delay (1000) cls Font.Draw ("TYPE!", 240, 200, titlefont, brightgreen) delay (500) cls Draw.FillBox (0, 0, maxx, maxy, black) randword := Rand.Int (1, 980) runnerpic := Pic.Scale (runnerpic, 25, 25) runnerpic2 := Pic.Scale (runnerpic2, 25, 25) runnerpic3 := Pic.Scale (runnerpic3, 25, 25) runnerpic4 := Pic.Scale (runnerpic4, 25, 25) fork race (runnerpic2, 95 - skill, 10) fork race (runnerpic3, 70 - skill, 45) fork race (runnerpic4, 80 - skill, 80) game if win = true then Font.Draw ("You won the race!", 200, 250, wordfont, brightgreen) elsif lose = true then Font.Draw ("You lost the race!", 200, 250, wordfont, brightgreen) end if Music.SoundOff |