How can a circle touch a line in Qbasic and end the program? -


i trying make maze in qbasic when pointer touches maze lines program not ending. want when circle (which pointer ) touches ends of maze program should go end.the program this:-

cls screen 12 dim p string dim a1 string 15 print"what want do?" print"a:draw image"," b:play maze game"; print print"type 'a' or 'b'in capital form" goto 102 99 print "rules play maze game:" print print "1 use 'w' move ball foward" print "2 use 's' move ball backward" print "3 use 'a' move ball leftward" print "4 use 'd' move ball rightward" input a1 cls goto 10  102  input p if p="a"then cls goto 20 elseif p="b" cls goto 99 elseif  p<>"a"  , p<>"b" print "choose between , b" goto 70 end if   10 pset(120,120) draw "r100" pset (120,140) draw"r80" pset (200,140) draw "d100" pset (220,120) draw"d140" pset (220,260) draw "l90" pset (200,240) draw "l50" pset (130,260) draw"u50l120u90r60u40l50u60r300d90l35d260l60d30l80 h20l20h20u30r40u5l70d60f40r250u90h40u45r40u40r50u130h40r225d65l50d60l15 d130l40d50l20d15r45d40r20u45r10u10r10u90r100"  pset(150,240) draw"u50l120u50r60u80l50u20r260d50l35d260l60d30l40h20l20h10r 40u50l120d98f50r290u115h40u20r40u40r50u160h10r140d20l50d60l15 d130h40d90l20d60r45d45r70u45r10u10r10u90r75"  20 dim k string x = 110 y = 105 k = ucase$(inkey$) if k="w"then  y = y - 2  elseif k= "s"  y = y + 8  elseif k="a"then  x = x - 8  elseif k="d"  x = x + 5  end if circle (x,y),7,10 loop until k ="q" goto   45 70 cls goto 15 if x=120 , y=120 goto 45 40  cls  45 end 

pls

thanks in advance....

ok, let's take peak @ game loop presented below , reformated bit readability:

do     k = ucase$(inkey$)      if k="w"then         y = y - 2     elseif k= "s"         y = y + 8     elseif k="a"then         x = x - 8     elseif k="d"         x = x + 5     end if      circle (x,y),7,10 loop until k ="q" 

your win case (if x=120 , y=120 goto 45) doesn't occur within loop outside it.

with do loops, code between , loop statement execute unless "until" statement returns true. in order words:

do     'this code execute  loop until k = "q"     'this code execute after k=q 

put win case in loop , should work.

if recall correctly, qbasic allows whitespace in beginning of line. recommend using whitespace organize code visually can see what's going on. @ how formatted main loop. loop controls tabbed right of , loop statement. way can see loop doing. in if statement gets same treatment similar reasons.

if in habit of indenting code, can start see code's logic laid out cleanly.

edit: seems you're new programming. if enjoy it, recommend learning python through codecademy rather qbasic. qbasic encourages bad habits, goto statements.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -