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

I am trying to make a maze in Qbasic, but when the pointer touches the mazes, the program does not end. I want that when the circle (which is a pointer) touches the ends of the maze, then the program should end. The program is as follows: -

cls
screen 12
DIM p AS STRING
DIM A1 AS STRING
15 print"What do you want to do?"
print"A:Draw AN IMAGE"," B:PLAY A MAZE GAME";
PRINT
PRINT"TYPE 'A' OR 'B'IN CAPITAL FORM"
GOTO 102
99 print "rules to play the maze game:"
print
print "1 use 'W' to move the ball foward"
print "2 use 'S' to move the ball backward"
print "3 use 'A' to move the ball leftward"
print "4 use 'D' to move the ball rightward"
INPUT A1
CLS
goto 10

102  INPUT P
if p="A"then
cls
goto 20
elseif p="B" then
cls
goto 99
elseif  p<>"A"  AND p<>"B" then
print "Choose between A and 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 as string
x = 110
y = 105
do
k = ucase$(inkey$)
if k="W"then

y = y - 2

elseif k= "S" then

y = y + 8

elseif k="A"then

x = x - 8

elseif k="D" then

x = x + 5

end if
circle (x,y),7,10
loop until k ="Q"
GOTO   45
70 CLS
GOTO 15
if x=120 and y=120 then goto 45
40  cls

45 END

Help Pls

Thanks in Advance ....

+3
source share
1 answer

Ok, let's take a peak in the game loop below and modify it a bit for readability:

do
    k = ucase$(inkey$)

    if k="W"then
        y = y - 2
    elseif k= "S" then
        y = y + 8
    elseif k="A"then
        x = x - 8
    elseif k="D" then
        x = x + 5
    end if

    circle (x,y),7,10
loop until k ="Q"

Your winning case (if x = 120 and y = 120 and then 45) does not actually happen inside the loop, but outside of it.

, do loop, "" true. :

do
    'This code will execute 
loop until k = "Q"
    'This code will only execute after k=Q

do, .

, QBasic . , , , . , . , loop, do loop. , , do. if .

, , .

Edit: , . , Python codecademy, QBasic. QBasic , goto.

+4

All Articles