how can I draw a board in 2d array?
hi
i'm trying to create a game called "Gomuku", but I don't know how to start this is my first game ever.. I need to create 10x10 board, JPanel, JButton to start the game "New Game" and a class called Square.java that holds int x,y,accupied;
this is Square.java class
Code:
public class Square {
private final int row ;
private final int col ;
private int accupied=0;
public Square(int r, int c) {
row = r;
col = c;
}
public void setAccupied(int ac) {
accupied = ac;
}
public int getAccupied()
{
return accupied;
}
}//end square class
Code:
class Board extends JPanel
{
private Square sq[][] ;
public void paintComponent(Graphics g)
{ sq[10][10] = new Square(10,10);
for (int row = 0; row < 10; row++) {
for (int column = 0; column < 10; column++) {
Square[row][column] = 0;
}
}
g.drawRect();
}
}//end class board
I want to draw the squares now with this method g.drawRect(); but it takes four parameters :confused: do you know where to get examples like that maybe I will get benefit of them?
I'm just beginning to learn how to create games like these using Square.java class and a JPanel.
Thanks
Re: how can I draw a board in 2d array?
That's cool... but i'm going to do Battlefield game. i need only draw mapping part... so how to put images in each selected cells?? i mean Obstacle images and target image? please help me...
Re: how can I draw a board in 2d array?
It's been well over a year since the last post in this thread. If you have a question, please open a new thread. Closing this.