Skip to content

Commit

Permalink
partially finished checkers canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Mar 30, 2016
1 parent 5ed596d commit 40bb19a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public Game(Player p1, Player p2) {
this.player_one = p1;
this.player_two = p2;
this.board = new Board();
assignPieces();
}

private void assignPieces() {
Expand Down
10 changes: 10 additions & 0 deletions src/test/GUITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test;

import view.CheckersWindow;

public class GUITest {

public static void main(String[] args) {
CheckersWindow window = new CheckersWindow();
}
}
37 changes: 37 additions & 0 deletions src/test/Square.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package test;

import java.awt.Color;

import javax.swing.JButton;

public class Square extends JButton {
private Color color;
private int row;
private int column;

public Square(Color color, int row, int column) {
super("");
this.color = color;
this.setRow(row);
this.setColumn(column);
this.setBackground(color);
}

public int getRow() {
return row;
}

public void setRow(int row) {
this.row = row;
}

public int getColumn() {
return column;
}

public void setColumn(int column) {
this.column = column;
}


}
54 changes: 54 additions & 0 deletions src/view/CheckersCanvas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package view;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JPanel;

import model.Board;
import test.Square;

public class CheckersCanvas extends JPanel {

public static final int BOARD_DIM = 8;

ArrayList<Square> blackSquares;
ArrayList<Square> redSquares;

/* Checker board representation */
Board board;
GridBagConstraints layoutConstraints;

public CheckersCanvas() {
super(new GridLayout(BOARD_DIM, BOARD_DIM));
this.blackSquares = new ArrayList<Square>();
this.redSquares = new ArrayList<Square>();
initSquares();
}

public void initSquares() {
for (int i = 0; i < BOARD_DIM; ++i) {
if (i % 2 == 0) {
for (int j = 0; j < BOARD_DIM/4; ++j) {
Square black = new Square(Color.BLACK, i, j*2);
Square red = new Square(Color.RED, i, j*2 + 1);
this.add(black);
blackSquares.add(black);
this.add(red);
redSquares.add(red);
}
} else {
for (int j = 0; j < BOARD_DIM/4; ++j) {
Square black = new Square(Color.BLACK, i, j*2 + 1);
Square red = new Square(Color.RED, i, j*2);
this.add(red);
blackSquares.add(red);
this.add(black);
redSquares.add(black);
}
}
}
}
}
30 changes: 30 additions & 0 deletions src/view/CheckersWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package view;

import javax.swing.JFrame;

public class CheckersWindow extends JFrame {

public static final int HEIGHT = 800;
public static final int WIDTH = 800;
private CheckersCanvas canvas;

public CheckersWindow() {
super("Checkers");
this.setSize(WIDTH, HEIGHT);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.getContentPane().add(new CheckersCanvas());
this.setVisible(true);

//pack();
}

public CheckersCanvas getCanvas() {
return canvas;
}

public void setCanvas(CheckersCanvas canvas) {
this.canvas = canvas;
}

}

0 comments on commit 40bb19a

Please sign in to comment.