Chess

20
CHESS GAME CHESS GAME A Project On A Project On Object Oriented Programming In Java Object Oriented Programming In Java

description

Chess is a two-player board game played on a chessboard, a square-checkered board with 64 squares arranged in an eight-by-eight grid.

Transcript of Chess

Page 1: Chess

CHESS GAMECHESS GAME A Project OnA Project On

Object Oriented Programming In JavaObject Oriented Programming In Java

Page 2: Chess

Submission DetailsSubmission Details

Submitted by:Iffat Anjum

Roll: 16.Md. Maruful Haque

Roll:37.Abdullah Al-Matin

Roll:23.Date:06/04/2011

Submitted to:Dr. Md. Rezaul Karim Associate Professor.Ashis Kumer Biswas

Lecturer.Mitra Kabir

Lecturer.

Page 3: Chess

IntroductionIntroductionChess is a two-player board game played on

a chessboard, a square-checkered board with 64 squares arranged in an eight-by-eight grid.

Each player begins the game with sixteen pieces: ◦ One king,◦ One queen, ◦ Two rooks, ◦ Two knights, ◦ Two bishops, and ◦ Eight pawns.

Page 4: Chess

First view of the Chess Board First view of the Chess Board

Page 5: Chess

Discussion On CodeDiscussion On CodeWe are discussing the Code in these

segments:◦ Graphical interface.◦ Movement of prawns.◦ Movement of King.◦ Movement of Queen.◦ Movement of Rooks.◦ Movement of Knights.◦ Movement of Bishops.◦ Synchronization and Control.◦ Defining wined player.◦ Networking.

Page 6: Chess

Graphical interfaceGraphical interface

To made the graphical interface we have first created a “frame” using “Jframe” class, Which gives us an window with the name and closing options on which we can include other components.

Page 7: Chess

Graphical interfaceGraphical interfaceNow we have created an “Panel” using

“JPanel” class which is a light weight container, that contains the other component of the chess board. The background is black.

In the upper portion of the panel we have the main chess board, with the size of (500,500).

On that we have drawn 64 rectangles, as a chess board.

In the Center of the panel we are displaying the messages giving commands to the players.

Page 8: Chess

Graphical interfaceGraphical interface

Page 9: Chess

Graphical interfaceGraphical interfaceIn the lower portion of the panel we are

using Color(75,141,221) to set light blue color as background, we have created two text field to give the two players’ name.

Two buttons one for setting the names and another for starting the game.

Page 10: Chess

Graphical interfaceGraphical interface

We are using MediaTracker class to load the images of the chess pieces.

We are creating two different array for staring the name of blue and red pieces.

We first initially set our chess board according to the rule.

Then after each change we first check if the change is valid, if valid use “repaint()” to refresh the chess board.

Page 11: Chess

Movement of PawnMovement of PawnAs we know that Pawn can only move

straight one position at a time, so the column position remains same only row changes.

Only go to the other side of the board. So that if its player one’s pawn its destination row will smaller and if player two’s pawn it will increase against its starting row.

It can go to diagonally one position only if there is opponents’ piece. So if there is a diagonal move we have to check if there is any opponent piece.

Page 12: Chess

Movement of King Movement of King

The king can move one position at a time, any direction straightly or diagonally. We can define the path: ◦ For straight path, we have to check if the row has

changed one position and column has not changed, or if the column changed and row unchanged. ◦ For diagonal path we have to check if row and

column both has changed by one positon.

Page 13: Chess

Movement of QueenMovement of QueenThe Queen can move in any direction and

any number of positions, diagonally and straight.

For this we have to first define, if it is moving straight, by checking: if the row position or the column position remains same, Or if it is moving diagonally, by checking if the difference between the rows and columns are same.

After defining the path we have to check each position in this path if these is any other chess piece in it. If there are ,the move is invalid.

Page 14: Chess

Movement of RookMovement of Rook

The rook can move any direction and any number of position, straight.

For this we have to first define, if it is moving straight, by checking if the row position or the column position remains same.

After defining the path we have to check each position in this path if these is any other chess piece in it. If there are ,the move is invalid.

Page 15: Chess

Movement of BishopMovement of Bishop

The Knight can move in any direction and any number of positions, diagonally .

For this we have to first define, if it is moving diagonally, by checking if the difference between the rows and columns are same.

After defining the path we have to check each position in this path if these is any other chess piece in it. If there are ,the move is invalid.

Page 16: Chess

Movement of knight Movement of knight The knight can move any direction in a “L”

shape.To define the “L” shape ,we have to check: ◦ if the row has changed in two position and the

column in one,◦ Or if the column has changed in two position and

the row in one. After defining the path we have to check

each position in this path if these is any other chess piece in it. If there are ,the move is invalid.

Page 17: Chess

Synchronization and controlSynchronization and control

To save the position of chess pieces of each player we are using two (8*8) array .

We are using 1 to indicate player one’s piece and 2 to indicate player two’s and 0 if there is no piece, Initializing playerMatrix according to current positions by them.

We are using 0 for pawn, 1 for rock, 2 for knight, 3 for bishop, 4 for queen, 5 for king, 6 empty ,and initializing pieceMatrix according to current positions of the board by them.

Page 18: Chess

Synchronization and controlSynchronization and controlWe are using KeyEvent class extending the

keylistener to have name inputs from the keyboard.

We are using MouseEvent class extending the Mouselistener to have inputs from the mouse.◦ Mouse can select a piece by clicking on it ,if the

piece is the current player’s, thus the player which has the turn to move.◦ The mouse can drag any piece to any position. ◦ It can drop the piece in any position it wants, then

we have check if the position is valid.

Page 19: Chess

Defining the winnerDefining the winnerHere in our project ,we have check every

time we have an valid move, if the opponent has the king, if don’t have then the current player wins.

Its is one of our limitation of our code, cause as we all know , the game ends when checkmate the opponent's king, whereby the king is under immediate attack (in "check") and there is no way to remove or defend it from attack on the next move. But we couldn’t define the “check” properly.

Page 20: Chess

Other….Other….There are another limitation of our project

there is no artificial intelligence, means there is no way to play with the computer.

Thank YouThank You