Results 1 to 4 of 4
  1. #1
    rrsv2 is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default Need help with 2D arrays...

    Ok here is the deal....I got homework and my Java teacher is asking me to create this simple little game(no GUI just numbers and letters showing in a console) I know how to do pretty much everything but one thing.....the 2d string array game board.....he want something that look like this..
    0 1 2 3 4 5 6 7 8 9 10 11
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    0 1 2 3 4 5 6 7 8 9 10 11
    (plus a right side thats goes the same way as the left)

    I can only get this...dont know how to create the bottom and right side
    0 1 2 3 4 5 6 7 8 9 10 11 12 13
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    here are my codes that create the board......

    public Partie (int vertical , int horizontal)
    {
    tableau = new String [vertical+2][horizontal+2];
    for (int v = 0 ; v<tableau.length ; v++ )
    {
    for(int h = 0 ; h<tableau.length ; h++)
    {
    tableau[0][h] = "" + String.format("%1$3d", ((h)));
    }
    }
    for (int v = 0 ; v<tableau.length ; v++ )
    {
    for(int h = 0 ; h<tableau.length ; h++)
    {
    tableau[v][0] = "" + String.format("%1$3d", ((v)));
    }
    }

    }


    I know there should be a tableau.length-1 ....just dont know how to use it...
    Any help will be greatly appreciated ! Thanks in advance

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    rrsv2 is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    All right well....the teacher made a main for us so that de game board is a square 12 x 12 but in our constructor it must be 2 more so lets say its 14x14 so so every side of the square must be numbered from 0 to 13 and thats pretty much it ...the only thing that I cant figure out is how to reverse the arrays so it displays the bottom 0 to13 and the right side 0 to 13.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    If you want to revers the array, start from the last element. But I'm confusing, that how to add numbers in the bottom like 0-13??? I think it should be 13-0, because the very bottom number in the left side column is 13, is it?

Similar Threads

  1. 2D Arrays
    By Major90 in forum New To Java
    Replies: 6
    Last Post: 11-06-2008, 02:08 PM
  2. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 01:59 PM
  3. Help with Arrays
    By bri1547 in forum New To Java
    Replies: 4
    Last Post: 08-01-2008, 05:12 AM
  4. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 10:08 PM
  5. arrays help
    By Warren in forum New To Java
    Replies: 6
    Last Post: 11-23-2007, 07:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •