有一中国象棋残局大全,前走法是红车吃黑马,吃黑象,吃黑士,吃黑马,请教残局名

《微信腾讯中国象棋》残局第147关攻略《微信腾讯中国象棋》残局第147关攻略三胖侃球百家号微信腾讯中国象棋残局第147关怎么过?春秋五霸147关和戎政策攻略。147关中,黑方已将红方右路掐死,红方的首要目标是利用连将来逼黑方解围。下面请看本关的具体攻略。春秋五霸147关和戎政策攻略:第1步,红马六进七,黑将4进1:第2步,红车八进八,黑将4进1:第3步,红兵七平六,黑将4平5:第4步,红马七退五,黑将5平6:第5步,红马五退三,黑将6退1:第6步,红马三进二,黑将6进1:第7步,红炮五平一,黑车9退2:第8步,红马二进三,黑将6退1:第9步,红马三退二,黑将6进1:第10步,红车八退一,黑象3进5:第11步,红马二退三,黑将6退1:第12步,红车八平五,黑马7退8:第13步,红马三进五,黑士5退4:第14步,红兵六进一,黑车6进1:第15步,红帅五平四,黑车9平6:第16步,红仕五进四,黑卒6平5:第17步,红车五进二,黑将6进1:第18步,红车五平四,绝杀成功:本关AI前期比较聪明,但它这种小聪明反而会被我们利用,红色边路马及后炮都是用来牵制黑车的套路,想吃又顾虑太多。另外,或许玩家会碰到另外一种:馬六进七,将4进1,車八进八,将4进1,兵七平六,将4平5,馬七退五,将5平6,馬五退三,将6退1,馬三进二,将6进1,馬二进三,将6退1,馬三退二,将6进1,車八退一,象3进5,砲五平一,车9退2,馬二退三,将6退1,車七平五,马7退8,馬三进五,士5退4,兵六进一,车6进1,帅五平四,车9平6,仕五进四,炮8平4,車五进二,将6进1,車五平四。可以看出,两种走法仅顺序不同,解围,要点就是为了争取步数。以上就是3DM小编为大家带来的春秋五霸147关和戎政策攻略,希望对大家有帮助。更多相关资讯,请关注3DM手游。本文由百家号作者上传并发布,百家号仅提供信息发布平台。文章仅代表作者个人观点,不代表百度立场。未经作者许可,不得转载。三胖侃球百家号最近更新:简介:三胖侃球,最新最全的实时咨询作者最新文章相关文章中国象棋残局游戏 最新免费版
当前位置:
请输入预约的手机号码
237人已预约此游戏
中国象棋残局游戏是一款包含了很多经典残局的象棋游戏,其中精选150例涵盖了象棋技战术的精髓。每一例中的每一步走子都可以任意控制、随意播放、走子动画与棋谱高度同步,操作简单方便。只要你能认真研习,相信你的棋技一定有突飞猛进的进步。
马兵类残局
马兵和士象全,注意马在3线,和七线偷袭。
马低兵必胜单象士,有难度需要认真对待。
马底兵和单炮,炮在中,避开红马抽将吃泡,可和。
马底兵胜马,因为马不能像炮一样走直,容易胜。
马高兵胜炮单仕,马在八横三,或七可胜。
马底兵胜炮单象,逼象归边,马中路困将。
马兵和炮双相,炮憋马脚,利用双象走闲。
马双兵和单马士象全。
马双兵和单炮士象全,用炮换兵,成马兵难胜士象全
车兵类残局
车低兵胜单车,黑将赶走中路,然后换车。
车低兵和单车,守和:黑占中线,不离开可和。
车高兵和单士象:守和:以车蔗头保士,以仕蔗头保宫心。
车低兵单士和车单士,守和:单车保士,称单车保肋,即车在士角护将,士在另一羊角,且红兵在一侧,使兵不能占中。
2:太公坐骑:士在将底,车沿将门走闲着。
3:攻:黑士在将顶,与黑车换车,用帅困将士,兵占中。
车高兵胜马士象全:
1:设法以兵换双象。成单车胜马双士的局面。
2:在马不合位的情况下,以兵换双士,成单车巧胜马双象的局面。
3:以兵换一士一象,成单车胜马单士象的局面。
注意不能让黑马换红兵成和。
车低兵胜马士象全,抓住黑象不能高飞的弱点,弃兵换士。车运用听着胜。
车低兵和炮士象全。
马炮类残局
马炮胜士象全:不要用马或炮换士。要个个击破。
马炮士象全胜马士象全:避免换子,设法吃士象。
马炮士象全和炮士象全,人们常说炮和马不和,即是指马炮士象全胜马士象全,和炮士象全,
守和:炮在将前,蔗护拦换
其他下载地址:
22.26 MB2 MB3.98 MB22.26 MB153.22 MB879.48 MB10.38 MB3.02 MB3.02 MB3.12 GB31.2 MB11.8 MB
764 MB49.19 MB49.19 MB49.19 MB49.19 MB34.86 MB0 bytes845.89 MB845.89 MB61.84 MB61.84 MB147 MB象棋残局!!!!求解!!!!!!!【nba吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0可签7级以上的吧50个
本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:6,161,559贴子:
象棋残局!!!!求解!!!!!!!
红先下!红怎么样才能赢??
是红先下么
我怎么感觉红的怎么下怎么赢
红车下底就将死了吧,应该黑棋先下吧。。。
谁先下就谁胜
在下水平比较低,只能看出这几步:红车将军,黑马挡,红车吃马将军,黑象挡,红车吃象将军,黑士挡,红车吃士将军,黑炮挡,同时黑车将军,红色有解吗?
会死吗? 你红车下 别人下马
你吃马 别人下士 注意对方车可以看住士
其实楼主想打炮!
但是红色只要不将军,黑色炮一挪开,红色就输了吧
是卒 不好意思 看错了
黑卒被你吃了?
红应该少个字
要么LZ 说少了 不然没办法赢
个人感觉 红怎么玩都输。。。
你红炮吃士就没有将军了,人家黑炮只要不下底就赢了
红车下去还有棋么?
炮挡以后```红马将
``他死不死?
红车下去将,马仕象全被吃,然后再用黑炮顶,红马再将,应该木棋了吧!?!?
呵呵,原来黑炮下去,就已经是将红了,所以,此套路黑方胜哦
贴吧热议榜
使用签名档&&
保存至快速回贴这个残局红方怎么过,过求高手指点!_百度知道
这个残局红方怎么过,过求高手指点!
我有更好的答案
红右车吃象,黑象吃红车。红车进底将军,黑升将。红车右平一步士位将军,黑士吃车。红马左进底将军,闷杀
采纳率:53%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Java棋类游戏实践之中国象棋
转载 &更新时间:日 11:51:36 & 作者:涛涌四海
这篇文章主要介绍了Java棋类游戏中的中国象棋实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例讲述了java实现的中国象棋游戏代码,分享给大家供大家参考,具体代码如下
一、实践目的:
1.鼠标点击、拖动等事件的应用与区别
2.棋谱文件的保存与读取
3.完善象棋的规则。
二、实践内容:
中国象棋历史悠久,吸引了无数的人研究,现对中国象棋的对战和实现棋谱的制作做如下的设计和说明,供大家参考学习。
1、机机对弈,红方先手。在符合规则的情况下拖动棋子到目的地,松鼠标落子。
人人对弈图
2、制作棋谱,选择制作棋谱菜单后,对弈开始,并记录了下棋过程。
选择“制作棋谱”菜单
棋谱制作完毕红方胜出
一方胜出后弹出胜利消息对话框。点击确定后,选择“保存棋谱”菜单,弹出保存文件对话框。
保存棋谱对话框
3.演示棋谱,选择演示棋谱菜单后,弹出打开对话框,选择保存好的棋谱,开始演示。
演示棋谱对话框
演示棋谱过程(自动和手动两种)
三、参考代码:
1.象棋主类 文件ChineseChess.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.LinkedL
* 象棋主类
* @author cnlht
public class ChineseChess extends JFrame implements ActionListener {
ChessBoard board =
Demon demon =
MakeChessManual record =
Container con =
JMenu fileM
JMenuItem 制作棋谱, 保存棋谱, 演示棋谱;
JFileChooser fileChooser =
LinkedList 棋谱 =
public ChineseChess() {
bar = new JMenuBar();
fileMenu = new JMenu("中国象棋");
制作棋谱 = new JMenuItem("制作棋谱");
保存棋谱 = new JMenuItem("保存棋谱");
保存棋谱.setEnabled(false);
演示棋谱 = new JMenuItem("演示棋谱");
fileMenu.add(制作棋谱);
fileMenu.add(保存棋谱);
fileMenu.add(演示棋谱);
bar.add(fileMenu);
setJMenuBar(bar);
setTitle(制作棋谱.getText());
制作棋谱.addActionListener(this);
保存棋谱.addActionListener(this);
演示棋谱.addActionListener(this);
board = new ChessBoard(45, 45, 9, 10);
record = board.
con = getContentPane();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
board, record);
split.setDividerSize(5);
split.setDividerLocation(460);
con.add(split, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
setVisible(true);
setBounds(60, 20, 690, 540);
fileChooser = new JFileChooser();
con.validate();
validate();
public void actionPerformed(ActionEvent e) {
if (e.getSource() == 制作棋谱) {
con.removeAll();
保存棋谱.setEnabled(true);
this.setTitle(制作棋谱.getText());
board = new ChessBoard(45, 45, 9, 10);
record = board.
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
true, board, record);
split.setDividerSize(5);
split.setDividerLocation(460);
con.add(split, BorderLayout.CENTER);
validate();
if (e.getSource() == 保存棋谱) {
int state = fileChooser.showSaveDialog(null);
File saveFile = fileChooser.getSelectedFile();
if (saveFile != null && state == JFileChooser.APPROVE_OPTION) {
FileOutputStream outOne = new FileOutputStream(saveFile);
ObjectOutputStream outTwo = new ObjectOutputStream(outOne);
outTwo.writeObject(record.获取棋谱());
outOne.close();
outTwo.close();
} catch (IOException event) {
if (e.getSource() == 演示棋谱) {
con.removeAll();
con.repaint();
con.validate();
validate();
保存棋谱.setEnabled(false);
int state = fileChooser.showOpenDialog(null);
File openFile = fileChooser.getSelectedFile();
if (openFile != null && state == JFileChooser.APPROVE_OPTION) {
FileInputStream inOne = new FileInputStream(openFile);
ObjectInputStream inTwo = new ObjectInputStream(inOne);
棋谱 = (LinkedList) inTwo.readObject();
inOne.close();
inTwo.close();
ChessBoard board = new ChessBoard(45, 45, 9, 10);
demon = new Demon(board);
demon.set棋谱(棋谱);
con.add(demon, BorderLayout.CENTER);
con.validate();
validate();
this.setTitle(演示棋谱.getText() + ":" + openFile);
} catch (Exception event) {
JLabel label = new JLabel("不是棋谱文件");
label.setFont(new Font("隶书", Font.BOLD, 60));
label.setForeground(Color.red);
label.setHorizontalAlignment(SwingConstants.CENTER);
con.add(label, BorderLayout.CENTER);
con.validate();
this.setTitle("没有打开棋谱");
validate();
JLabel label = new JLabel("没有打开棋谱文件呢");
label.setFont(new Font("隶书", Font.BOLD, 50));
label.setForeground(Color.pink);
label.setHorizontalAlignment(SwingConstants.CENTER);
con.add(label, BorderLayout.CENTER);
con.validate();
this.setTitle("没有打开棋谱文件呢");
validate();
public static void main(String args[]) {
new ChineseChess();
2.象棋棋盘类文件ChessBoard.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* @author cnlht
public class ChessBoard extends JPanel implements MouseListener,
MouseMotionListener {
public ChessPoint point[][];
public int unitWidth, unitH
private int x轴长, y轴长;
private int x,
protected Image pieceI
private boolean move =
public String 红方颜色 = "红方", 黑方颜色 = "黑方";
ChessPiece 红车1, 红车2, 红马1, 红马2, 红相1, 红相2, 红帅, 红士1, 红士2, 红兵1, 红兵2, 红兵3, 红兵4,
红兵5, 红炮1, 红炮2;
ChessPiece 黑车1, 黑车2, 黑马1, 黑马2, 黑将, 黑士1, 黑士2, 黑卒1, 黑卒2, 黑卒3, 黑卒4, 黑卒5, 黑象1,
黑象2, 黑炮1, 黑炮2;
int startX, startY;
int startI, startJ;
public boolean 红方走棋 = true, 黑方走棋 =
Rule rule =
public MakeChessManual record =
public ChessBoard(int w, int h, int r, int c) {
setLayout(null);
addMouseListener(this);
addMouseMotionListener(this);
Color bc = getBackground();
unitWidth =
unitHeight =
point = new ChessPoint[r + 1][c + 1];
for (int i = 1; i &= i++) {
for (int j = 1; j &= j++) {
point[i][j] = new ChessPoint(i * unitWidth, j * unitHeight,
rule = new Rule(this, point);
record = new MakeChessManual(this, point);
img = Toolkit.getDefaultToolkit().getImage("board.jpg");
pieceImg = Toolkit.getDefaultToolkit().getImage("piece.gif");
红车1 = new ChessPiece("車", Color.red, bc, w - 4, h - 4, this);
红车1.set棋子类别(红方颜色);
红车2 = new ChessPiece("車", Color.red, bc, w - 4, h - 4, this);
红车2.set棋子类别(红方颜色);
红马1 = new ChessPiece("馬", Color.red, bc, w - 4, h - 4, this);
红马1.set棋子类别(红方颜色);
红马2 = new ChessPiece("馬", Color.red, bc, w - 4, h - 4, this);
红马2.set棋子类别(红方颜色);
红炮1 = new ChessPiece("炮", Color.red, bc, w - 4, h - 4, this);
红炮1.set棋子类别(红方颜色);
红炮2 = new ChessPiece("炮", Color.red, bc, w - 4, h - 4, this);
红炮2.set棋子类别(红方颜色);
红相1 = new ChessPiece("相", Color.red, bc, w - 4, h - 4, this);
红相1.set棋子类别(红方颜色);
红相2 = new ChessPiece("相", Color.red, bc, w - 4, h - 4, this);
红相2.set棋子类别(红方颜色);
红士1 = new ChessPiece("仕", Color.red, bc, w - 4, h - 4, this);
红士1.set棋子类别(红方颜色);
红士2 = new ChessPiece("仕", Color.red, bc, w - 4, h - 4, this);
红士2.set棋子类别(红方颜色);
红帅 = new ChessPiece("帅", Color.red, bc, w - 4, h - 4, this);
红帅.set棋子类别(红方颜色);
红兵1 = new ChessPiece("兵", Color.red, bc, w - 4, h - 4, this);
红兵1.set棋子类别(红方颜色);
红兵2 = new ChessPiece("兵", Color.red, bc, w - 4, h - 4, this);
红兵2.set棋子类别(红方颜色);
红兵3 = new ChessPiece("兵", Color.red, bc, w - 4, h - 4, this);
红兵3.set棋子类别(红方颜色);
红兵4 = new ChessPiece("兵", Color.red, bc, w - 4, h - 4, this);
红兵4.set棋子类别(红方颜色);
红兵5 = new ChessPiece("兵", Color.red, bc, w - 4, h - 4, this);
红兵5.set棋子类别(红方颜色);
黑将 = new ChessPiece("将", Color.black, bc, w - 4, h - 4, this);
黑将.set棋子类别(黑方颜色);
黑士1 = new ChessPiece("士", Color.black, bc, w - 4, h - 4, this);
黑士1.set棋子类别(黑方颜色);
黑士2 = new ChessPiece("士", Color.black, bc, w - 4, h - 4, this);
黑士2.set棋子类别(黑方颜色);
黑车1 = new ChessPiece("车", Color.black, bc, w - 4, h - 4, this);
黑车1.set棋子类别(黑方颜色);
黑车2 = new ChessPiece("车", Color.black, bc, w - 4, h - 4, this);
黑车2.set棋子类别(黑方颜色);
黑炮1 = new ChessPiece("炮", Color.black, bc, w - 4, h - 4, this);
黑炮1.set棋子类别(黑方颜色);
黑炮2 = new ChessPiece("炮", Color.black, bc, w - 4, h - 4, this);
黑炮2.set棋子类别(黑方颜色);
黑象1 = new ChessPiece("象", Color.black, bc, w - 4, h - 4, this);
黑象1.set棋子类别(黑方颜色);
黑象2 = new ChessPiece("象", Color.black, bc, w - 4, h - 4, this);
黑象2.set棋子类别(黑方颜色);
黑马1 = new ChessPiece("马", Color.black, bc, w - 4, h - 4, this);
黑马1.set棋子类别(黑方颜色);
黑马2 = new ChessPiece("马", Color.black, bc, w - 4, h - 4, this);
黑马2.set棋子类别(黑方颜色);
黑卒1 = new ChessPiece("卒", Color.black, bc, w - 4, h - 4, this);
黑卒1.set棋子类别(黑方颜色);
黑卒2 = new ChessPiece("卒", Color.black, bc, w - 4, h - 4, this);
黑卒2.set棋子类别(黑方颜色);
黑卒3 = new ChessPiece("卒", Color.black, bc, w - 4, h - 4, this);
黑卒3.set棋子类别(黑方颜色);
黑卒4 = new ChessPiece("卒", Color.black, bc, w - 4, h - 4, this);
黑卒4.set棋子类别(黑方颜色);
黑卒5 = new ChessPiece("卒", Color.black, bc, w - 4, h - 4, this);
黑卒5.set棋子类别(黑方颜色);
point[1][10].setPiece(红车1, this);
point[2][10].setPiece(红马1, this);
point[3][10].setPiece(红相1, this);
point[4][10].setPiece(红士1, this);
point[5][10].setPiece(红帅, this);
point[6][10].setPiece(红士2, this);
point[7][10].setPiece(红相2, this);
point[8][10].setPiece(红马2, this);
point[9][10].setPiece(红车2, this);
point[2][8].setPiece(红炮1, this);
point[8][8].setPiece(红炮2, this);
point[1][7].setPiece(红兵1, this);
point[3][7].setPiece(红兵2, this);
point[5][7].setPiece(红兵3, this);
point[7][7].setPiece(红兵4, this);
point[9][7].setPiece(红兵5, this);
point[1][1].setPiece(黑车1, this);
point[2][1].setPiece(黑马1, this);
point[3][1].setPiece(黑象1, this);
point[4][1].setPiece(黑士1, this);
point[5][1].setPiece(黑将, this);
point[6][1].setPiece(黑士2, this);
point[7][1].setPiece(黑象2, this);
point[8][1].setPiece(黑马2, this);
point[9][1].setPiece(黑车2, this);
point[2][3].setPiece(黑炮1, this);
point[8][3].setPiece(黑炮2, this);
point[1][4].setPiece(黑卒1, this);
point[3][4].setPiece(黑卒2, this);
point[5][4].setPiece(黑卒3, this);
point[7][4].setPiece(黑卒4, this);
point[9][4].setPiece(黑卒5, this);
public void paintComponent(Graphics g) {
super.paintComponent(g);
int imgWidth = img.getWidth(this);
int imgHeight = img.getHeight(this);// 获得图片的宽度与高度
int FWidth = getWidth();
int FHeight = getHeight();// 获得窗口的宽度与高度
int x = (FWidth - imgWidth) / 2;
int y = (FHeight - imgHeight) / 2;
g.drawImage(img, x, y, null);
for (int j = 1; j &= y轴长; j++) {
g.drawLine(point[1][j].x, point[1][j].y, point[x轴长][j].x,
point[x轴长][j].y);
for (int i = 1; i &= x轴长; i++) {
if (i != 1 && i != x轴长) {
g.drawLine(point[i][1].x, point[i][1].y, point[i][y轴长 - 5].x,
point[i][y轴长 - 5].y);
g.drawLine(point[i][y轴长 - 4].x, point[i][y轴长 - 4].y,
point[i][y轴长].x, point[i][y轴长].y);
g.drawLine(point[i][1].x, point[i][1].y, point[i][y轴长].x,
point[i][y轴长].y);
g.drawLine(point[4][1].x, point[4][1].y, point[6][3].x, point[6][3].y);
g.drawLine(point[6][1].x, point[6][1].y, point[4][3].x, point[4][3].y);
g.drawLine(point[4][8].x, point[4][8].y, point[6][y轴长].x,
point[6][y轴长].y);
g.drawLine(point[4][y轴长].x, point[4][y轴长].y, point[6][8].x,
point[6][8].y);
for (int i = 1; i &= x轴长; i++) {
g.drawString("" + i, i * unitWidth, unitHeight / 2);
int j = 1;
for (char c = 'A'; c &= 'J'; c++) {
g.drawString("" + c, unitWidth / 4, j * unitHeight);
/**鼠标按下事件*/
public void mousePressed(MouseEvent e) {
ChessPiece piece =
Rectangle rect =
if (e.getSource() == this)
if (move == false)
if (e.getSource() instanceof ChessPiece) {
piece = (ChessPiece) e.getSource();
startX = piece.getBounds().x;
startY = piece.getBounds().y;
rect = piece.getBounds();
for (int i = 1; i &= x轴长; i++) {
for (int j = 1; j &= y轴长; j++) {
int x = point[i][j].getX();
int y = point[i][j].getY();
if (rect.contains(x, y)) {
public void mouseMoved(MouseEvent e) {
/**鼠标拖动事件*/
public void mouseDragged(MouseEvent e) {
ChessPiece piece =
if (e.getSource() instanceof ChessPiece) {
piece = (ChessPiece) e.getSource();
e = SwingUtilities.convertMouseEvent(piece, e, this);
if (e.getSource() == this) {
if (move && piece != null) {
x = e.getX();
y = e.getY();
if (红方走棋 && ((piece.棋子类别()).equals(红方颜色))) {
piece.setLocation(x - piece.getWidth() / 2,
y - piece.getHeight() / 2);
if (黑方走棋 && (piece.棋子类别().equals(黑方颜色))) {
piece.setLocation(x - piece.getWidth() / 2,
y - piece.getHeight() / 2);
/**松开鼠标事件*/
public void mouseReleased(MouseEvent e) {
ChessPiece piece =
Rectangle rect =
if (e.getSource() instanceof ChessPiece) {
piece = (ChessPiece) e.getSource();
rect = piece.getBounds();
e = SwingUtilities.convertMouseEvent(piece, e, this);
if (e.getSource() == this) {
boolean containChessPoint =
int x = 0, y = 0;
int m = 0, n = 0;
if (piece != null) {
for (int i = 1; i &= x轴长; i++) {
for (int j = 1; j &= y轴长; j++) {
x = point[i][j].getX();
y = point[i][j].getY();
if (rect.contains(x, y)) {
containChessPoint =
if (piece != null && containChessPoint) {
Color pieceColor = piece.获取棋子颜色();
if (point[m][n].isPiece()) {
Color c = (point[m][n].getPiece()).获取棋子颜色();
if (pieceColor.getRGB() == c.getRGB()) {
piece.setLocation(startX, startY);
(point[startI][startJ]).set有棋子(true);
boolean ok = rule.movePieceRule(piece, startI, startJ,
ChessPiece pieceRemoved = point[m][n].getPiece();
point[m][n].reMovePiece(pieceRemoved, this);
point[m][n].setPiece(piece, this);
(point[startI][startJ]).set有棋子(false);
record.记录棋谱(piece, startI, startJ, m, n);
record.记录吃掉的棋子(pieceRemoved);
rule.isWine(pieceRemoved);
if (piece.棋子类别().equals(红方颜色)) {
红方走棋 =
黑方走棋 =
if (piece.棋子类别().equals(黑方颜色)) {
黑方走棋 =
红方走棋 =
validate();
repaint();
piece.setLocation(startX, startY);
(point[startI][startJ]).set有棋子(true);
boolean ok = rule
.movePieceRule(piece, startI, startJ, m, n);
point[m][n].setPiece(piece, this);
(point[startI][startJ]).set有棋子(false);
record.记录棋谱(piece, startI, startJ, m, n);
record.记录吃掉的棋子("没吃棋子");
if (piece.棋子类别().equals(红方颜色)) {
红方走棋 =
黑方走棋 =
if (piece.棋子类别().equals(黑方颜色)) {
黑方走棋 =
红方走棋 =
piece.setLocation(startX, startY);
(point[startI][startJ]).set有棋子(true);
if (piece != null && !containChessPoint) {
piece.setLocation(startX, startY);
(point[startI][startJ]).set有棋子(true);
public void mouseEntered(MouseEvent e) {
public void mouseExited(MouseEvent e) {
public void mouseClicked(MouseEvent e) {
3.棋子类文件ChessPiece.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* @author cnlht
public class ChessPiece extends JLabel {
S // 棋子名字
Color backColor = null, foreC// 背景色和前景色
String 颜色类别 =
ChessBoard board =
int width,// 大小
public ChessPiece(String name, Color fc, Color bc, int width, int height,
ChessBoard board) {// 构造棋子
this.name =
this.board =
this.width =
this.height =
foreColor =
backColor =
setSize(width, height);
setBackground(bc);
addMouseMotionListener(board);
addMouseListener(board);
// 绘制棋子
public void paint(Graphics g) {
g.drawImage(board.pieceImg, 2, 2, width-2, height-2, null);
g.setColor(foreColor);
g.setFont(new Font("楷体", Font.BOLD, 26));
g.drawString(name, 7, height - 8);// 在棋子上绘制 “棋子名”
g.setColor(Color.black);
//g.drawOval(1, 1, width - 1, height - 1);
float lineWidth = 2.3f;
((Graphics2D)g).setStroke(new BasicStroke(lineWidth));
((Graphics2D)g).drawOval(2, 2, width-2, height-2);
public int getWidth() {
public int getHeight() {
public String getName() {
public Color 获取棋子颜色() {
return foreC
public void set棋子类别(String 类别) {
颜色类别 = 类别;
public String 棋子类别() {
return 颜色类别;
4.棋子点坐标类文件
package cn.edu.ouc.chineseC
* @author cnlht
public class ChessPoint {
/** 棋子坐标 */
/** 该坐标 是否有子*/
boolean 有棋子;
/** 改坐标的棋子 */
ChessPiece piece =
/** 坐标所属棋盘 */
ChessBoard board =
public ChessPoint(int x, int y, boolean boo) {
public boolean isPiece() {
return 有棋子;
public void set有棋子(boolean boo) {
public int getX() {
public int getY() {
// 设置改点棋子
public void setPiece(ChessPiece piece, ChessBoard board) {
this.board =
this.piece =
board.add(piece);
int w = (board.unitWidth);
int h = (board.unitHeight);
piece.setBounds(x - w / 2, y - h / 2, w, h);// 棋子位置,宽度,高度
board.validate();
public ChessPiece getPiece() {
public void reMovePiece(ChessPiece piece, ChessBoard board) {
this.board =
this.piece =
board.remove(piece);
board.validate();
5.玩法规则类文件Rule.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* 走棋规则类
* @author cnlht
public class Rule {
ChessBoard board =
ChessPiece piece =
ChessPoint point[][];
int startI, startJ, endI, endJ;
public Rule(ChessBoard board, ChessPoint point[][]) {
this.board =
this.point =
public void isWine(ChessPiece piece) {
this.piece =
if (piece.getName() == "将" || piece.getName() == "帅") {
if (piece.颜色类别 == "红方") {
JOptionPane.showMessageDialog(null, "黑方 胜利!");
JOptionPane.showMessageDialog(null, "红方 胜利!");
public boolean movePieceRule(ChessPiece piece, int startI, int startJ,
int endI, int endJ) {
this.piece =
this.startI = startI;
this.startJ = startJ;
this.endI = endI;
this.endJ = endJ;
int minI = Math.min(startI, endI);
int maxI = Math.max(startI, endI);
int minJ = Math.min(startJ, endJ);
int maxJ = Math.max(startJ, endJ);
boolean 可否走棋 =
if (piece.getName().equals("车")) {
if (startI == endI) {
int j = 0;
for (j = minJ + 1; j &= maxJ - 1; j++) {
if (point[startI][j].isPiece()) {
可否走棋 =
if (j == maxJ) {
可否走棋 =
} else if (startJ == endJ) {
int i = 0;
for (i = minI + 1; i &= maxI - 1; i++) {
if (point[i][startJ].isPiece()) {
可否走棋 =
if (i == maxI) {
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("車")) {
if (startI == endI) {
int j = 0;
for (j = minJ + 1; j &= maxJ - 1; j++) {
if (point[startI][j].isPiece()) {
可否走棋 =
if (j == maxJ) {
可否走棋 =
} else if (startJ == endJ) {
int i = 0;
for (i = minI + 1; i &= maxI - 1; i++) {
if (point[i][startJ].isPiece()) {
可否走棋 =
if (i == maxI) {
可否走棋 =
可否走棋 =
}else if (piece.getName().equals("马")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (xAxle == 2 && yAxle == 1) {
if (endI & startI) {
if (point[startI + 1][startJ].isPiece()) {
可否走棋 =
可否走棋 =
if (endI & startI) {
if (point[startI - 1][startJ].isPiece()) {
可否走棋 =
可否走棋 =
}else if (xAxle == 1 && yAxle == 2) {
if (endJ & startJ) {
if (point[startI][startJ + 1].isPiece()) {
可否走棋 =
可否走棋 =
if (endJ & startJ) {
if (point[startI][startJ - 1].isPiece()) {
可否走棋 =
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("馬")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (xAxle == 2 && yAxle == 1) {
if (endI & startI) {
if (point[startI + 1][startJ].isPiece()) {
可否走棋 =
可否走棋 =
if (endI & startI) {
if (point[startI - 1][startJ].isPiece()) {
可否走棋 =
可否走棋 =
}else if (xAxle == 1 && yAxle == 2) {
if (endJ & startJ) {
if (point[startI][startJ + 1].isPiece()) {
可否走棋 =
可否走棋 =
if (endJ & startJ) {
if (point[startI][startJ - 1].isPiece()) {
可否走棋 =
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("象")) {
int centerI = (startI + endI) / 2;
int centerJ = (startJ + endJ) / 2;
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (xAxle == 2 && yAxle == 2 && endJ &= 5) {
if (point[centerI][centerJ].isPiece()) {
可否走棋 =
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("相")) {
int centerI = (startI + endI) / 2;
int centerJ = (startJ + endJ) / 2;
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (xAxle == 2 && yAxle == 2 && endJ &= 6) {
if (point[centerI][centerJ].isPiece()) {
可否走棋 =
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("炮")) {
int number = 0;
if (startI == endI) {
int j = 0;
for (j = minJ + 1; j &= maxJ - 1; j++) {
if (point[startI][j].isPiece()) {
if (number & 1) {
可否走棋 =
} else if (number == 1) {
if (point[endI][endJ].isPiece()) {
可否走棋 =
} else if (number == 0 && !point[endI][endJ].isPiece()) {
可否走棋 =
} else if (startJ == endJ) {
int i = 0;
for (i = minI + 1; i &= maxI - 1; i++) {
if (point[i][startJ].isPiece()) {
if (number & 1) {
可否走棋 =
} else if (number == 1) {
if (point[endI][endJ].isPiece()) {
可否走棋 =
} else if (number == 0 && !point[endI][endJ].isPiece()) {
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("兵")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (endJ &= 6) {
if (startJ - endJ == 1 && xAxle == 0) {
可否走棋 =
可否走棋 =
} else if (endJ &= 5) {
if ((startJ - endJ == 1) && (xAxle == 0)) {
可否走棋 =
} else if ((endJ - startJ == 0) && (xAxle == 1)) {
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("卒")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (endJ &= 5) {
if (endJ - startJ == 1 && xAxle == 0) {
可否走棋 =
可否走棋 =
} else if (endJ &= 6) {
if ((endJ - startJ == 1) && (xAxle == 0)) {
可否走棋 =
} else if ((endJ - startJ == 0) && (xAxle == 1)) {
可否走棋 =
可否走棋 =
else if (piece.getName().equals("士")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (endI &= 6 && endI &= 4 && xAxle == 1 && yAxle == 1) {
可否走棋 =
可否走棋 =
} else if (piece.getName().equals("仕")) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (endI &= 6 && endI &= 4 && xAxle == 1 && yAxle == 1) {
可否走棋 =
可否走棋 =
} else if ((piece.getName().equals("帅"))
|| (piece.getName().equals("将"))) {
int xAxle = Math.abs(startI - endI);
int yAxle = Math.abs(startJ - endJ);
if (endI &= 6 && endI &= 4) {
if ((xAxle == 1 && yAxle == 0) || (xAxle == 0 && yAxle == 1)) {
可否走棋 =
可否走棋 =
可否走棋 =
return 可否走棋;
6.走步类文件MoveStep.java
package cn.edu.ouc.chineseC
import java.awt.P
* @author cnlht
public class MoveStep implements java.io.Serializable {
public Point pStart, pE
public MoveStep(Point p1, Point p2) {
pStart = p1;
pEnd = p2;
7.制作棋谱类MakeChessManual.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedL
* 制作棋谱类
* @author cnlht
public class MakeChessManual extends JPanel implements ActionListener {
JTextArea text =
JScrollPane scroll =
ChessBoard board =
ChessPoint[][]
LinkedList 棋谱 =
LinkedList 吃掉的棋子 =
JButton buttonU
int i = 0;
public MakeChessManual(ChessBoard board, ChessPoint[][] point) {
this.board =
this.point =
text = new JTextArea();
scroll = new JScrollPane(text);
棋谱 = new LinkedList();
吃掉的棋子 = new LinkedList();
buttonUndo = new JButton("悔棋");
buttonUndo.setFont(new Font("隶书", Font.PLAIN, 18));
setLayout(new BorderLayout());
add(scroll, BorderLayout.CENTER);
add(buttonUndo, BorderLayout.SOUTH);
buttonUndo.addActionListener(this);
public char numberToLetter(int n) {
char c = '\0';
switch (n) {
public void 记录棋谱(ChessPiece piece, int startI, int startJ, int endI,
int endJ) {
Point pStart = new Point(startI, startJ);
Point pEnd = new Point(endI, endJ);
MoveStep step = new MoveStep(pStart, pEnd);
棋谱.add(step);
String 棋子类别 = piece.棋子类别();
String name = piece.getName();
String m = "#" + 棋子类别 + name + ": " + startI + numberToLetter(startJ)
+ " 到 " + endI + numberToLetter(endJ);
text.append(m);
if (piece.棋子类别().equals(board.黑方颜色))
text.append("\n");
public void 记录吃掉的棋子(Object object) {
吃掉的棋子.add(object);
public LinkedList 获取棋谱() {
return 棋谱;
public void actionPerformed(ActionEvent e) {
int position = text.getText().lastIndexOf("#");
if (position != -1)
text.replaceRange("", position, text.getText().length());
if (棋谱.size() & 0) {
MoveStep lastStep = (MoveStep) 棋谱.getLast();
棋谱.removeLast();
Object qizi = 吃掉的棋子.getLast();
吃掉的棋子.removeLast();
String temp = qizi.toString();
if (temp.equals("没吃棋子")) {
int startI = lastStep.pStart.x;
int startJ = lastStep.pStart.y;
int endI = lastStep.pEnd.x;
int endJ = lastStep.pEnd.y;
ChessPiece piece = point[endI][endJ].getPiece();
point[startI][startJ].setPiece(piece, board);
(point[endI][endJ]).set有棋子(false);
if (piece.棋子类别().equals(board.红方颜色)) {
board.红方走棋 =
board.黑方走棋 =
if (piece.棋子类别().equals(board.黑方颜色)) {
board.黑方走棋 =
board.红方走棋 =
ChessPiece removedPiece = (ChessPiece)
int startI = lastStep.pStart.x;
int startJ = lastStep.pStart.y;
int endI = lastStep.pEnd.x;
int endJ = lastStep.pEnd.y;
ChessPiece piece = point[endI][endJ].getPiece();
point[startI][startJ].setPiece(piece, board);
point[endI][endJ].setPiece(removedPiece, board);
(point[endI][endJ]).set有棋子(true);
if (piece.棋子类别().equals(board.红方颜色)) {
board.红方走棋 =
board.黑方走棋 =
if (piece.棋子类别().equals(board.黑方颜色)) {
board.黑方走棋 =
board.红方走棋 =
8.演示棋谱类文件Demon.java
package cn.edu.ouc.chineseC
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
* 演示棋谱类
* @author cnlht
public class Demon extends JPanel implements ActionListener, Runnable {
public JButton replay = null, next = null, auto = null, stop =
LinkedList 棋谱 =
Thread 自动演示 =
int index = -1;
ChessBoard board =
JTextField 时间间隔 =
int time = 1000;
String 演示过程 = "";
JSplitPane splitH = null, splitV =
public Demon(ChessBoard board) {
this.board =
replay = new JButton("重新演示");
next = new JButton("下一步");
auto = new JButton("自动演示");
stop = new JButton("暂停演示");
自动演示 = new Thread(this);
replay.addActionListener(this);
next.addActionListener(this);
auto.addActionListener(this);
stop.addActionListener(this);
text = new JTextArea();
时间间隔 = new JTextField("1");
setLayout(new BorderLayout());
JScrollPane pane = new JScrollPane(text);
JPanel p = new JPanel(new GridLayout(3, 2));
p.add(next);
p.add(replay);
p.add(auto);
p.add(stop);
p.add(new JLabel("时间间隔(秒)", SwingConstants.CENTER));
p.add(时间间隔);
splitV = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, p);
splitH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, board, splitV);
splitV.setDividerSize(5);
splitV.setDividerLocation(400);
splitH.setDividerSize(5);
splitH.setDividerLocation(460);
add(splitH, BorderLayout.CENTER);
validate();
public void set棋谱(LinkedList 棋谱) {
this.棋谱 = 棋谱;
public char numberToLetter(int n) {
char c = '\0';
switch (n) {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == next) {
if (index & 棋谱.size()) {
演示一步(index);
演示结束("棋谱演示完毕");
if (e.getSource() == replay) {
board = new ChessBoard(45, 45, 9, 10);
splitH.remove(board);
splitH.setDividerSize(5);
splitH.setDividerLocation(460);
splitH.setLeftComponent(board);
splitH.validate();
index = -1;
text.setText(null);
if (e.getSource() == auto) {
next.setEnabled(false);
replay.setEnabled(false);
time = 1000 * Integer.parseInt(时间间隔.getText().trim());
} catch (NumberFormatException ee) {
time = 1000;
if (!(自动演示.isAlive())) {
自动演示 = new Thread(this);
board = new ChessBoard(45, 45, 9, 10);
splitH.remove(board);
splitH.setDividerSize(5);
splitH.setDividerLocation(460);
splitH.setLeftComponent(board);
splitH.validate();
text.setText(null);
自动演示.start();
if (e.getSource() == stop) {
if (e.getActionCommand().equals("暂停演示")) {
演示过程 = "暂停演示";
stop.setText("继续演示");
stop.repaint();
if (e.getActionCommand().equals("继续演示")) {
演示过程 = "继续演示";
自动演示.interrupt();
stop.setText("暂停演示");
stop.repaint();
public synchronized void run() {
for (index = 0; index & 棋谱.size(); index++) {
Thread.sleep(time);
} catch (InterruptedException e) {
while (演示过程.equals("暂停演示")) {
} catch (InterruptedException e) {
notifyAll();
演示一步(index);
if (index &= 棋谱.size()) {
演示结束("棋谱演示完毕");
next.setEnabled(true);
replay.setEnabled(true);
public void 演示一步(int index) {
MoveStep step = (MoveStep) 棋谱.get(index);
Point pStart = step.pS
Point pEnd = step.pE
int startI = pStart.x;
int startJ = pStart.y;
int endI = pEnd.x;
int endJ = pEnd.y;
ChessPiece piece = (board.point)[startI][startJ].getPiece();
if ((board.point)[endI][endJ].isPiece() == true) {
ChessPiece pieceRemoved = (board.point)[endI][endJ].getPiece();
(board.point)[endI][endJ].reMovePiece(pieceRemoved, board);
board.repaint();
(board.point)[endI][endJ].setPiece(piece, board);
(board.point)[startI][startJ].set有棋子(false);
board.repaint();
(board.point)[endI][endJ].setPiece(piece, board);
(board.point)[startI][startJ].set有棋子(false);
String 棋子类别 = piece.棋子类别();
String name = piece.getName();
String m = "#" + 棋子类别 + name + ": " + startI + numberToLetter(startJ)
+ " 到 " + endI + numberToLetter(endJ);
text.append(m);
if (piece.棋子类别().equals(board.黑方颜色))
text.append("\n");
public void 演示结束(String message) {
splitH.remove(board);
splitH.setDividerSize(5);
splitH.setDividerLocation(460);
JLabel label = new JLabel(message);
label.setFont(new Font("隶书", Font.BOLD, 40));
label.setForeground(Color.blue);
label.setHorizontalAlignment(SwingConstants.CENTER);
splitH.setLeftComponent(label);
splitH.validate();
四、总结与要求
1.理解8个文件,没有太复杂的代码。
2.理解鼠标的MouseListener,MouseMotionListener两个接口的区别,五子棋的实现不需要MouseMotionListener。
3.使用LinkedList记录棋谱的方法。
希望大家喜欢这篇文章,制作一款属于自己的中国象棋游戏。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

 

随机推荐