Working on a program that loads a maze.txt file and then the user tries to find the cheese or 'C' and can't get through any walls 'X'. Haven't even gotten to the finding the cheese part as I can't get it to stop and go back if they hit a wall. Can anyone take a look and give me a kick in the right direction? I am not sure if it is even loading my text file, and like I said, cannot get it to stop and go back if they move to a space containing a wall.
Here is what I have so far:
Maze.txt contents:
XXXXXXXXXXXX
X X
X X
XXXXXXX X
X X
X X
X XXXXXXX
X X
X C X
X X
XXXXXXXXXXXX
TITLE Maze
INCLUDE Irvine32.inc
.data
line BYTE 0dh, 0ah,0
screen BYTE 200 DUP(' ')
fileName BYTE 100 DUP(0)
buffer BYTE 5000 DUP(?)
ARRAY_SIZE = 144
pArray DWORD ?
FILL_VAL EQU ' '
.code
main PROC
call allocate_array
jnc arrayOk ; failed (CF = 1)?
call WriteWindowsMsg
call Crlf
jmp quit
arrayOk:
mov edx, OFFSET fileName
call GetCommandTail
add edx, 1
call OpenInputFile
push eax ; EAX Has file handle
mov edx, OFFSET buffer
mov ecx, 5000
call ReadFromFile
mov ecx, eax
mov esi,pArray
mov edi, OFFSET buffer
call writeScreen; write to the screen first time
mov ecx, 40; number of moves to make
mov edx, 13; starting location
READTOP:
mov bl, screen[edx]
mov screen[edx], '.';previous location
call ReadChar; get the key press
AA: cmp al, 'd'
jne BB
inc edx
jmp WALL
BB: cmp al, 'a'
jne CC
dec edx
jmp WALL
CC: cmp al, 's'
jne DD1
add edx, 12
jmp WALL
DD1: cmp al, 'w'
jne DON
sub edx, 12
jmp WALL
DON:
WALL: cmp screen[edx], 'X'
jne BOT
mov screen[ebx], bl
jmp READTOP
BOT:mov screen[edx], 0B0h; character for the mouse
call writeScreen;rewrite the screen
loop READTOP
quit:
exit
main ENDP
allocate_array PROC USES eax
.IF eax == NULL
stc ; return with CF = 1
.ELSE
mov pArray,eax ; save the pointer
clc ; return with CF = 0
.ENDIF
ret
allocate_array ENDP
writeScreen PROC; write the screen to the terminal
push eax;save used registers
push ebx
push ecx
push edx
push esi
mov dl, 0
mov dh, 0
call gotoxy; mov to 0,0 which uses dl and dh
mov ecx, 200
mov edi, 0; char to write to screen
mov edx, 0; newline counter
TOP:
mov al, [screen + edi];get the char from screen
call WriteChar;write character to console
cmp edx, 11;check for newlines
jne CC1
call crlf
mov edx, 0
jmp EE
CC1:inc edx
EE: inc edi; increment array index
loop TOP
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
writeScreen ENDP
END main
Sorry, here is my maze file in tags
XXXXXXXXXXXX X X X X XXXXXXX X X X X X X XXXXXXX X X X C X X X XXXXXXXXXXXX

New Topic/Question
Reply


MultiQuote






|