Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is wrong??????
#1
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....

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...
Reply
#2
check if the next position is a wall or not... if it is, try random move again.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
Well, I don't know why do you need to calculate the ghost position three times in a loop (row, col and then col again). Notice after first row and col you do a check for walls but you only reset row, not col. Doing the check and the right reset after every calculation would be good..
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)