@@ -54,12 +54,13 @@ public class ComputerGame extends JFrame {
54
54
55
55
int ChessBoardWidth = 1800 ;
56
56
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 ;
61
61
JTextArea jt = new JTextArea ();
62
62
JScrollPane jscroll ;
63
+
63
64
public ComputerGame () {
64
65
65
66
}
@@ -79,7 +80,7 @@ public ComputerGame(BeginWindow parFrame,String username,int AlgLeave) {
79
80
this .parFrame = parFrame ;
80
81
81
82
//播放背景音乐
82
- GameRoomUtil .playBgmusic ();
83
+ new GameRoomUtil () .playBgmusic ();
83
84
84
85
85
86
setResizable (false );
@@ -142,15 +143,15 @@ public void actionPerformed(ActionEvent e) {
142
143
return ;
143
144
}
144
145
if (sendtext .getText ().contains ("快点" )) {
145
- GameRoomUtil .palyothermusic ("source/ flowerdie.mp3" );
146
+ gameRoomUtil .palyothermusic ("flowerdie.mp3" );
146
147
}
147
148
148
149
if (sendtext .getText ().contains ("停止" )) {
149
150
GameRoomUtil .stopmusic ();
150
151
gamepanel .musicing = false ;
151
152
}
152
153
if (sendtext .getText ().contains ("开始" )) {
153
- GameRoomUtil .playBgmusic ();
154
+ new GameRoomUtil () .playBgmusic ();
154
155
gamepanel .musicing = true ;
155
156
}
156
157
@@ -260,7 +261,7 @@ public void windowDeactivated(java.awt.event.WindowEvent e) {
260
261
class xiaqiThread extends Thread {
261
262
GamePlane gmplane ;
262
263
MouseEvent e ;
263
-
264
+ GameRoomUtil gameRoomUtil = new GameRoomUtil ();
264
265
CompututerAlg compututerAlg = new CompututerAlg ();
265
266
public xiaqiThread (GamePlane chessBoard , MouseEvent e ) {
266
267
this .gmplane = chessBoard ;
@@ -312,7 +313,7 @@ public void run() {
312
313
}else {
313
314
gmplane .allChess [gmplane .rx ][gmplane .ry ] =2 ;
314
315
}
315
- GameRoomUtil .palyothermusic ("source/ mousedown.mp3" );
316
+ gameRoomUtil .palyothermusic ("mousedown.mp3" );
316
317
gmplane .chessPoint .add (gmplane .MyChessColor +"," +(gmplane .rx *45 +430 )+"," +(gmplane .ry *45 +110 ));
317
318
gmplane .isme = false ;
318
319
@@ -327,7 +328,7 @@ public void run() {
327
328
gmplane .chessBoard .jt .append ("系统:" +gmplane .dateFormat .format (new Date ())+"\n 你赢得了比赛!!\n " );
328
329
gmplane .MyplayGamewinnum ++;
329
330
gmplane .GameWinAfter (gmplane );
330
- GameRoomUtil .palyothermusic ("source/ winmusic.mp3" );
331
+ gameRoomUtil .palyothermusic ("winmusic.mp3" );
331
332
}else {
332
333
ComputerXiaqi (gmplane );
333
334
}
@@ -396,12 +397,14 @@ class GamePlane extends JSplitPane implements MouseListener{
396
397
*
397
398
*/
398
399
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 ;
405
408
BufferedImage qizi = null ;
406
409
BufferedImage bqizi = null ;
407
410
BufferedImage hqizi = null ;
@@ -432,15 +435,16 @@ class GamePlane extends JSplitPane implements MouseListener{
432
435
boolean isme = true ;
433
436
DecimalFormat df = new DecimalFormat ("0.00" );
434
437
String gameplayer2 ="风萧萧兮易水寒" ;
435
-
438
+ public ImageIcon chessWhite ;
439
+ public ImageIcon chessBlack ;
436
440
437
441
//白1黑2
438
442
String MyChessColor ="black" ;
439
443
int MyChessColorINT =2 ;
440
444
String ComputerChessColor ="white" ;
441
445
int ComputerChessColorINT = 1 ;
442
446
443
-
447
+ private GameRoomUtil gameRoomUtil = new GameRoomUtil ();
444
448
445
449
BufferedImage Colorstaus ;
446
450
//胜率
@@ -454,8 +458,7 @@ class GamePlane extends JSplitPane implements MouseListener{
454
458
int PlayGamenum = 0 ;
455
459
456
460
boolean kaishi = false ;
457
- ImageIcon man = new ImageIcon ("source/man.jpg" );
458
- ImageIcon women = new ImageIcon ("source/women.jpg" );
461
+
459
462
460
463
URL classUrl = this .getClass ().getResource ("" );
461
464
//空的图片 即就是隐藏鼠标
@@ -466,14 +469,24 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
466
469
this .AlgLeave = AlgLeave ;
467
470
this .gameplayer1 = gameplayer1 ;
468
471
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" ));
469
482
//透明
470
483
//setOpaque(false);
471
484
//不要忘记添加 这个事件
472
485
addMouseListener (this );
473
486
474
487
try {
475
488
476
- qizi = ImageIO .read (new File ( "source /qizi.png" ));
489
+ qizi = ImageIO .read (getClass (). getClassLoader (). getResource ( "img /qizi.png" ));
477
490
hqizi = qizi .getSubimage (10 , 10 , 85 , 85 );
478
491
bqizi = qizi .getSubimage (5 , 95 , 85 ,85 );
479
492
@@ -486,7 +499,7 @@ public GamePlane(ComputerGame chessBoard,String gameplayer1,int AlgLeave) {
486
499
man .setImage (man .getImage ().getScaledInstance (150 , 150 , Image .SCALE_DEFAULT ));
487
500
women .setImage (women .getImage ().getScaledInstance (150 , 150 , Image .SCALE_DEFAULT ));
488
501
stopImage .setImage (stopImage .getImage ().getScaledInstance (40 , 40 , Image .SCALE_DEFAULT ));
489
- moveImage . setImage ( moveImage . getImage (). getScaledInstance ( 400 , 400 , Image . SCALE_DEFAULT ));
502
+
490
503
addMouseMotionListener (new MouseMotionListener () {
491
504
492
505
@ Override
@@ -496,7 +509,7 @@ public void mouseMoved(MouseEvent e) {
496
509
497
510
498
511
if (!BeginWindow .bofang ) {
499
- GameRoomUtil .playChessMovemusic ("source/move.mp3" );
512
+ gameRoomUtil .playChessMovemusic ();
500
513
501
514
}
502
515
MouseAtChess = true ;
@@ -532,7 +545,7 @@ public void paint(Graphics g) {
532
545
533
546
g2 .setRenderingHint (RenderingHints .KEY_ANTIALIASING ,RenderingHints .VALUE_ANTIALIAS_ON );
534
547
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 ());
536
549
g2 .setColor (Color .BLACK );
537
550
for (int i =0 ;i <15 ;i ++) {
538
551
g2 .drawLine (430 , 110 +45 *i , 1060 , 110 +45 *i );
@@ -574,13 +587,13 @@ public void paint(Graphics g) {
574
587
575
588
//画头像下的棋子颜色
576
589
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 );
578
591
if (!gameplayer2 .equals ("" ))
579
- g2 .drawImage (Room . chessBlack .getImage (), 150 ,750 ,60 ,60 ,this );
592
+ g2 .drawImage (chessBlack .getImage (), 150 ,750 ,60 ,60 ,this );
580
593
}else {
581
- g2 .drawImage (Room . chessBlack .getImage (), 150 ,260 ,60 ,60 ,this );
594
+ g2 .drawImage (chessBlack .getImage (), 150 ,260 ,60 ,60 ,this );
582
595
if (!gameplayer2 .equals ("" ))
583
- g2 .drawImage (Room . chessWhite .getImage (), 150 ,750 ,60 ,60 ,this );
596
+ g2 .drawImage (chessWhite .getImage (), 150 ,750 ,60 ,60 ,this );
584
597
}
585
598
586
599
// 画棋子
@@ -619,10 +632,10 @@ public void paint(Graphics g) {
619
632
}
620
633
if (musicing ) {
621
634
622
- g2 .drawImage (GamePlane . StopBG .getImage (), 1200 , 30 ,50 ,50 , this );
635
+ g2 .drawImage (StopBG .getImage (), 1200 , 30 ,50 ,50 , this );
623
636
}else {
624
637
625
- g2 .drawImage (GamePlane . beginBG .getImage (), 1200 , 30 ,50 ,50 , this );
638
+ g2 .drawImage (beginBG .getImage (), 1200 , 30 ,50 ,50 , this );
626
639
}
627
640
628
641
@@ -639,9 +652,10 @@ public void mousePressed(MouseEvent e) {
639
652
640
653
@ Override
641
654
public void mouseClicked (MouseEvent e ) {
655
+
642
656
new xiaqiThread (this ,e ).start ();
643
657
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" );
645
659
if (!kaishi ) {
646
660
JOptionPane .showMessageDialog (this , "游戏还没有开始~你就认输了??" ,"false" ,2 );
647
661
return ;
@@ -654,7 +668,7 @@ public void mouseClicked(MouseEvent e) {
654
668
}
655
669
656
670
}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" );
658
672
if (!kaishi ) {
659
673
JOptionPane .showMessageDialog (this , "游戏还没有开始~" ,"false" ,2 );
660
674
return ;
@@ -681,7 +695,7 @@ public void mouseClicked(MouseEvent e) {
681
695
}
682
696
683
697
}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" ); ;
685
699
if (!kaishi ) {
686
700
JOptionPane .showMessageDialog (this , "游戏还没有开始~" ,"false" ,2 );
687
701
return ;
@@ -692,10 +706,11 @@ public void mouseClicked(MouseEvent e) {
692
706
}
693
707
694
708
}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" ); ;
696
710
kaishi = true ;
697
711
System .out .println ("开始游戏了" );
698
- GameRoomUtil .palyothermusic ("source/begin.mp3" );
712
+ gameRoomUtil .palyothermusic ("begin.mp3" );;
713
+
699
714
//如果电脑先手
700
715
if (ComputerChessColorINT ==2 ) {
701
716
rx = new Random ().nextInt (14 );
@@ -705,14 +720,14 @@ public void mouseClicked(MouseEvent e) {
705
720
}
706
721
707
722
}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" );
709
724
if (musicing ) {
710
725
musicing = false ;
711
726
712
727
GameRoomUtil .stopmusic ();
713
728
}else {
714
729
musicing = true ;
715
- GameRoomUtil .playBgmusic ();
730
+ new GameRoomUtil () .playBgmusic ();
716
731
}
717
732
718
733
}
0 commit comments