Computer Science Canada Exiting this loop... |
Author: | horlickiki [ Fri Mar 18, 2005 7:12 pm ] |
Post subject: | Exiting this loop... |
Quote: setscreen ("graphics:640;400") var y : int %%%%%%%%%%%%%%%%%%% temp? %VARIABLE DECLARATION / ARRAY DECLARATION var fonta := Font.New ("Amerigo BT:36") var fontb := Font.New ("Amerigo BT:24") var fontc := Font.New ("Amerigo BT:18") var fontd := Font.New ("Amerigo BT:14") var fontcountdown := Font.New ("Amerigo BT:144") var ctc : string (1) var movex : string (1) var mmptxchoice : int var modechoiceptx : int var countdown : int := 3 var move : int := 305 var mmptxoption : flexible array 1 .. 3 of string var modeptx : flexible array 1 .. 3 of string mmptxoption (1) := "1. Play" mmptxoption (2) := "2. View Instructions" mmptxoption (3) := "3. Exit" modeptx (1) := "1. 1 Player" modeptx (2) := "2. 2 Players" modeptx (3) := "3. Exit" % PROCEDURE DECLARATION / PROCESS DECLARATION proc X Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0) loop Font.Draw ("X", move, 200, fontb, 0) drawline (315, 180, 315, 240, 0) %drawline (0, 210, 305, 210, 0) %drawline (335, 210, 640, 210, 0) if hasch then getch (movex) if movex = "S" or movex = "s" then move -= 10 Font.Draw ("X", move + 10, 200, fontb, 7) elsif movex = "J" or movex = "j" then move += 10 Font.Draw ("X", move - 10, 200, fontb, 7) end if cls if move < 305 then Font.Draw ("Player 1 Is Winning", 220, 100, fontc, 0) elsif move > 305 then Font.Draw ("Player 2 Is Winning", 220, 100, fontc, 0) else Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0) exit when move = 0 or move = maxx end if end if end loop end X proc player1ptx cls Font.Draw ("Get Ready...", 220, 300, fontb, 0) Font.Draw ("Press Any Key To Start The Countdown", 150, 100, fontd, 0) locatexy (310, 50) getch (ctc) cls for q : 1 .. 3 Font.Draw (intstr (countdown), 250, 150, fontcountdown, 0) %locatexy (310, 50) %put countdown countdown := countdown - 1 delay (1000) cls end for Font.Draw ("Go!!!", 120, 120, fontcountdown, 0) delay (1000) cls X end player1ptx proc rtmm cls Font.Draw ("That Was Not An Option:", 85, 300, fontb, 0) Font.Draw ("Redirecting To main menu", 85, 200, fontb, 0) delay (600) Font.Draw (".", 460, 200, fontb, 0) delay (600) Font.Draw (".", 470, 200, fontb, 0) delay (600) Font.Draw (".", 480, 200, fontb, 0) delay (600) end rtmm %WELCOME MENU color (0) colorback (black) cls Font.Draw ("Welcome To Pull The X", 60, 300, fonta, 0) delay (1000) Font.Draw ("Press Any Key To Continue...", 200, 30, fontd, 0) locatexy (470, 40) getch (ctc) %MAIN MENU %loop loop colorback (7) cls Font.Draw ("Choose An Option From The List:", 85, 300, fontb, 0) y := 220 for menuptx : 1 .. 3 y := y - 50 Font.Draw (mmptxoption (menuptx), 100, y, fontd, 0) end for locatexy (400, 120) get mmptxchoice %%%%%%%%%%%%%%%%% OPTION 1 %%%%%%%%%%%%%%%%%% if mmptxchoice = 1 then cls Font.Draw ("Choose Mode", 100, 300, fontb, 0) y := 220 for playptx : 1 .. 3 y := y - 50 Font.Draw (modeptx (playptx), 100, y, fontd, 0) end for locatexy (400, 120) get modechoiceptx if modechoiceptx = 1 then player1ptx end if %%%%%%%%%%%%%%%%% OPTION 2 %%%%%%%%%%%%%%%% elsif mmptxchoice = 2 then cls Font.Draw ("Instructions:", 220, 300, fontb, 0) Font.Draw ("Tap Your Key Until The X Has Reached Your Side Of The Screen", 50, 180, fontd, 0) Font.Draw ("Player 1 Controls:", 40, 120, fontc, 0) Font.Draw ("S Key Moves The X To The Left", 20, 80, fontd, 0) Font.Draw ("Player 2 Controls:", 360, 120, fontc, 0) Font.Draw ("J Key Moves The X To The Right", 340, 80, fontd, 0) Font.Draw ("Press Any Key To Continue...", 170, 10, fontd, 0) locatexy (430, 10) getch (ctc) %%%%%%%%%%%%%%%%%% OPTION 3 %%%%%%%%%%%%%%%%%%%%%%% elsif mmptxchoice = 3 then exit else rtmm end if end loop why doesnt't proc X end? |
Author: | Bacchus [ Fri Mar 18, 2005 9:07 pm ] |
Post subject: | |
caus e its in a loop and there no exit or exit when in it, so it just keeps going lol |
Author: | mike200015 [ Fri Mar 18, 2005 11:27 pm ] |
Post subject: | |
there is an exit when Quote: exit when move = 0 or move = maxx |
Author: | Bacchus [ Fri Mar 18, 2005 11:43 pm ] | ||
Post subject: | |||
oops didnt see that lol kinda hidden there ![]()
|
Author: | ssr [ Sat Mar 19, 2005 1:05 pm ] | ||
Post subject: | |||
actually that wont fully work yet U PUT IT IN THE WRONG LOOP!! the exit when will only exit teh if statement not teh whole loop just move it to right before end loop try it
![]() btw u want to shorten ur codes? |
Author: | Bacchus [ Sat Mar 19, 2005 3:57 pm ] |
Post subject: | |
exit really only cause loops and for loops to exit, pretty sure it wouldnt matter if the exit is in an if cause i do it all the time |
Author: | Cervantes [ Sat Mar 19, 2005 6:16 pm ] |
Post subject: | |
Bacchus wrote: exit really only cause loops and for loops to exit, pretty sure it wouldnt matter if the exit is in an if cause i do it all the time
Bacchus is correct. The reason your code works, ssr, is because you used the >= and <=, rather than just = and =. Bacchus was right again. ![]() |
Author: | ssr [ Sat Mar 19, 2005 6:23 pm ] |
Post subject: | |
ok but try it int he if statement, it wont work for me... ![]() |
Author: | ssr [ Sat Mar 19, 2005 6:31 pm ] | ||||
Post subject: | |||||
try these 2 codes, one will exit and the other wont
|
Author: | mike200015 [ Sat Mar 19, 2005 6:56 pm ] | ||||
Post subject: | |||||
yea.. thats tru.. only in some cases it doesnt matter.. because if its in the if statement.. then the program will only exit when it gets into the if statement, and satisfies the exit when .. but if u use an exit, not an exit when it matters.. like:
^ that will exit when u press 1.. so u need to put it in the if.. but:
^that will always exit. |
Author: | ssr [ Sat Mar 19, 2005 7:24 pm ] |
Post subject: | |
lol ya exactly, thanks for the explanation mike. ![]() |
Author: | mike200015 [ Sat Mar 19, 2005 8:23 pm ] |
Post subject: | |
haha no problem ssr ![]() ![]() |
Author: | Mr. T [ Sat Mar 19, 2005 8:54 pm ] |
Post subject: | |
horlickiki should be the one thanking you, lol |
Author: | ssr [ Sat Mar 19, 2005 9:03 pm ] |
Post subject: | |
we all learnt something didnt we... ![]() |
Author: | Bacchus [ Sun Mar 20, 2005 12:48 am ] |
Post subject: | |
Cervantes wrote: Bacchus was right again. wOOt!, im getting better at this ![]() ![]() |
Author: | horlickiki [ Mon Mar 21, 2005 9:06 pm ] |
Post subject: | |
Thanks A Lot Guys!!! It Works!!! |