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
9631408
Chess
Commits
6f8bb035
Commit
6f8bb035
authored
May 22, 2019
by
kimia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pawn move
parent
a771ed9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
ChessBoardGUI.java
src/ChessBoardGUI.java
+2
-1
Pawn.java
src/Pawn.java
+15
-11
No files found.
src/ChessBoardGUI.java
View file @
6f8bb035
...
@@ -21,7 +21,8 @@ public class ChessBoardGUI extends JPanel {
...
@@ -21,7 +21,8 @@ public class ChessBoardGUI extends JPanel {
public
ChessBoardGUI
(
JPanel
removedPiecePanel
){
public
ChessBoardGUI
(
JPanel
removedPiecePanel
){
super
();
super
();
this
.
removedPiecePanel
=
removedPiecePanel
;
this
.
removedPiecePanel
=
removedPiecePanel
;
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize
(
800
,
600
);
setSize
(
800
,
600
);
...
...
src/Pawn.java
View file @
6f8bb035
public
class
Pawn
extends
Piece
{
public
class
Pawn
extends
Piece
{
private
boolean
once
,
end
;
private
boolean
once
,
end
;
public
Pawn
(
Cell
cell
,
PieceColor
pieceC
olor
)
{
public
Pawn
(
Cell
cell
,
PieceColor
c
olor
)
{
super
(
cell
,
pieceC
olor
)
;
super
(
cell
,
c
olor
)
;
this
.
once
=
true
;
this
.
once
=
true
;
this
.
end
=
false
;
this
.
end
=
false
;
}
}
...
@@ -18,18 +18,22 @@ public class Pawn extends Piece{
...
@@ -18,18 +18,22 @@ public class Pawn extends Piece{
@Override
@Override
public
boolean
isValidMove
(
Cell
c
,
Cell
board
[][],
Piece
pw
[],
Piece
pb
[])
{
public
boolean
isValidMove
(
Cell
c
,
Cell
board
[][],
Piece
pw
[],
Piece
pb
[])
{
if
(
super
.
isDeleted
())
return
false
;
if
(
super
.
isDeleted
())
return
false
;
if
(
super
.
getPieceColor
()==
PieceColor
.
BLACK
&&
super
.
getCell
().
getRow
()==
0
)
end
=
true
;
if
(
super
.
getPieceColor
()==
PieceColor
.
BLACK
&&
super
.
getCell
().
getRow
()==
0
)
end
=
true
;
if
(
super
.
getPieceColor
()==
PieceColor
.
WHITE
&&
super
.
getCell
().
getRow
()==
7
)
end
=
true
;
if
(
super
.
getPieceColor
()==
PieceColor
.
WHITE
&&
super
.
getCell
().
getRow
()==
7
)
end
=
true
;
int
sw
=
0
;
int
sw
=
0
;
if
(
super
.
getPieceColor
()
==
PieceColor
.
BLACK
)
{
if
(
super
.
getPieceColor
()
==
PieceColor
.
BLACK
)
{
for
(
Piece
p:
pw
)
{
for
(
Piece
p:
pw
)
{
if
(!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()==
c
.
getRow
()
&&
p
.
getCell
().
getCol
()==
c
.
getCol
())
sw
=
1
;
if
(!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()==
c
.
getRow
()
&&
p
.
getCell
().
getCol
()==
c
.
getCol
()
&&
c
.
getRow
()-
this
.
getCell
().
getRow
()==-
1
&&
Math
.
abs
(
this
.
getCell
().
getCol
()-
c
.
getCol
())==
1
)
sw
=
1
;
}
}
}
}
else
{
else
{
for
(
Piece
p:
pb
)
{
for
(
Piece
p:
pb
)
{
if
(!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()==
c
.
getRow
()
&&
p
.
getCell
().
getCol
()==
c
.
getCol
())
sw
=
1
;
if
(!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()==
c
.
getRow
()
&&
p
.
getCell
().
getCol
()==
c
.
getCol
()
&&
c
.
getRow
()-
this
.
getCell
().
getRow
()==
1
&&
Math
.
abs
(
this
.
getCell
().
getCol
()-
c
.
getCol
())==
1
)
sw
=
1
;
}
}
}
}
...
@@ -55,13 +59,13 @@ public class Pawn extends Piece{
...
@@ -55,13 +59,13 @@ public class Pawn extends Piece{
}
}
else
{
else
{
if
(
if
(
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
c
.
isEmpty
()
&&
((
this
.
getCell
().
getRow
()-
c
.
getRow
()==
1
&&
super
.
getPieceColor
()==
PieceColor
.
BLACK
)
||
((
this
.
getCell
().
getRow
()-
c
.
getRow
()==
1
&&
super
.
getPieceColor
()==
PieceColor
.
BLACK
)
||
(
this
.
getCell
().
getRow
()-
c
.
getRow
()==-
1
&&
super
.
getPieceColor
()==
PieceColor
.
WHITE
))
)
(
this
.
getCell
().
getRow
()-
c
.
getRow
()==-
1
&&
super
.
getPieceColor
()==
PieceColor
.
WHITE
))
)
||
||
(
Math
.
abs
(
this
.
getCell
().
getCol
()-
c
.
getCol
())==
Math
.
abs
(
this
.
getCell
().
getRow
()-
c
.
getRow
())
&&
(
Math
.
abs
(
this
.
getCell
().
getCol
()-
c
.
getCol
())==
Math
.
abs
(
this
.
getCell
().
getRow
()-
c
.
getRow
())
&&
((
this
.
getCell
().
getRow
()-
c
.
getRow
()==
1
&&
super
.
getPieceColor
()==
PieceColor
.
BLACK
&&
sw
==
1
)
||
((
this
.
getCell
().
getRow
()-
c
.
getRow
()==
1
&&
super
.
getPieceColor
()==
PieceColor
.
BLACK
&&
sw
==
1
)
||
(
this
.
getCell
().
getRow
()-
c
.
getRow
()==-
1
&&
super
.
getPieceColor
()==
PieceColor
.
WHITE
&&
sw
==
1
))
)
(
this
.
getCell
().
getRow
()-
c
.
getRow
()==-
1
&&
super
.
getPieceColor
()==
PieceColor
.
WHITE
&&
sw
==
1
))
)
)
return
true
;
)
return
true
;
else
return
false
;
else
return
false
;
}
}
...
...
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