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/