School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,096 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,033 people online right now. Registration is fast and FREE... Join Now!




QBasic MouseBot

 

QBasic MouseBot, Need help moving the mouse through maze array!

Ostralis

18 Oct, 2009 - 11:08 AM
Post #1

D.I.C Regular
Group Icon

Joined: 13 Dec, 2008
Posts: 437



Thanked: 4 times
My Contributions
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.dat
CODE
"**********"
"    ** ***"
"* ***  ***"
"* ****   *"
"*    * * *"
"** *** * *"
"*  **  * *"
"**     *  "
"** *** ***"
"**********"


map2.dat
CODE
"**********"
"*  *** ***"
"*      ***"
"* ****   *"
"*    * * *"
"** *** * *"
"*  **  * *"
"   **  *  "
"**  ** ***"
"**********"


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

User is offlineProfile CardPM
+Quote Post


Ostralis

RE: QBasic MouseBot

29 Oct, 2009 - 04:57 PM
Post #2

D.I.C Regular
Group Icon

Joined: 13 Dec, 2008
Posts: 437



Thanked: 4 times
My Contributions
Still no replies, eh? If anyone could help, it'd be greatly appreciated. Though, I'm working on troubleshooting some more this week.
User is offlineProfile CardPM
+Quote Post

calvinthedestroyer

RE: QBasic MouseBot

2 Nov, 2009 - 08:12 PM
Post #3

D.I.C Regular
***

Joined: 13 Oct, 2007
Posts: 287



Thanked: 3 times
Expert In: QBasic, Legos

My Contributions
I'll take a look at it smile.gif

User is offlineProfile CardPM
+Quote Post

calvinthedestroyer

RE: QBasic MouseBot

2 Nov, 2009 - 08:53 PM
Post #4

D.I.C Regular
***

Joined: 13 Oct, 2007
Posts: 287



Thanked: 3 times
Expert In: QBasic, Legos

My Contributions
It sounds like you need help with the LOGIC of your program.

1- Are you having the USER move the mouse, by using the keypad?

2- or do you want the mouse to randomly find its own way through the maze.

I think you want the the 2nd one right?

I don't see any kind of an engine designed into your program.
for example:
CODE

CLS
SCREEN 7
GOSUB inputmap
$endflag = "yes"
do while endflag$ = "yes"
GOSUB printmap
gosub calculate      '* here should be were the mouse looks around and decides were to move next
GOSUB movemouse
'GOSUB mazemouse
loop

some were with in that loop you will have to decide to end the program by setting endflag$ = "no"

PS GOSUB mazemouse is missing? did you forget that part? What were you going to have that sub do?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 11:50AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month