Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
chess
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9611046
chess
Commits
72f9a332
Commit
72f9a332
authored
Jun 30, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation
parent
d81eeeb2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
145 additions
and
4 deletions
+145
-4
Main.java
src/game/Main.java
+17
-1
Bishop.java
src/pieces/Bishop.java
+20
-0
King.java
src/pieces/King.java
+42
-2
Knight.java
src/pieces/Knight.java
+16
-0
Pawn.java
src/pieces/Pawn.java
+16
-1
Queen.java
src/pieces/Queen.java
+18
-0
Rook.java
src/pieces/Rook.java
+16
-0
No files found.
src/game/Main.java
View file @
72f9a332
...
...
@@ -255,12 +255,28 @@ public class Main extends JFrame implements MouseListener {
Mainboard
=
new
Main
();
}
private
void
changeTurn
()
{
/**
* performs changing turn of players
*/
public
void
changeTurn
()
{
if
(
whosTurn
.
equals
(
"w"
))
whosTurn
=
"b"
;
else
whosTurn
=
"w"
;
}
/*
public boolean checkmateCheck(Square [][] chessBoardSquares){
}
*/
/**
*
* @param color is the player color
* @param board is current board
* @return true if the player king piece is checked
*/
private
boolean
isChecked
(
String
color
,
Square
[][]
board
)
{
if
(
color
.
equals
(
"w"
))
return
wk
.
isChecked
(
board
);
else
if
(
color
.
equals
(
"b"
))
return
bk
.
isChecked
(
board
);
...
...
src/pieces/Bishop.java
View file @
72f9a332
...
...
@@ -5,13 +5,33 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
*Bishop class show the Bishop's moves that moves and set its ID imagePath and color
*/
public
class
Bishop
extends
Piece
{
//constructor
/**
*
* @param ID set ID of bishop
* @param imagePath set image of bishop
* @param color set color of bishop
*/
public
Bishop
(
String
ID
,
String
imagePath
,
String
color
)
{
setPieceId
(
ID
);
setImage
(
imagePath
);
setPieceColor
(
color
);
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of bishop in board
* @param y is the y of bishop in board
* @return arraylist of next possible squares of bishop
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
boardSquares
,
int
x
,
int
y
)
{
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
ArrayList
<
Square
>
possibleSquares
=
new
ArrayList
<>();
...
...
src/pieces/King.java
View file @
72f9a332
...
...
@@ -5,8 +5,19 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
* *King class show the King's moves that moves and set its ID imagePath and color
*/
public
class
King
extends
Piece
{
private
int
x
,
y
;
/**
*
* @param ID set ID of king
* @param imagePath set image king
* @param color set color of king
*/
public
King
(
String
ID
,
String
imagePath
,
String
color
,
int
x
,
int
y
)
{
this
.
x
=
x
;
...
...
@@ -16,27 +27,51 @@ public class King extends Piece {
setPieceColor
(
color
);
}
public
King
()
{
}
/**
*
* @param x set x coordinate of king
*/
public
void
setx
(
int
x
)
{
this
.
x
=
x
;
}
/**
*
* @param y set y coordinate of a king
*/
public
void
sety
(
int
y
)
{
this
.
y
=
y
;
}
/**
*
* @return x coordinate of king
*/
public
int
getx
()
{
return
x
;
}
/**
*
* @return y coordinate of king
*/
public
int
gety
()
{
return
y
;
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of king in board
* @param y is the y of king in board
* @return arraylist of next possible squares of king
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
squares
,
int
x
,
int
y
){
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
ArrayList
<
Square
>
possibleSquares
=
new
ArrayList
<>();
...
...
@@ -53,6 +88,11 @@ public class King extends Piece {
return
possibleSquares
;
}
/**
*
* @param squares current situation of a board
* @return true if king is checked
*/
public
boolean
isChecked
(
Square
[][]
squares
){
//Checking for attack from left,right,up and down
for
(
int
i
=
x
+
1
;
i
<
8
;
i
++)
...
...
src/pieces/Knight.java
View file @
72f9a332
...
...
@@ -4,14 +4,30 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
*Bishop class show the Knight's moves that moves and set its ID imagePath and color
*/
public
class
Knight
extends
Piece
{
/**
*
* @param ID set ID of Knight
* @param imagePath set image of Knight
* @param color set color of Knight
*/
public
Knight
(
String
ID
,
String
imagePath
,
String
color
)
{
setPieceId
(
ID
);
setImage
(
imagePath
);
setPieceColor
(
color
);
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of Knight in board
* @param y is the y of Knight in board
* @return arraylist of next possible squares of Knight
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
boardSquares
,
int
x
,
int
y
)
{
ArrayList
<
Square
>
possibleSquares
=
new
ArrayList
<>();
//possibleSquares.clear();
...
...
src/pieces/Pawn.java
View file @
72f9a332
...
...
@@ -4,10 +4,19 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
* *King class show the Pawn's moves that moves and set its ID imagePath and color
*/
public
class
Pawn
extends
Piece
{
/**
*
* @param ID set ID of Pawn
* @param imagePath set image of Pawn
* @param color set color of Pawn
*/
public
Pawn
(
String
ID
,
String
imagePath
,
String
color
){
setPieceId
(
ID
);
setImage
(
imagePath
);
...
...
@@ -15,6 +24,12 @@ public class Pawn extends Piece {
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of Pawn in board
* @param y is the y of Pawn in board
* @return arraylist of next possible squares of Pawn
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
boardSquares
,
int
x
,
int
y
)
{
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
// possibleSquares.clear();
...
...
src/pieces/Queen.java
View file @
72f9a332
...
...
@@ -5,7 +5,18 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
* *King class show the Queen's moves that moves and set its ID imagePath and color
*/
public
class
Queen
extends
Piece
{
/**
*
* @param ID set ID of Queen
* @param imagePath set image of Queen
* @param color set color of Queen
*/
public
Queen
(
String
ID
,
String
imagePath
,
String
color
){
setPieceId
(
ID
);
...
...
@@ -13,6 +24,13 @@ public class Queen extends Piece {
setPieceColor
(
color
);
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of Queen in board
* @param y is the y of Queen in board
* @return arraylist of next possible squares of Queen
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
boardSquares
,
int
x
,
int
y
)
{
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
ArrayList
<
Square
>
possibleSquares
=
new
ArrayList
<>();
...
...
src/pieces/Rook.java
View file @
72f9a332
...
...
@@ -5,13 +5,29 @@ import game.Square;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* @author Newsha Shahbodaghkhan
* *King class show the Rook's moves that moves and set its ID imagePath and color
*/
public
class
Rook
extends
Piece
{
/**
*
* @param ID set ID of Rook
* @param imagePath set image of Rook
* @param color set color of Rook
*/
public
Rook
(
String
ID
,
String
imagePath
,
String
color
){
setPieceId
(
ID
);
setImage
(
imagePath
);
setPieceColor
(
color
);
}
@Override
/**
* @param boardSquare is the current board situation
* @param x is the x of Rook in board
* @param y is the y of Rook in board
* @return arraylist of next possible squares of Rook
*/
public
ArrayList
<
Square
>
move
(
Square
[][]
boardSquares
,
int
x
,
int
y
){
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
ArrayList
<
Square
>
possibleSquares
=
new
ArrayList
<>();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment