QuestionAsk Questions?

Hi there

I am new to java and i am trying to place checkers pieces into a checker board which is set up as an array. What i have done so far is create an array and fill it with nothing. I have then created a copy and now want to place the appropriate pieces into the array

Here is my code

public class Checkerboard { // Constructors private Object checkerboard;; // Creates a checkerboard where all the squares are empty. public Checkerboard() { Checker checkerboard[][] = new Checker[8][8]; for (int i=0; i < 8; i++) for (int j=0; j < 8; j++) checkerboard[i][j] = new Checker(null); } public Checkerboard(Checkerboard old) { if (old == null) { System.out.println("Fatal error: copying null Checker"); System.exit(1); } this.checkerboard = old.checkerboard; } public void initialise() { Checker checkerboard[][] = new Checker[8][8]; for (int i=0; i < 1; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(true); for (int i=1; i < 2; i++) for (int j=1; j < checkerboard.length; j=+2) checkerboard[i][j] = new Checker(true); for (int i=2; i < 3; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(true); for (int i=5; i < 6; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(false); for (int i=6; i < 7; i++) for (int j=1; j < checkerboard.length; j=+2) checkerboard[i][j] = new Checker(false); for (int i=7; i < checkerboard.length; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(false); } }

My checker piece is in another class and is boolean type (red = true, black = false). I know I need to access the Checker piece, but I'm really not sure how to do this. And it seems really messy to have 6 for loops. Any advice would be very helpful.

Thanks

View Answers

Related Tutorials/Questions & Answers:

Advertisements