Skip to content

Commit 2eccee3

Browse files
committed
使用jar包资源
1 parent 6eb9059 commit 2eccee3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+164
-131
lines changed

src/main/java/client/computer/ComputerGame.java

+52-37
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ public class ComputerGame extends JFrame {
5454

5555
int ChessBoardWidth = 1800;
5656
int ChessBoardHeight = 1000;
57-
58-
BeginWindow parFrame;
59-
GamePlane gamepanel;
60-
JSplitPane chatPlane;
57+
GameRoomUtil gameRoomUtil = new GameRoomUtil();
58+
public BeginWindow parFrame;
59+
public GamePlane gamepanel;
60+
private JSplitPane chatPlane;
6161
JTextArea jt = new JTextArea();
6262
JScrollPane jscroll ;
63+
6364
public ComputerGame() {
6465

6566
}
@@ -79,7 +80,7 @@ public ComputerGame(BeginWindow parFrame,String username,int AlgLeave) {
7980
this.parFrame = parFrame;
8081

8182
//播放背景音乐
82-
GameRoomUtil.playBgmusic();
83+
new GameRoomUtil().playBgmusic();
8384

8485

8586
setResizable(false);
@@ -142,15 +143,15 @@ public void actionPerformed(ActionEvent e) {
142143
return;
143144
}
144145
if(sendtext.getText().contains("快点")) {
145-
GameRoomUtil.palyothermusic("source/flowerdie.mp3");
146+
gameRoomUtil.palyothermusic("flowerdie.mp3");
146147
}
147148

148149
if(sendtext.getText().contains("停止")) {
149150
GameRoomUtil.stopmusic();
150151
gamepanel.musicing = false;
151152
}
152153
if(sendtext.getText().contains("开始")) {
153-
GameRoomUtil.playBgmusic();
154+
new GameRoomUtil().playBgmusic();
154155
gamepanel.musicing = true;
155156
}
156157

@@ -260,7 +261,7 @@ public void windowDeactivated(java.awt.event.WindowEvent e) {
260261
class xiaqiThread extends Thread{
261262
GamePlane gmplane;
262263
MouseEvent e;
263-
264+
GameRoomUtil gameRoomUtil = new GameRoomUtil();
264265
CompututerAlg compututerAlg = new CompututerAlg();
265266
public xiaqiThread(GamePlane chessBoard, MouseEvent e) {
266267
this.gmplane = chessBoard;
@@ -312,7 +313,7 @@ public void run() {
312313
}else {
313314
gmplane.allChess[gmplane.rx][gmplane.ry] =2;
314315
}
315-
GameRoomUtil.palyothermusic("source/mousedown.mp3");
316+
gameRoomUtil.palyothermusic("mousedown.mp3");
316317
gmplane.chessPoint.add(gmplane.MyChessColor+","+(gmplane.rx*45+430)+","+(gmplane.ry*45+110));
317318
gmplane.isme = false;
318319

@@ -327,7 +328,7 @@ public void run() {
327328
gmplane.chessBoard.jt.append("系统:"+gmplane.dateFormat.format(new Date())+"\n 你赢得了比赛!!\n");
328329
gmplane.MyplayGamewinnum++;
329330
gmplane.GameWinAfter(gmplane);
330-
GameRoomUtil.palyothermusic("source/winmusic.mp3");
331+
gameRoomUtil.palyothermusic("winmusic.mp3");
331332
}else {
332333
ComputerXiaqi(gmplane);
333334
}
@@ -396,12 +397,14 @@ class GamePlane extends JSplitPane implements MouseListener{
396397
*
397398
*/
398399
private static final long serialVersionUID = 1L;
399-
static ImageIcon stopImage = new ImageIcon("source/stop.png");
400-
static ImageIcon bgImage = new ImageIcon("source/bgImage.jpg");
401-
static ImageIcon chatImage = new ImageIcon("source/chat.png");
402-
static ImageIcon moveImage = new ImageIcon("source/move.png");
403-
static ImageIcon beginBG = new ImageIcon("source/bfmusic.png");
404-
static ImageIcon StopBG = new ImageIcon("source/stopmusic.png");
400+
public ImageIcon stopImage;
401+
public ImageIcon bgImage;
402+
public ImageIcon chatImage;
403+
404+
public ImageIcon beginBG;
405+
public ImageIcon StopBG;
406+
public ImageIcon man ;
407+
public ImageIcon women ;
405408
BufferedImage qizi = null;
406409
BufferedImage bqizi = null;
407410
BufferedImage hqizi = null;
@@ -432,15 +435,16 @@ class GamePlane extends JSplitPane implements MouseListener{
432435
boolean isme = true;
433436
DecimalFormat df = new DecimalFormat("0.00");
434437
String gameplayer2 ="风萧萧兮易水寒";
435-
438+
public ImageIcon chessWhite;
439+
public ImageIcon chessBlack;
436440

437441
//白1黑2
438442
String MyChessColor ="black";
439443
int MyChessColorINT =2;
440444
String ComputerChessColor ="white";
441445
int ComputerChessColorINT = 1;
442446

443-
447+
private GameRoomUtil gameRoomUtil = new GameRoomUtil();
444448

445449
BufferedImage Colorstaus;
446450
//胜率
@@ -454,8 +458,7 @@ class GamePlane extends JSplitPane implements MouseListener{
454458
int PlayGamenum = 0;
455459

456460
boolean kaishi = false;
457-
ImageIcon man = new ImageIcon("source/man.jpg");
458-
ImageIcon women = new ImageIcon("source/women.jpg");
461+
459462

460463
URL classUrl = this.getClass().getResource("");
461464
//空的图片 即就是隐藏鼠标
@@ -466,14 +469,24 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
466469
this.AlgLeave = AlgLeave;
467470
this.gameplayer1 = gameplayer1;
468471
this.chessBoard = chessBoard;
472+
stopImage = new ImageIcon(getClass().getClassLoader().getResource("img/stop.png"));
473+
bgImage = new ImageIcon(getClass().getClassLoader().getResource("img/bgImage.jpg"));
474+
chatImage = new ImageIcon(getClass().getClassLoader().getResource("img/chat.png"));
475+
// moveImage = new ImageIcon(getClass().getClassLoader().getResource("img/move.png"));
476+
beginBG = new ImageIcon(getClass().getClassLoader().getResource("img/bfmusic.png"));
477+
StopBG = new ImageIcon(getClass().getClassLoader().getResource("img/stopmusic.png"));
478+
man = new ImageIcon(getClass().getClassLoader().getResource("img/man.jpg"));
479+
women = new ImageIcon(getClass().getClassLoader().getResource("img/women.jpg"));
480+
chessWhite = new ImageIcon(getClass().getClassLoader().getResource("img/chessWhite.png"));
481+
chessBlack = new ImageIcon(getClass().getClassLoader().getResource("img/chessBlack.png"));
469482
//透明
470483
//setOpaque(false);
471484
//不要忘记添加 这个事件
472485
addMouseListener(this);
473486

474487
try {
475488

476-
qizi = ImageIO.read(new File("source/qizi.png"));
489+
qizi = ImageIO.read(getClass().getClassLoader().getResource("img/qizi.png"));
477490
hqizi = qizi.getSubimage(10, 10, 85, 85);
478491
bqizi = qizi.getSubimage(5, 95, 85,85);
479492

@@ -486,7 +499,7 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
486499
man.setImage(man.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
487500
women.setImage(women.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
488501
stopImage.setImage(stopImage.getImage().getScaledInstance(40, 40, Image.SCALE_DEFAULT));
489-
moveImage.setImage(moveImage.getImage().getScaledInstance(400, 400, Image.SCALE_DEFAULT));
502+
490503
addMouseMotionListener(new MouseMotionListener() {
491504

492505
@Override
@@ -496,7 +509,7 @@ public void mouseMoved(MouseEvent e) {
496509

497510

498511
if(!BeginWindow.bofang) {
499-
GameRoomUtil.playChessMovemusic("source/move.mp3");
512+
gameRoomUtil.playChessMovemusic();
500513

501514
}
502515
MouseAtChess = true;
@@ -532,7 +545,7 @@ public void paint(Graphics g) {
532545

533546
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
534547
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_DEFAULT);
535-
g2.drawImage(GamePlane.bgImage.getImage(), 0, 0,GameWidth, GameHeight, GamePlane.bgImage.getImageObserver());
548+
g2.drawImage(bgImage.getImage(), 0, 0,GameWidth, GameHeight, bgImage.getImageObserver());
536549
g2.setColor(Color.BLACK);
537550
for(int i=0;i<15;i++) {
538551
g2.drawLine(430, 110+45*i, 1060, 110+45*i);
@@ -574,13 +587,13 @@ public void paint(Graphics g) {
574587

575588
//画头像下的棋子颜色
576589
if(MyChessColor.equals("white")) {
577-
g2.drawImage(Room.chessWhite.getImage(), 150,260,60,60,this);
590+
g2.drawImage(chessWhite.getImage(), 150,260,60,60,this);
578591
if(!gameplayer2.equals(""))
579-
g2.drawImage(Room.chessBlack.getImage(), 150,750,60,60,this);
592+
g2.drawImage(chessBlack.getImage(), 150,750,60,60,this);
580593
}else {
581-
g2.drawImage(Room.chessBlack.getImage(), 150,260,60,60,this);
594+
g2.drawImage(chessBlack.getImage(), 150,260,60,60,this);
582595
if(!gameplayer2.equals(""))
583-
g2.drawImage(Room.chessWhite.getImage(), 150,750,60,60,this);
596+
g2.drawImage(chessWhite.getImage(), 150,750,60,60,this);
584597
}
585598

586599
// 画棋子
@@ -619,10 +632,10 @@ public void paint(Graphics g) {
619632
}
620633
if(musicing) {
621634

622-
g2.drawImage(GamePlane.StopBG.getImage(), 1200, 30,50,50, this);
635+
g2.drawImage(StopBG.getImage(), 1200, 30,50,50, this);
623636
}else {
624637

625-
g2.drawImage(GamePlane.beginBG.getImage(), 1200, 30,50,50, this);
638+
g2.drawImage(beginBG.getImage(), 1200, 30,50,50, this);
626639
}
627640

628641

@@ -639,9 +652,10 @@ public void mousePressed(MouseEvent e) {
639652

640653
@Override
641654
public void mouseClicked(MouseEvent e) {
655+
642656
new xiaqiThread(this,e).start();
643657
if (e.getX()>=510&&e.getX()<=630&&e.getY()>=820-40&&e.getY()<=880-40) {
644-
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
658+
gameRoomUtil.palyothermusic("mousedown.mp3");
645659
if(!kaishi) {
646660
JOptionPane.showMessageDialog(this, "游戏还没有开始~你就认输了??","false",2);
647661
return;
@@ -654,7 +668,7 @@ public void mouseClicked(MouseEvent e) {
654668
}
655669

656670
}else if (e.getX()>=710&&e.getX()<=830&&e.getY()>=820-40&&e.getY()<=880-40) {
657-
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
671+
gameRoomUtil.palyothermusic("mousedown.mp3");
658672
if(!kaishi) {
659673
JOptionPane.showMessageDialog(this, "游戏还没有开始~","false",2);
660674
return;
@@ -681,7 +695,7 @@ public void mouseClicked(MouseEvent e) {
681695
}
682696

683697
}else if (e.getX()>=910&&e.getX()<=1030&&e.getY()>=820-40&&e.getY()<=880-40) {
684-
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
698+
gameRoomUtil.palyothermusic("mousedown.mp3");;
685699
if(!kaishi) {
686700
JOptionPane.showMessageDialog(this, "游戏还没有开始~","false",2);
687701
return;
@@ -692,10 +706,11 @@ public void mouseClicked(MouseEvent e) {
692706
}
693707

694708
}else if (e.getX()>=650&&e.getX()<=830&&e.getY()>=80-40&&e.getY()<=140-40) {
695-
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
709+
gameRoomUtil.palyothermusic("mousedown.mp3");;
696710
kaishi = true;
697711
System.out.println("开始游戏了");
698-
GameRoomUtil.palyothermusic("source/begin.mp3");
712+
gameRoomUtil.palyothermusic("begin.mp3");;
713+
699714
//如果电脑先手
700715
if(ComputerChessColorINT==2) {
701716
rx = new Random().nextInt(14);
@@ -705,14 +720,14 @@ public void mouseClicked(MouseEvent e) {
705720
}
706721

707722
}else if (e.getX()>=1200&&e.getX()<=1250&&e.getY()>=30&&e.getY()<=80) {
708-
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
723+
gameRoomUtil.palyothermusic("begin.mp3");
709724
if(musicing) {
710725
musicing = false;
711726

712727
GameRoomUtil.stopmusic();
713728
}else {
714729
musicing = true;
715-
GameRoomUtil.playBgmusic();
730+
new GameRoomUtil().playBgmusic();
716731
}
717732

718733
}

src/main/java/client/start/GameClient.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33

44

5+
import java.io.File;
6+
import java.io.IOException;
57
import javax.swing.UIManager;
68

9+
import org.apache.ibatis.javassist.ClassClassPath;
10+
import org.springframework.core.io.ClassPathResource;
11+
712
import client.window.BeginWindow;
813

914
/**
@@ -15,11 +20,12 @@
1520
*/
1621
public class GameClient {
1722
public static BeginWindow beginWindow;
18-
23+
1924
public static String onlineGameMSG;
2025
public static String namerepeatMSG;
2126
public static String roomFullOrRoomDistroyMSG;
22-
public static void main(String[] args) {
27+
public static void main(String[] args) throws IOException {
28+
2329

2430
try {
2531

src/main/java/client/tidings/HandleMsgThread.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.alibaba.fastjson.JSONObject;
1212

1313
import bean.User;
14+
import client.start.GameClient;
1415
import client.ui.GamePlane;
1516
import client.ui.MouseAdapterOfRoomPlane;
1617
import client.ui.RoomPlane;
@@ -28,7 +29,7 @@
2829
*/
2930

3031
public class HandleMsgThread extends Thread{
31-
32+
3233
@Override
3334
public void run() {
3435
while (true) {
@@ -52,6 +53,7 @@ public void run() {
5253
}
5354
}
5455
public static void ResultMsg(String msgType ,String msgData) {
56+
GameRoomUtil gameRoomUtil = new GameRoomUtil();
5557
if(msgType.equals("CloseGameRoom") ) {
5658
if(BeginWindow.out!=null) {
5759
try {
@@ -131,7 +133,7 @@ public static void ResultMsg(String msgType ,String msgData) {
131133
}else if (msgType.equals("GameBegin")) {
132134
System.out.println("游戏开始");
133135
ChessBoard.gamepanel.kaishi = true;
134-
GameRoomUtil.palyothermusic("source/begin.mp3");
136+
gameRoomUtil.palyothermusic("begin.mp3");
135137

136138
}else if (msgType.equals("GameReady")) {
137139
if(msgData.equals("0")) {
@@ -141,9 +143,9 @@ public static void ResultMsg(String msgType ,String msgData) {
141143
}
142144
}else if(msgType.equals("GameChat")){
143145
if(msgData.contains("快点")) {
144-
GameRoomUtil.palyothermusic("source/flowerdie.mp3");
146+
gameRoomUtil.palyothermusic("flowerdie.mp3");
145147
}
146-
GameRoomUtil.palyothermusic("source/chating.mp3");
148+
gameRoomUtil.palyothermusic("chating.mp3");
147149
ChessBoard.jt.append(ChessBoard.gamepanel.gameplayer2.getNickName()+":"+ChessBoard.gamepanel.dateFormat.format(new Date())+"\n "+msgData.toString()+"\n");
148150
//设置总在最下方
149151
ChessBoard.jt.setCaretPosition(ChessBoard.jt.getDocument().getLength());
@@ -177,7 +179,7 @@ public static void ResultMsg(String msgType ,String msgData) {
177179

178180
ChessBoard.gamepanel.GameWinAfter(ChessBoard.gamepanel);
179181

180-
GameRoomUtil.palyothermusic("source/winmusic.mp3");
182+
gameRoomUtil.palyothermusic("winmusic.mp3");
181183
}else if (msgType.equals("YouLose")) {
182184

183185
JOptionPane.showMessageDialog(ChessBoard.gamepanel, "你输了比赛哦~");
@@ -205,7 +207,7 @@ else if(ChessBorldLocation[0].equals("black")){
205207
}else if (msgType.equals("AdmitDefeat")) {
206208
JOptionPane.showMessageDialog(ChessBoard.gamepanel, "对方认输了,你很棒哦");
207209
ChessBoard.gamepanel.gameplayer1.setWinBoutAddOne();
208-
GameRoomUtil.palyothermusic("source/winmusic.mp3");
210+
gameRoomUtil.palyothermusic("winmusic.mp3");
209211
ChessBoard.gamepanel.GameWinAfter(ChessBoard.gamepanel);
210212
}else if (msgType.equals("heqi")) {
211213
if(msgData != null) {

0 commit comments

Comments
 (0)