05-29-2003, 06:30 AM
ok guys, i have been working on my Pacman, and i got the AI working...uhhh (ok).... and now i have another problem....i use the same case statement for pacman and the ghost to stay inside the maze, but ghost still manages to get thru walls....whats wrong...sumone help please......heres my code....
please note that those accented a's, and e's etc.. are actually the DOS code for the pipes in diff. directions...
Code:
CLS 'clear screen
SCREEN 13 'set screen resolution
DIM maze$(11) 'Declares that there is 6 maze variables
DIM oldrow
DIM oldcol
maze$(1) = "ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃû" 'the following is the maze in
maze$(2) = "º º º" 'the variables
maze$(3) = "º º ÃÃÃÃÃÃÃÃà º º"
maze$(4) = "º º º º"
maze$(5) = "º ÃÃû ÃÃà ÃÃü º"
maze$(6) = "º º º"
maze$(7) = "º º"
maze$(8) = "º ÃÃÃÃÃÃÃÃà º"
maze$(9) = "º º º"
maze$(10) = "º º"
maze$(11) = "ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃü "
row = 4 'says which row pacman is at
col = 7 'says which column pacman is at
ghostrow = 9 'says which row the ghost starts at
ghostcol = 10 'says which column the ghost starts at
dots = 54 'declares how many dots there are
DO 'Begins the Game loop
LOCATE 1, 1 'positions the maze
FOR count = 1 TO 11 'Prints the maze out
PRINT maze$(count)
NEXT count
LOCATE row, col
COLOR 14 'Prints Pacman
PRINT "C"
COLOR 15
LOCATE ghostrow, ghostcol
COLOR 4 'makes ghost red
PRINT "" 'Prints ghost
COLOR 15
IF dots = 0 THEN 'declares when the user can win
LOCATE 15, 1
PRINT "You Have Won" 'Prints You win, if you eat all
END 'dots
END IF
'The following condition is for
'when you get eaten by a ghost
IF ((row = ghostrow) AND (col = ghostcol)) THEN
LOCATE 15, 1
PRINT "Your Dead" 'Prints your dead
END
END IF
DO 'Program freezes until user press'
press$ = INKEY$ 'any key
LOOP UNTIL press$ <> ""
oldrow = row 'every move is stored into the variable
oldcol = col
SELECT CASE press$ 'the following is the conditions for
CASE CHR$(0) + CHR$(72) 'the key press'
row = row - 1
CASE CHR$(0) + CHR$(80)
row = row + 1
CASE CHR$(0) + CHR$(75)
col = col - 1
CASE CHR$(0) + CHR$(77)
col = col + 1
END SELECT
SELECT CASE MID$(maze$(row), col, 1) 'wont let you get passed maze
CASE "¹", "º", "»", "¼", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã"
row = oldrow
col = oldcol
CASE "." 'when you eat a dot, it dissapears
MID$(maze$(row), col, 1) = " ": BEEP
dots = dots - 1
END SELECT
'*******************
'Ghost Movements
'*******************
IF RND < .9 THEN 'randomizes the ghosts movements
oldrow = ghostrow
SELECT CASE ghostrow
CASE IS < row 'moves ghost closer to you
ghostrow = ghostrow + 1
CASE IS > row
ghostrow = ghostrow - 1
END SELECT
oldrow = ghostrow
SELECT CASE ghostcol 'moves ghost closer to you
CASE IS < row
ghostrow = ghostrow + 1
CASE IS > row
ghostrow = ghostrow - 1
END SELECT
'wont let ghost go through walls
SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
CASE "¹", "º", "»", "¼", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã"
ghostrow = oldrow
END SELECT
IF ghostrow = oldrow THEN 'moves ghost closer to you
oldcol = ghostcol
SELECT CASE ghostcol
CASE IS < col
ghostcol = ghostcol + 1
CASE IS > col
ghostcol = ghostcol - 1
END SELECT
END IF
'makes the ghost stay if he tries to
'get out of maze
SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
CASE "¹", "º", "»", "¼", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã", "Ã"
ghostcol = oldcol
END SELECT
END IF
LOOP UNTIL press$ = CHR$(13)
please note that those accented a's, and e's etc.. are actually the DOS code for the pipes in diff. directions...