Hi guys, my CPS 181 class professor is having us right a OOP Program that asks user for board colors and checker colors and then draws it out on a canvas. I have everything written correctly but i dont know how to get my checkers to place on specific squares. Any help would be greatly appreciated.
To save space i will post ONLY the driver (checkerboard.java) and not the other .java files im using
Code:/**
* This is the start of the checkerboard
* program that displays a checkerboard in
* the starting position.
*
* @author Justin Newberry
* @VERSION Final
*/
import java.util.Scanner;
public class CheckerBoard {
// Put your data attributes here
private Square[][] sqrs; // Declare a 2D array
private Circle[][] circles;
private final int NUMROWS = 8;
private final int NUMCOLS = 8;
private final int SIZESQUARE = 50;
private final int BORDER = 40;
private final int SIZECIRCLE = 30;
public int color;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CheckerBoard board = new CheckerBoard();
board.create();
}
public CheckerBoard() {
// Instantiate or initialize attributes here
sqrs = null;
circles = null;
}
/**
* Creates the checker board. This method currently just draws 2 squares as an example.
* Use this as a starting point in this assignment.
*
*/
private void create() {
Canvas.getCanvas();
// Draw the squares
//Square sq1 = new Square();
//sq1.makeVisible();
//Square sq2 = new Square();
//sq2.moveLeft();
//sq2.changeColor("blue");
//sq2.makeVisible();
createsqrs();
createcircles();
}
public void createsqrs() {
// Create a 2D array of Squares
// Create the array of rows
sqrs = new Square[NUMROWS][];
Scanner color = new Scanner(System.in);
System.out.print("Enter a color for the first set of squares: ");
String color1 = color.next();
System.out.print("Enter a color for the second set of squares: ");
String color2 = color.next();
for(int i = 0; i < sqrs.length; i++) {
sqrs[i] = new Square[NUMCOLS];
for(int j = 0; j < sqrs[i].length; j++) {
if((i + j) % 2 == 0) {
sqrs[i][j] = new Square(SIZESQUARE, BORDER + i * SIZESQUARE, BORDER + j * SIZESQUARE, color1); }
else {
sqrs[i][j] = new Square(SIZESQUARE, BORDER + i * SIZESQUARE, BORDER + j * SIZESQUARE, color2); }
sqrs[i][j].makeVisible();
}
}
}
public void createcircles(){
circles = new Circle[NUMROWS][NUMCOLS];
Scanner color = new Scanner(System.in);
System.out.print("Enter a color for the first set of checkers: ");
String color3 = color.next();
System.out.print("Enter a color for the second set of checkers: ");
String color4 = color.next();
int[] xPos1 = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
int[] yPos1 = {1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};
for(int i = 0; i < circles.length; i++) {
circles[i] = new Circle[NUMCOLS];
for(int j = 0; j < circles[i].length; j++) {
if((i + j) % 2 == 0) {
circles[i][j] = new Circle(SIZECIRCLE, BORDER + xPos1[i] * SIZECIRCLE, BORDER + yPos1[j] * SIZECIRCLE, color3); }
else {
circles[i][j] = new Circle(SIZECIRCLE, BORDER + xPos1[i] * SIZECIRCLE, BORDER + yPos1[j] * SIZECIRCLE, color4); }
sqrs[i][j].makeVisible();
}
}
}
}

