-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |