View Single Post
Old Apr 28th, 2005, 9:10 AM   #4
Easter Bunny
Programmer
 
Easter Bunny's Avatar
 
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4 Easter Bunny is on a distinguished road
sorry, got a bit busy and also have my finger in so many pies here (hmm... pies... *drool* ) i kinda forgot about this.

ok, now don't freak out, but i modified your board class a bit

board.java

public class Board
{
    char[][] ar = new char[10][10];
    
    /*Creates a new instance of Board*/
    public Board()
    {
        this.ar = ar;
        for (int r=0; r<ar.length; r++)
        {
            for (int c=0; c<ar[r].length; c++)
            {
               ar[r][c] = 'w';
            }
        }
         
       // this.setBoard();
    }
    
    public void setBoard( char[][] arr )
    {
       for (int r=0; r<arr.length; r++)
       {
            for (int c=0; c<arr[r].length; c++)
            {
                System.out.print(" " + ar[r][c]);
            }
            System.out.println("");
      }
    }

//important bit

    public char[][] getArray()
    {
    	return ar;
    }
}


player.java

class Player
{
    Board board = new Board();
    char[][] array;
    
    /** Creates a new instance of Player */
    public Player()
    {
        this.setBattleship();
    }
    
    void setBattleship()
    {
    	array = board.getArray();    //important bit
        int R = 0;
        int C = 0;
        int place = 0;
        int pos = 0;
        RandomNumber r = new RandomNumber(1, 10);
        RandomNumber vh = new RandomNumber(1, 2);
        BattleShip b = new BattleShip("BattleShip", 4, 0);
        
        place = vh.roll()-1;
        R = r.roll()-1;
        C = r.roll()-1;
          for(int i = 0; i < b.size; i++)
          {
              if(C > 10)
                break;
               if(R > 10)
                break;
              
               array[R][C] = 'B';
               
               if(place == 0)
               {
                   C++;
               }
               else if(place == 1)
               {
                   R++;
               }
          }
          board.setBoard( array );    //important bit
    }
}


lets see... what did i do.... ah!!

when board is initiated and the object created, it creates the array and puts in a bunch of w's. what then happens, is that player class calls getArray() and that gives it an array. it puts in the ship and then sends it back to the board class with setBoard( array ) and that tells it to put it on screen. you can try it, it works(except for the out of bounds part, i'm gonna try fix that now). what happens now, is that you will have B's on the board instead of all w's.

sorry about not replying dude.
__________________
There's got to be more to life than being really, really
ridiculously good looking

Last edited by Easter Bunny; Apr 28th, 2005 at 9:28 AM.
Easter Bunny is offline   Reply With Quote