A quick question

Discussion in 'JavaScript' started by queen_mary, Nov 5, 2009.

  1. #1
    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
     
    queen_mary, Nov 5, 2009 IP
  2. queen_mary

    queen_mary Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Also, what is the meaning of

    for (x=0;x<gridx;++x)
    grid[y][x] = [100,-1,0];


    in the code (battleship game).....
     
    queen_mary, Nov 5, 2009 IP
  3. queen_mary

    queen_mary Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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?
     
    queen_mary, Nov 5, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    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.
     
    Last edited: Nov 6, 2009
    dimitar christoff, Nov 6, 2009 IP
  5. queen_mary

    queen_mary Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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?
     
    queen_mary, Nov 6, 2009 IP
  6. queen_mary

    queen_mary Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    can anyone explain this?

    thx
     
    queen_mary, Nov 8, 2009 IP
  7. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    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 :)
     
    dimitar christoff, Nov 8, 2009 IP
  8. queen_mary

    queen_mary Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks will try again
     
    queen_mary, Nov 9, 2009 IP