QBasic MouseBot

Need help moving the mouse through maze array!

Page 1 of 1

3 Replies - 2221 Views - Last Post: 02 November 2009 - 09:53 PM Rate Topic: -----

#1 Ostralis  Icon User is offline

  • #include <greeter>
  • member icon

Reputation: 9
  • View blog
  • Posts: 559
  • Joined: 13-December 08

QBasic MouseBot

Post icon  Posted 18 October 2009 - 12:08 PM

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
"**********"
"	** ***"
"* ***  ***"
"* ****   *"
"*	* * *"
"** *** * *"
"*  **  * *"
"**	 *  "
"** *** ***"
"**********"


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


Mouse.bas - The following is what I have so far, code-wise:
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 October 2009 - 12:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: QBasic MouseBot

#2 Ostralis  Icon User is offline

  • #include <greeter>
  • member icon

Reputation: 9
  • View blog
  • Posts: 559
  • Joined: 13-December 08

Re: QBasic MouseBot

Posted 29 October 2009 - 05:57 PM

Still no replies, eh? If anyone could help, it'd be greatly appreciated. Though, I'm working on troubleshooting some more this week.
Was This Post Helpful? 0
  • +
  • -

#3 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,915
  • Joined: 13-October 07

Re: QBasic MouseBot

Posted 02 November 2009 - 09:12 PM

I'll take a look at it :)
Was This Post Helpful? 0
  • +
  • -

#4 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,915
  • Joined: 13-October 07

Re: QBasic MouseBot

Posted 02 November 2009 - 09:53 PM

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:
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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1