Hey guys,
I sort of need some last minute help with a QBasic project. I've been having a lot of trouble with programming this project we have entitled, "MouseBot". Essentially the goal is to move a mouse through the designated array called maze$. I have gotten the initial pacing down, and moving into the maze, though I'm having trouble finding a way to move throughout maze, I'm not exactly sure what to do. Have a look at my code, and see if you can help me out. Any help is much appreciated! My question is, what would be a good way to move throughout the maze?
Thanks,
Ost
10x10 mazes are defined separately in .dat files:map1.datCODE
"**********"
" ** ***"
"* *** ***"
"* **** *"
"* * * *"
"** *** * *"
"* ** * *"
"** * "
"** *** ***"
"**********"
map2.datCODE
"**********"
"* *** ***"
"* ***"
"* **** *"
"* * * *"
"** *** * *"
"* ** * *"
" ** * "
"** ** ***"
"**********"
Mouse.bas - The following is what I have so far, code-wise:
CODE
CLS
SCREEN 7
GOSUB inputmap
CLS
GOSUB printmap
GOSUB movemouse
GOSUB mazemouse
END
'Sub Pause
'=========
pause:
FOR pause = 1 TO 70000
NEXT pause
'54000
RETURN
'Input Information
'=================
inputmap:
INPUT "Which map would you like"; map$
map$ = map$ + ".dat"
OPEN map$ FOR INPUT AS #1
RETURN
'Define Array and Print
'======================
printmap:
DIM maze$(1 TO 10, 1 TO 10)
FOR row = 1 TO 10
INPUT #1, in$
FOR col = 1 TO 10
maze$(row, col) = MID$(in$, col, 1)
NEXT col
NEXT row
FOR x = 1 TO 10
FOR y = 1 TO 10
LOCATE x, y + 1: PRINT maze$(x, y)
NEXT y
NEXT x
RETURN
'Print Mouse
'===========
movemouse:
x = 1
y = 11
DO WHILE INKEY$ <> " "
DO WHILE x < 11
IF x = t THEN
LOCATE x, 1: PRINT CHR$(2)
GOSUB pause
LOCATE x, 1: PRINT " "
LOCATE x, 2: PRINT CHR$(2)
GOSUB pause
LOCATE x, 2: PRINT " "
LOCATE x, 3: PRINT CHR$(2)
'END
RETURN
END IF
LOCATE x, 1: COLOR 12: PRINT CHR$(2)
IF maze$(x, 1) = " " THEN
t = x
END IF
GOSUB pause
x = x + 1
IF x <> 1 THEN
LOCATE x - 1, 1: PRINT " "
END IF
LOOP
DO WHILE x > 2
LOCATE x - 2, 1: COLOR 12: PRINT CHR$(2)
IF maze$(x - 2, 1) = " " THEN
t = x - 2
END IF
GOSUB pause
x = x - 1
IF x <> 1 THEN LOCATE x - 1, 1: PRINT " "
LOOP
LOCATE 20, 20: PRINT t
LOOP
COLOR 7
RETURN
CLOSE #1
Thanks again, any help is
much appreciated!
This post has been edited by Ostralis: 18 Oct, 2009 - 11:09 AM