There's a commonly used middle ground in OO languages, which is an instance variable. In fact, this is one of the bread-and-butter features of OO languages that make them so powerful.
You can design your class to simply have a public int[][] board
, removing the static
modifier from all methods that operate on the game state.
If your class is called CheckerGame
, you can instantiate a new CheckerGame()
in your main method, and call methods upon it. The following non-sensical example should get you started:
public class CheckerGame {
public int[][] board;
public int getBoard(int row, int col){
return board[row][col];
}
public void setBoard(int row, int col, int val){
board[row][col] = val;
}
public CheckerGame(){ board = new int[8][8];
public static void main(String... argv){
CheckerGame game = new CheckerGame();
game.setBoard(1,2,0);
}
}
You can then add new methods to operate on the instance (for example moveChecker and checkWin), allowing you to reuse and organize functionality.