Commit cc4b8713 authored by kimia's avatar kimia

final check

parent 4f26b735
...@@ -13,7 +13,7 @@ import java.util.ArrayList; ...@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class ChessBoardGUI extends JPanel { public class ChessBoardGUI extends JPanel {
static boolean isServer = false ; public static boolean isServer = false ;
private PrintWriter out; private PrintWriter out;
public JButton[][] button = new JButton[8][8]; public JButton[][] button = new JButton[8][8];
...@@ -94,7 +94,7 @@ public class ChessBoardGUI extends JPanel { ...@@ -94,7 +94,7 @@ public class ChessBoardGUI extends JPanel {
// setVisible(true); // setVisible(true);
} }
public void updatesAfterMove(){ public void updatesAfterMove(){
buttonRepaint(); buttonUpdate();
updateDeletedPanel(); updateDeletedPanel();
//---------------- //----------------
int condition = checkmateCondition(board,pw,pb); int condition = checkmateCondition(board,pw,pb);
...@@ -154,7 +154,11 @@ public class ChessBoardGUI extends JPanel { ...@@ -154,7 +154,11 @@ public class ChessBoardGUI extends JPanel {
out.flush(); out.flush();
} }
private void buttonRepaint(){
/**
* it updates the graphical page , it changes the pieces with the new actions
*/
private void buttonUpdate(){
Piece[][] pieceBoard = getUpdatedBoard(); Piece[][] pieceBoard = getUpdatedBoard();
for (int i = 0 ;i<8 ;i++){ for (int i = 0 ;i<8 ;i++){
for (int j = 0 ; j < 8 ;j++){ for (int j = 0 ; j < 8 ;j++){
...@@ -171,6 +175,11 @@ public class ChessBoardGUI extends JPanel { ...@@ -171,6 +175,11 @@ public class ChessBoardGUI extends JPanel {
} }
} }
} }
/***
* change the background color of possible moves to red
* @param moveBoard possible moves of the piece
*/
private void updateGUIBoard(boolean [][] moveBoard){ private void updateGUIBoard(boolean [][] moveBoard){
if(moveBoard ==null) return;; if(moveBoard ==null) return;;
for (int i = 0 ; i < 8 ;i++){ for (int i = 0 ; i < 8 ;i++){
...@@ -188,6 +197,14 @@ public class ChessBoardGUI extends JPanel { ...@@ -188,6 +197,14 @@ public class ChessBoardGUI extends JPanel {
} }
} }
} }
/**
*
* @param board
* @param pw
* @param pb
* @return
*/
private int checkmateCondition(Cell board[][], Piece pw[], Piece pb[]) { private int checkmateCondition(Cell board[][], Piece pw[], Piece pb[]) {
if (checkCondition(board, pw, pb, 1) == 1) { if (checkCondition(board, pw, pb, 1) == 1) {
for (Piece p:pw) { for (Piece p:pw) {
...@@ -286,6 +303,12 @@ public class ChessBoardGUI extends JPanel { ...@@ -286,6 +303,12 @@ public class ChessBoardGUI extends JPanel {
board[p.getCell().getRow()][p.getCell().getCol()] = p.getCell() ; board[p.getCell().getRow()][p.getCell().getCol()] = p.getCell() ;
} }
} }
/**
*give coordinate of a piece and shows the possible moves
* @param source the coordinates that move start from
* @return list of possible moves in a binary board
*/
public boolean[][] moves(Cell source){ public boolean[][] moves(Cell source){
boolean[][] binaryBoard = new boolean[8][8]; boolean[][] binaryBoard = new boolean[8][8];
if (wORb%2==0) { if (wORb%2==0) {
...@@ -318,6 +341,13 @@ public class ChessBoardGUI extends JPanel { ...@@ -318,6 +341,13 @@ public class ChessBoardGUI extends JPanel {
} }
return null; return null;
} }
/**
* it gets a source and destination and moves piece from source to destination
* @param source a coordinates that move has started from
* @param dest a coordinates that is our destination
* @return true if the change was possible and piece moved
*/
public boolean movePiece(Cell source, Cell dest){ public boolean movePiece(Cell source, Cell dest){
//-------------- //--------------
if (wORb%2==0) { if (wORb%2==0) {
...@@ -421,6 +451,11 @@ public class ChessBoardGUI extends JPanel { ...@@ -421,6 +451,11 @@ public class ChessBoardGUI extends JPanel {
//-------------- //--------------
return false; return false;
} }
/**
*when we call this method the last changes of the board are shown
* @return the final board with changes
*/
public Piece[][] getUpdatedBoard(){ public Piece[][] getUpdatedBoard(){
Piece[][] pieceboard = new Piece[8][8]; Piece[][] pieceboard = new Piece[8][8];
Piece pw[] = white.getPieces() ; Piece pw[] = white.getPieces() ;
...@@ -435,6 +470,15 @@ public class ChessBoardGUI extends JPanel { ...@@ -435,6 +470,15 @@ public class ChessBoardGUI extends JPanel {
} }
return pieceboard; return pieceboard;
} }
/**
* it check Condition for pieces that are instance of white or black kings.
* @param board the board of the game
* @param pw the piece that belongs to white player
* @param pb the piece that belong to black player
* @param flag
* @return
*/
private int checkCondition(Cell board[][], Piece pw[], Piece pb[], int flag) { private int checkCondition(Cell board[][], Piece pw[], Piece pb[], int flag) {
for (Piece p:pw) { for (Piece p:pw) {
if (p instanceof King) { if (p instanceof King) {
......
...@@ -63,8 +63,8 @@ public class ChessGameGUI extends JFrame { ...@@ -63,8 +63,8 @@ public class ChessGameGUI extends JFrame {
} }
/** /**
* creating a socket and waits for a client to connect with 1234 port as soon as * creating a socket and waits for a client to connect with 1234 port . as soon as
* a client connected to the socket it gets an inputStream and outputStream * a client connected to the socket it gets an Stream as an input(inputStream) and output as an output(outputStream).
*/ */
private void server(){ private void server(){
try { try {
...@@ -98,7 +98,9 @@ public class ChessGameGUI extends JFrame { ...@@ -98,7 +98,9 @@ public class ChessGameGUI extends JFrame {
} }
/** /**
* try to connect to the socket and gets an inputStream and outputStream * try to connect to the socket server and gets an inputStream and outputStream
* we write changes of the games on outputStream and send it to other app
* we read inputs of inputStream then change the game
* @param address address is an input we give to the system which is the address of the server * @param address address is an input we give to the system which is the address of the server
*/ */
private void client(String address){ private void client(String address){
......
...@@ -84,6 +84,10 @@ public abstract class Piece { ...@@ -84,6 +84,10 @@ public abstract class Piece {
return pieceColor; return pieceColor;
} }
/**
* check that if the piece is deleted or not
* @return deleted if it was true
*/
public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment