Skip to content

Commit

Permalink
使用jar包资源
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenCri committed Nov 6, 2019
1 parent 6eb9059 commit 2eccee3
Show file tree
Hide file tree
Showing 54 changed files with 164 additions and 131 deletions.
89 changes: 52 additions & 37 deletions src/main/java/client/computer/ComputerGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public class ComputerGame extends JFrame {

int ChessBoardWidth = 1800;
int ChessBoardHeight = 1000;

BeginWindow parFrame;
GamePlane gamepanel;
JSplitPane chatPlane;
GameRoomUtil gameRoomUtil = new GameRoomUtil();
public BeginWindow parFrame;
public GamePlane gamepanel;
private JSplitPane chatPlane;
JTextArea jt = new JTextArea();
JScrollPane jscroll ;

public ComputerGame() {

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

//播放背景音乐
GameRoomUtil.playBgmusic();
new GameRoomUtil().playBgmusic();


setResizable(false);
Expand Down Expand Up @@ -142,15 +143,15 @@ public void actionPerformed(ActionEvent e) {
return;
}
if(sendtext.getText().contains("快点")) {
GameRoomUtil.palyothermusic("source/flowerdie.mp3");
gameRoomUtil.palyothermusic("flowerdie.mp3");
}

if(sendtext.getText().contains("停止")) {
GameRoomUtil.stopmusic();
gamepanel.musicing = false;
}
if(sendtext.getText().contains("开始")) {
GameRoomUtil.playBgmusic();
new GameRoomUtil().playBgmusic();
gamepanel.musicing = true;
}

Expand Down Expand Up @@ -260,7 +261,7 @@ public void windowDeactivated(java.awt.event.WindowEvent e) {
class xiaqiThread extends Thread{
GamePlane gmplane;
MouseEvent e;

GameRoomUtil gameRoomUtil = new GameRoomUtil();
CompututerAlg compututerAlg = new CompututerAlg();
public xiaqiThread(GamePlane chessBoard, MouseEvent e) {
this.gmplane = chessBoard;
Expand Down Expand Up @@ -312,7 +313,7 @@ public void run() {
}else {
gmplane.allChess[gmplane.rx][gmplane.ry] =2;
}
GameRoomUtil.palyothermusic("source/mousedown.mp3");
gameRoomUtil.palyothermusic("mousedown.mp3");
gmplane.chessPoint.add(gmplane.MyChessColor+","+(gmplane.rx*45+430)+","+(gmplane.ry*45+110));
gmplane.isme = false;

Expand All @@ -327,7 +328,7 @@ public void run() {
gmplane.chessBoard.jt.append("系统:"+gmplane.dateFormat.format(new Date())+"\n 你赢得了比赛!!\n");
gmplane.MyplayGamewinnum++;
gmplane.GameWinAfter(gmplane);
GameRoomUtil.palyothermusic("source/winmusic.mp3");
gameRoomUtil.palyothermusic("winmusic.mp3");
}else {
ComputerXiaqi(gmplane);
}
Expand Down Expand Up @@ -396,12 +397,14 @@ class GamePlane extends JSplitPane implements MouseListener{
*
*/
private static final long serialVersionUID = 1L;
static ImageIcon stopImage = new ImageIcon("source/stop.png");
static ImageIcon bgImage = new ImageIcon("source/bgImage.jpg");
static ImageIcon chatImage = new ImageIcon("source/chat.png");
static ImageIcon moveImage = new ImageIcon("source/move.png");
static ImageIcon beginBG = new ImageIcon("source/bfmusic.png");
static ImageIcon StopBG = new ImageIcon("source/stopmusic.png");
public ImageIcon stopImage;
public ImageIcon bgImage;
public ImageIcon chatImage;

public ImageIcon beginBG;
public ImageIcon StopBG;
public ImageIcon man ;
public ImageIcon women ;
BufferedImage qizi = null;
BufferedImage bqizi = null;
BufferedImage hqizi = null;
Expand Down Expand Up @@ -432,15 +435,16 @@ class GamePlane extends JSplitPane implements MouseListener{
boolean isme = true;
DecimalFormat df = new DecimalFormat("0.00");
String gameplayer2 ="风萧萧兮易水寒";

public ImageIcon chessWhite;
public ImageIcon chessBlack;

//白1黑2
String MyChessColor ="black";
int MyChessColorINT =2;
String ComputerChessColor ="white";
int ComputerChessColorINT = 1;


private GameRoomUtil gameRoomUtil = new GameRoomUtil();

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

boolean kaishi = false;
ImageIcon man = new ImageIcon("source/man.jpg");
ImageIcon women = new ImageIcon("source/women.jpg");


URL classUrl = this.getClass().getResource("");
//空的图片 即就是隐藏鼠标
Expand All @@ -466,14 +469,24 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
this.AlgLeave = AlgLeave;
this.gameplayer1 = gameplayer1;
this.chessBoard = chessBoard;
stopImage = new ImageIcon(getClass().getClassLoader().getResource("img/stop.png"));
bgImage = new ImageIcon(getClass().getClassLoader().getResource("img/bgImage.jpg"));
chatImage = new ImageIcon(getClass().getClassLoader().getResource("img/chat.png"));
// moveImage = new ImageIcon(getClass().getClassLoader().getResource("img/move.png"));
beginBG = new ImageIcon(getClass().getClassLoader().getResource("img/bfmusic.png"));
StopBG = new ImageIcon(getClass().getClassLoader().getResource("img/stopmusic.png"));
man = new ImageIcon(getClass().getClassLoader().getResource("img/man.jpg"));
women = new ImageIcon(getClass().getClassLoader().getResource("img/women.jpg"));
chessWhite = new ImageIcon(getClass().getClassLoader().getResource("img/chessWhite.png"));
chessBlack = new ImageIcon(getClass().getClassLoader().getResource("img/chessBlack.png"));
//透明
//setOpaque(false);
//不要忘记添加 这个事件
addMouseListener(this);

try {

qizi = ImageIO.read(new File("source/qizi.png"));
qizi = ImageIO.read(getClass().getClassLoader().getResource("img/qizi.png"));
hqizi = qizi.getSubimage(10, 10, 85, 85);
bqizi = qizi.getSubimage(5, 95, 85,85);

Expand All @@ -486,7 +499,7 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
man.setImage(man.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
women.setImage(women.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
stopImage.setImage(stopImage.getImage().getScaledInstance(40, 40, Image.SCALE_DEFAULT));
moveImage.setImage(moveImage.getImage().getScaledInstance(400, 400, Image.SCALE_DEFAULT));

addMouseMotionListener(new MouseMotionListener() {

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


if(!BeginWindow.bofang) {
GameRoomUtil.playChessMovemusic("source/move.mp3");
gameRoomUtil.playChessMovemusic();

}
MouseAtChess = true;
Expand Down Expand Up @@ -532,7 +545,7 @@ public void paint(Graphics g) {

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

//画头像下的棋子颜色
if(MyChessColor.equals("white")) {
g2.drawImage(Room.chessWhite.getImage(), 150,260,60,60,this);
g2.drawImage(chessWhite.getImage(), 150,260,60,60,this);
if(!gameplayer2.equals(""))
g2.drawImage(Room.chessBlack.getImage(), 150,750,60,60,this);
g2.drawImage(chessBlack.getImage(), 150,750,60,60,this);
}else {
g2.drawImage(Room.chessBlack.getImage(), 150,260,60,60,this);
g2.drawImage(chessBlack.getImage(), 150,260,60,60,this);
if(!gameplayer2.equals(""))
g2.drawImage(Room.chessWhite.getImage(), 150,750,60,60,this);
g2.drawImage(chessWhite.getImage(), 150,750,60,60,this);
}

// 画棋子
Expand Down Expand Up @@ -619,10 +632,10 @@ public void paint(Graphics g) {
}
if(musicing) {

g2.drawImage(GamePlane.StopBG.getImage(), 1200, 30,50,50, this);
g2.drawImage(StopBG.getImage(), 1200, 30,50,50, this);
}else {

g2.drawImage(GamePlane.beginBG.getImage(), 1200, 30,50,50, this);
g2.drawImage(beginBG.getImage(), 1200, 30,50,50, this);
}


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

@Override
public void mouseClicked(MouseEvent e) {

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

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

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

}else if (e.getX()>=650&&e.getX()<=830&&e.getY()>=80-40&&e.getY()<=140-40) {
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
gameRoomUtil.palyothermusic("mousedown.mp3");;
kaishi = true;
System.out.println("开始游戏了");
GameRoomUtil.palyothermusic("source/begin.mp3");
gameRoomUtil.palyothermusic("begin.mp3");;

//如果电脑先手
if(ComputerChessColorINT==2) {
rx = new Random().nextInt(14);
Expand All @@ -705,14 +720,14 @@ public void mouseClicked(MouseEvent e) {
}

}else if (e.getX()>=1200&&e.getX()<=1250&&e.getY()>=30&&e.getY()<=80) {
GameRoomUtil.playChessMovemusic("source/mousedown.mp3");
gameRoomUtil.palyothermusic("begin.mp3");
if(musicing) {
musicing = false;

GameRoomUtil.stopmusic();
}else {
musicing = true;
GameRoomUtil.playBgmusic();
new GameRoomUtil().playBgmusic();
}

}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/client/start/GameClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@



import java.io.File;
import java.io.IOException;
import javax.swing.UIManager;

import org.apache.ibatis.javassist.ClassClassPath;
import org.springframework.core.io.ClassPathResource;

import client.window.BeginWindow;

/**
Expand All @@ -15,11 +20,12 @@
*/
public class GameClient {
public static BeginWindow beginWindow;

public static String onlineGameMSG;
public static String namerepeatMSG;
public static String roomFullOrRoomDistroyMSG;
public static void main(String[] args) {
public static void main(String[] args) throws IOException {


try {

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/client/tidings/HandleMsgThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.alibaba.fastjson.JSONObject;

import bean.User;
import client.start.GameClient;
import client.ui.GamePlane;
import client.ui.MouseAdapterOfRoomPlane;
import client.ui.RoomPlane;
Expand All @@ -28,7 +29,7 @@
*/

public class HandleMsgThread extends Thread{

@Override
public void run() {
while (true) {
Expand All @@ -52,6 +53,7 @@ public void run() {
}
}
public static void ResultMsg(String msgType ,String msgData) {
GameRoomUtil gameRoomUtil = new GameRoomUtil();
if(msgType.equals("CloseGameRoom") ) {
if(BeginWindow.out!=null) {
try {
Expand Down Expand Up @@ -131,7 +133,7 @@ public static void ResultMsg(String msgType ,String msgData) {
}else if (msgType.equals("GameBegin")) {
System.out.println("游戏开始");
ChessBoard.gamepanel.kaishi = true;
GameRoomUtil.palyothermusic("source/begin.mp3");
gameRoomUtil.palyothermusic("begin.mp3");

}else if (msgType.equals("GameReady")) {
if(msgData.equals("0")) {
Expand All @@ -141,9 +143,9 @@ public static void ResultMsg(String msgType ,String msgData) {
}
}else if(msgType.equals("GameChat")){
if(msgData.contains("快点")) {
GameRoomUtil.palyothermusic("source/flowerdie.mp3");
gameRoomUtil.palyothermusic("flowerdie.mp3");
}
GameRoomUtil.palyothermusic("source/chating.mp3");
gameRoomUtil.palyothermusic("chating.mp3");
ChessBoard.jt.append(ChessBoard.gamepanel.gameplayer2.getNickName()+":"+ChessBoard.gamepanel.dateFormat.format(new Date())+"\n "+msgData.toString()+"\n");
//设置总在最下方
ChessBoard.jt.setCaretPosition(ChessBoard.jt.getDocument().getLength());
Expand Down Expand Up @@ -177,7 +179,7 @@ public static void ResultMsg(String msgType ,String msgData) {

ChessBoard.gamepanel.GameWinAfter(ChessBoard.gamepanel);

GameRoomUtil.palyothermusic("source/winmusic.mp3");
gameRoomUtil.palyothermusic("winmusic.mp3");
}else if (msgType.equals("YouLose")) {

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

0 comments on commit 2eccee3

Please sign in to comment.