I'm learning js by experimenting with them. I know how to display a custom google map in a div element (html). I would like to know how will be able to put the Battleship game (js script) on top of the google map (ie. i would like to have google map as background). http://javascript.internet.com/games/battleship-demo.html Can someone help? Thanks
Also, what is the meaning of for (x=0;x<gridx;++x) grid[y][x] = [100,-1,0]; in the code (battleship game).....
And I guess, I need to change the code under "/* Function to insert HTML source for a grid */" alone. If I am just using function map(){ var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(1.4419, 1.1419), 2); } How do I edit this to add the game script as an extra layer on top? Is it hard to display the two regions (pc and human) of the game in two separate maps?
cool - are you trying to make a battleship game using google maps? nice! for (x=0;x<gridx;++x) grid[y][x] = [100,-1,0]; Code (markup): this updates the grid multidimensional array and assigns all members of the current grid[y] to the array [100,-1,0] so you get like y = 34, gridx = 30; grid[34][0] = [100,-1,0]; grid[34][1] = [100,-1,0]; ... grid[34][30] = [100,1,0]; Code (javascript): get firefox and firebug, then modify this code like so: for (x=0;x<gridx;++x) { grid[y][x] = [100,-1,0]; } console.log(grid[y]); // see the new arrays. Code (javascript): - press f12 to enable console.
thanks dimitar christoff... But may i ask the purpose of the [-1,0] in the array [100,-1,0] ? Also, any idea how to add google map as a background for this?
erm. in the context of: var gridx = 16, gridy = 16; for (y=0;y<gridx;++y) { grid[y] = []; for (x=0;x<gridx;++x) grid[y][x] = [100,-1,0]; } Code (javascript): this goes and sets the ship data for the whole grid to an array with values 100, -1, false later on it becomes evident that the 3 represent different things: grid[cy][cx][0] = ship[d][s][j]; // i think the ship types. grid[cy][cx][1] = shipno; // changes from -1 to reference the ship its building grid[cy][cx][2] = dead[d][s][j]; Code (markup): as i said, get firebug and use console.log(grid) then explore it. the trick is to find the correlation between the ship types, dead spots and the grid etc. its not coded in a very user-friendly way though so you need to really apply yourself to figure what they were doing / trying to do. good luck