Kent55 0 Newbie Poster

I am making a game for my computing class and the objective of the game is for the player to move around the grid and collect all of the passengers in the game and deliver them to the base before they run out of power. I have managed almost everything else except for when I try to check whether the player moves over a passenger. My latest fiddle: http://jsfiddle.net/nZ8vA/13/ is as far as I have tried in getting it to detect the passengers. In the fiddle it seems as if it is working (as it detects the p) however if you continue to move around the grid and then go back it will detect other random squares as being passengers even though they do not have a letter assigned to them.

My new array (that I am struggling to figure out how to get to work properly):

var map = [
    [{ color: "g", letter: "" }, 
     { color: "g", letter: "" }, 
     { color: "w", letter: "P" }, 
     { color: "w", letter: ""  }],

    [{ color: "w", letter: "" }],

    [{ color: "w", letter: "" }],

    [{ color: "g", letter: "" }, 
     { color: "g", letter: "" }, 
     { color: "w", letter: "" }, 
     { color: "w", letter: "" }],

    [{ color: "g", letter: "" }, 
     { color: "b", letter: "" }, 
     { color: "b", letter: "" }, 
     { color: "w", letter: "" }, 
     { color: "w", letter: "" }, 
     { color: "w", letter: "" }, 
     { color: "g", letter: "" }, 
     { color: "g", letter: "" }, 
     { color: "w", letter: "" }, 
     { color: "w", letter: "" }]
];

I am really struggling in trying to get this to work, if anyone knows why this is not working then that would be great.

My old fiddle (before I started attempting to detect the passengers) contains the old array I had, and the full grid layout: http://jsfiddle.net/nZ8vA/7/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.