Commit cc4b8713 authored by kimia's avatar kimia

final check

parent 4f26b735
......@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class ChessBoardGUI extends JPanel {
static boolean isServer = false ;
public static boolean isServer = false ;
private PrintWriter out;
public JButton[][] button = new JButton[8][8];
......@@ -94,7 +94,7 @@ public class ChessBoardGUI extends JPanel {
// setVisible(true);
}
public void updatesAfterMove(){
buttonRepaint();
buttonUpdate();
updateDeletedPanel();
//----------------
int condition = checkmateCondition(board,pw,pb);
......@@ -154,7 +154,11 @@ public class ChessBoardGUI extends JPanel {
out.flush();
}
private void buttonRepaint(){
/**
* it updates the graphical page , it changes the pieces with the new actions
*/
private void buttonUpdate(){
Piece[][] pieceBoard = getUpdatedBoard();
for (int i = 0 ;i<8 ;i++){
for (int j = 0 ; j < 8 ;j++){
......@@ -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){
if(moveBoard ==null) return;;
for (int i = 0 ; i < 8 ;i++){
......@@ -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[]) {
if (checkCondition(board, pw, pb, 1) == 1) {
for (Piece p:pw) {
......@@ -286,6 +303,12 @@ public class ChessBoardGUI extends JPanel {
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){
boolean[][] binaryBoard = new boolean[8][8];
if (wORb%2==0) {
......@@ -318,6 +341,13 @@ public class ChessBoardGUI extends JPanel {
}
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){
//--------------
if (wORb%2==0) {
......@@ -421,6 +451,11 @@ public class ChessBoardGUI extends JPanel {
//--------------
return false;
}
/**
*when we call this method the last changes of the board are shown
* @return the final board with changes
*/
public Piece[][] getUpdatedBoard(){
Piece[][] pieceboard = new Piece[8][8];
Piece pw[] = white.getPieces() ;
......@@ -435,6 +470,15 @@ public class ChessBoardGUI extends JPanel {
}
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) {
for (Piece p:pw) {
if (p instanceof King) {
......
......@@ -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
* a client connected to the socket it gets an inputStream and outputStream
* 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 Stream as an input(inputStream) and output as an output(outputStream).
*/
private void server(){
try {
......@@ -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
*/
private void client(String address){
......
......@@ -84,6 +84,10 @@ public abstract class Piece {
return pieceColor;
}
/**
* check that if the piece is deleted or not
* @return deleted if it was true
*/
public boolean isDeleted() {
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