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
db33b6b9
Commit
db33b6b9
authored
May 20, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isPossible move method add in GUI
parent
06a3cff9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
2 deletions
+74
-2
Main.java
src/game/Main.java
+74
-2
No files found.
src/game/Main.java
View file @
db33b6b9
...
@@ -6,6 +6,7 @@ import javax.swing.*;
...
@@ -6,6 +6,7 @@ import javax.swing.*;
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseListener
;
import
java.util.ArrayList
;
/**
/**
* @author Newsha Shahbodaghkhan
* @author Newsha Shahbodaghkhan
...
@@ -22,6 +23,9 @@ public class Main extends JFrame implements MouseListener{
...
@@ -22,6 +23,9 @@ public class Main extends JFrame implements MouseListener{
private
static
Main
Mainboard
;
private
static
Main
Mainboard
;
// private JButton[][] chessBoardSquares ;
// private JButton[][] chessBoardSquares ;
private
Square
[][]
chessBoardSquares
;
private
Square
[][]
chessBoardSquares
;
private
boolean
select
=
false
;
private
Square
lastSquare
;
private
Piece
lastPiece
;
private
JFrame
myFrame
;
private
JFrame
myFrame
;
private
static
Rook
wr01
,
wr02
,
br01
,
br02
;
private
static
Rook
wr01
,
wr02
,
br01
,
br02
;
private
static
Knight
wk01
,
wk02
,
bk01
,
bk02
;
private
static
Knight
wk01
,
wk02
,
bk01
,
bk02
;
...
@@ -216,15 +220,83 @@ private Main() {
...
@@ -216,15 +220,83 @@ private Main() {
centerpanel
.
add
(
chessBoardSquares
[
i
][
j
]);
centerpanel
.
add
(
chessBoardSquares
[
i
][
j
]);
}
}
}
}
// MouseListener mouseListener = null;
for
(
int
i
=
0
;
i
<
8
;
i
++){
for
(
int
j
=
0
;
j
<
8
;
j
++){
chessBoardSquares
[
i
][
j
].
addMouseListener
(
this
);
}
}
// chessBoardSquares
// String whosTurn = "white";
// while(bk.isCheckMate(chessBoardSquares)){
//
// }
myFrame
.
setVisible
(
true
);
myFrame
.
setVisible
(
true
);
myFrame
.
setResizable
(
true
);
myFrame
.
setResizable
(
true
);
myFrame
.
setExtendedState
(
myFrame
.
getExtendedState
()
|
JFrame
.
MAXIMIZED_BOTH
);
myFrame
.
setExtendedState
(
myFrame
.
getExtendedState
()
|
JFrame
.
MAXIMIZED_BOTH
);
}
}
@Override
@Override
public
void
mouseClicked
(
MouseEvent
e
){
public
void
mouseClicked
(
MouseEvent
e
)
{
if
(!
select
)
{
((
Square
)
(
e
.
getSource
())).
selectSquare
();
}
else
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
chessBoardSquares
[
i
][
j
].
cancleSelection
();
}
}
((
Square
)
(
e
.
getSource
())).
selectSquare
();
}
select
=
true
;
// Square square1 = null;
// Piece piece1 = null;
if
(((
Square
)
(
e
.
getSource
())).
getPiece
()!=
null
)
{
lastSquare
=
((
Square
)
(
e
.
getSource
()));
lastPiece
=
((
Square
)
(
e
.
getSource
())).
getPiece
();
}
if
(((
Square
)
(
e
.
getSource
())).
getPiece
()!=
null
){
ArrayList
<
Square
>
possibleMoves
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
8
;
i
++){
for
(
int
j
=
0
;
j
<
8
;
j
++){
//
if
(
chessBoardSquares
[
i
][
j
].
isSelected
()){
Piece
piece
=
chessBoardSquares
[
i
][
j
].
getPiece
();
possibleMoves
=
piece
.
move
(
chessBoardSquares
,
i
,
j
);
}
}
}
for
(
Square
ps:
possibleMoves
){
ps
.
makePossible
();
}
// System.out.println(piece1+"/"+square1);
if
(((
Square
)
(
e
.
getSource
())).
isPossibleSquare
()&&((
Square
)
(
e
.
getSource
())).
isSelected
()){
// if (lastSquare != null)
((
Square
)
(
e
.
getSource
())).
setPiece
(
lastPiece
);
// if (lastSquare != null) {
lastSquare
.
removePiece
();
}
}
}
}
@Override
@Override
public
void
mouseEntered
(
MouseEvent
arg0
){
public
void
mouseEntered
(
MouseEvent
arg0
){
...
...
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