-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="activation" level="project" /> | ||
<orderEntry type="library" name="beautyeye_lnf" level="project" /> | ||
<orderEntry type="library" name="javax.mail" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: Main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: Main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import view.home.HomeFrame; | ||
|
||
import javax.swing.*; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
try { | ||
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
SwingUtilities.invokeLater(() -> { | ||
HomeFrame homeFrame = new HomeFrame(1300, 730); | ||
homeFrame.setVisible(true); | ||
|
||
}); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package components; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
public abstract class BasicComponent extends JComponent { | ||
public BasicComponent() { | ||
this.addMouseListener(new MouseAdapter() { | ||
@Override | ||
public void mouseReleased(MouseEvent e) { | ||
onMouseReleased(e); | ||
} | ||
|
||
@Override | ||
public void mouseMoved(MouseEvent e) { | ||
onMouseMoved(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @author Bill | ||
* @description 重写此方法,点击时调用 | ||
**/ | ||
public abstract void onMouseReleased(MouseEvent e); | ||
|
||
/** | ||
* @author Bill | ||
* @description 重写此方法,鼠标移动时调用 | ||
**/ | ||
public abstract void onMouseMoved(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package components; | ||
|
||
import controller.BoardController; | ||
import model.GameStack; | ||
import view.game.GameFrame; | ||
import view.game.VideoPanel; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.MouseEvent; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* @author Bill | ||
* @description 每个棋格 棋格组件类 | ||
**/ | ||
public class ChessGridComponent extends BasicComponent { | ||
public static int chessSize; //棋子的直径 | ||
public static final int gridSize = 79; //棋格的边长 | ||
private static final Color LIGHT_COLOR = new Color(144, 186, 200); //棋格的颜色 | ||
private static final Color DARK_COLOR = new Color(82, 138, 158); //棋格的颜色 | ||
private final Color color; | ||
private ChessPiece oldPiece; | ||
private ChessPiece chessPiece; | ||
private VideoPanel videoPanel = new VideoPanel(); | ||
|
||
private int row; //行 y | ||
private int col; //列 x | ||
|
||
private boolean justNow; //是否是刚刚下的子 | ||
|
||
public ChessGridComponent(int col, int row) { | ||
this.setSize(gridSize + 2, gridSize + 2); //设置棋格的边长 | ||
this.row = row; //鼠标所在的行 | ||
this.col = col; //鼠标所在的列 | ||
//格子的颜色深浅不同 | ||
if ((row + col) % 2 == 0) { | ||
color = LIGHT_COLOR; | ||
} else { | ||
color = DARK_COLOR; | ||
} | ||
oldPiece = chessPiece; | ||
// videoPanel = new VideoPanel(); | ||
// videoPanel.setVisible(true); | ||
|
||
|
||
} | ||
|
||
public ChessPiece getChessPiece() { | ||
return chessPiece; | ||
} | ||
|
||
|
||
public void setChessPiece(ChessPiece chessPiece) { | ||
this.chessPiece = chessPiece; | ||
} | ||
|
||
public void setOldPiece(ChessPiece oldPiece) { | ||
this.oldPiece = oldPiece; | ||
} | ||
|
||
public int getRow() { | ||
return row; | ||
} | ||
|
||
public int getCol() { | ||
return col; | ||
} | ||
|
||
/** | ||
* @author Bill | ||
* @description 画每个格子的颜色(如果有棋子也画) | ||
**/ | ||
public void drawPiece(Graphics g) { | ||
if (GameFrame.controller.getTheme() == Theme.BLUE) { | ||
g.setColor(color); | ||
//是fill,不是draw!! | ||
g.fill3DRect(4, 4, gridSize, gridSize, true); | ||
} else if (GameFrame.controller.getTheme() == Theme.ELEGANT) { | ||
Graphics2D g1 = (Graphics2D) g; | ||
g1.setStroke(new BasicStroke(2)); | ||
// g1.setColor(); | ||
g1.drawRect(2, 2, gridSize, gridSize); | ||
} else if (GameFrame.controller.getTheme() == Theme.CLASSIC) { | ||
|
||
} | ||
|
||
//标记可以下的点 | ||
//半透明圆圈 | ||
GameFrame.controller.setBoardController(); | ||
BoardController b = GameFrame.controller.getBoardController(); | ||
g.setColor(Color.GREEN); | ||
if (b.isLegalPlace(true, row, col)) { | ||
if (GameFrame.controller.getCurrentPlayer() == ChessPiece.BLACK) { | ||
g.drawImage(Transparent.BLACK.getImage(), 20, 20, null); | ||
} else { | ||
g.drawImage(Transparent.WHITE.getImage(), 20, 20, null); | ||
} | ||
|
||
} | ||
|
||
|
||
if (oldPiece != chessPiece && !justNow && GameFrame.controller.isVideoOn()) { | ||
|
||
g.setColor(color); | ||
//是fill,不是draw!! | ||
g.fill3DRect(4, 4, gridSize, gridSize, true); | ||
|
||
|
||
boolean b1 = true; | ||
if (oldPiece == ChessPiece.BLACK && chessPiece == ChessPiece.WHITE) { | ||
b1 = false; | ||
} else if (oldPiece == ChessPiece.WHITE && chessPiece == ChessPiece.BLACK) { | ||
b1 = true; | ||
} | ||
|
||
|
||
videoPanel = new VideoPanel(); | ||
// System.out.print(Thread.currentThread()); | ||
videoPanel.setLocation(6, 7); | ||
add(videoPanel); | ||
videoPanel.setVisible(true); | ||
boolean finalB = b1; | ||
|
||
Runnable r1 = new Thread(() -> videoPanel.playVideo(chessPiece, finalB)); | ||
|
||
SwingUtilities.invokeLater(r1); | ||
|
||
|
||
// try { | ||
// Thread.sleep(700); | ||
// } catch (InterruptedException e) { | ||
// e.printStackTrace(); | ||
// } | ||
// g.drawImage(chessPiece.getImage(), 7, 7, null); | ||
|
||
|
||
} else if (chessPiece != null) { | ||
g.drawImage(chessPiece.getImage(), 7, 7, null); | ||
} | ||
|
||
oldPiece = chessPiece; | ||
|
||
if (justNow) { | ||
g.setColor(Color.RED); | ||
g.fillOval(38, 38, 10, 10); | ||
} | ||
} | ||
|
||
@Override | ||
protected void paintComponent(Graphics g) { | ||
super.paintComponent(g); | ||
drawPiece(g); | ||
} | ||
|
||
@Override | ||
public void onMouseReleased(MouseEvent e) { | ||
if (e.getButton() == MouseEvent.BUTTON1 && | ||
!(GameFrame.controller.isMachineMode() && | ||
GameFrame.controller.getCurrentPlayer() != GameFrame.controller.getManPiece())) { //鼠标左键按下 | ||
System.out.printf("%s clicked (%d, %d)\n", GameFrame.controller.getCurrentPlayer(), row, col); | ||
GameFrame.controller.click(row, col); | ||
} | ||
|
||
|
||
// HomeFrame.gameFrame.repaint(); | ||
} | ||
|
||
@Override | ||
public void onMouseMoved() { | ||
// repaint(); | ||
System.out.println("fhasdjhfkladjfklaj;fa"); | ||
} | ||
|
||
public boolean isJustNow() { | ||
return justNow; | ||
} | ||
|
||
public void setJustNow(boolean justNow) { | ||
this.justNow = justNow; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package components; | ||
|
||
import gameUtil.Path; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Bill | ||
* @description 单个棋子组件 | ||
**/ | ||
public enum ChessPiece { | ||
BLACK(Path.BLACK_PIECE, -1, "黑方"), | ||
WHITE(Path.WHITE_PIECE, 1, "白方"); | ||
|
||
private BufferedImage image; | ||
private int color; | ||
private String name; | ||
|
||
ChessPiece(String filePath, int color, String name) { | ||
try { | ||
image = ImageIO.read(new File(filePath)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
this.color = color; | ||
this.name = name; | ||
} | ||
|
||
public BufferedImage getImage() { | ||
return image; | ||
} | ||
|
||
public int getColor() { | ||
return color; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |