中国象棋源代码C#

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using using using using using using using using using using using
System; System.Collections.Generic; ponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.IO; System.Media; System.Diagnostics;
for (int row = 1; row <= 10; row++) { g.DrawString(row.ToString(), font2, fontBrush, new Point((int)(_leftTop.X + _columnWidth * 8.6), (int)(_leftTop.Y _rowHeight * 0.4 + _rowHeight * (row - 1)))); } //书写列数字编号 string[] colNumber = new string[10] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; Font font3 = new Font("黑体", (float)(_rowHeight * 0.5), FontStyle.Regular, GraphicsUnit.Pixel); for (int col = 1; col <= 9; col++) { g.DrawString(colNumber[col], font3, fontBrush, new Point((int)(_leftTop.X - 0.25 * _columnWidth + _columnWidth * (col 1)), (int)(_leftTop.Y + 9.6 * _rowHeight))); } //书写“甲方”“乙方” g.DrawString("甲方", font3, fontBrush, new Point(_leftTop.X + 8 * _columnWidth + 100, (int)(_leftTop.Y + 2.5 * _rowHeight))); g.DrawString("乙方", font3, fontBrush, new Point(_leftTop.X + 8 * _columnWidth + 100, (int)(_leftTop.Y + 6.5 * _rowHeight))); //绘制棋盘第三行焦点的细线条 DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 2), true, true, true, true); DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 2), true, true, true, true); //绘制第四行焦点的线条 DrawCrossLine(g, new Point(_leftTop.X, _leftTop.Y + * 3), false, true, false, true); DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 3), true, true, true, true); DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 3), true, true, true, true); DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 3), true, true, true, true); DrawCrossLine(g, new Point(_leftTop.X + _columnWidth + _rowHeight * 3), true, false, true, false); //绘制第七行焦点的线条 DrawCrossLine(g, new Point(_leftTop.X, _leftTop.Y +
namespace Chess { //定义一个走棋步骤结构 struct ChessStep { public string _whoPlay; public string _pickPiece; //拾起的棋子行列号 public int _pickRow; public int _pickCol; //放下位置的棋子值 public string _dropPiece; //放下棋子行列号 public int _dropRow; public int _dropCol; } public partial class FormMain : Form { //存储走棋步骤的List集合 private List<ChessStep> _listStep = new List<ChessStep>(); //象棋棋盘的棋子值 private string[,] _chessValue = new string[11, 10]; //象棋棋盘的行高和列宽 private int _rowHeight = 60; private int _columnWidth = 60; //象棋棋盘的左上角点 private Point _leftTop = new Point(80, 100); //棋子半径 private int _pieceRadius = 29; //拾起的棋子值 private string _pickChessValue = "无子";
//拾起的棋子行号 private int _pickRow = -1; //拾起的棋子列号 private int _pickCol = -1; //鼠标移动时所在点的坐标 private Point _mouseMovePoint = new Point(0, 0); //棋盘背景位图对象 Bitmap _bmpBg = new Bitmap("棋盘桌面.jpg"); //棋子位图对象(甲乙双方共有14种棋子) Bitmap[] _bmpPiece = new Bitmap[14]; //头像位图对象 Bitmap _bmpHeadJia = new Bitmap("甲方头像.bmp"); Bitmap _bmpHeadYi = new Bitmap("乙方头像.bmp"); //当前走棋方 private string _whoPlay = "无"; //当前.exe文件所在路径 string _exePath; //当前保存或打开的文件名 private string _fileName = ""; //=============================================================== //类成员方法:绘制棋盘 public void DrawChessBoard(Graphics g) { //绘制棋盘背景 // Bitmap bmpBg = new Bitmap("棋盘桌面.jpg"); g.DrawImage(_bmpBg, new Point(0, 0)); //创建粗画笔和细画笔 Pen thinPen = new Pen(Color.Black, 2); Pen thickPen = new Pen(Color.Black, 6); //绘制外围的方框 g.DrawRectangle(thickPen, new Rectangle(_leftTop.X - 10, _leftTop.Y - 10, _columnWidth * 8 + 20, _rowHeight * 9 + 20)); //绘制10条横线 for (int row = 1; row <= 10; row++) { g.DrawLine(thinPen, new Point(_leftTop.X, _leftTop.Y + _rowHeight * (row - 1)), new Point(_leftTop.X + 8 * _columnWidth, _leftTop.Y + _rowHeight * (row - 1))); } //绘制9列 for (int col = 1; col <= 9; col++) {
//绘制棋盘上半部分的竖线 g.DrawLine(thinPen, new Point(_leftTop.X + _columnWidth * (col - 1), _leftTop.Y), new Point(_leftTop.X + _columnWidth * (col - 1), _leftTop.Y + 4 * _rowHeight)); //绘制棋盘下半部分的竖线 g.DrawLine(thinPen, new Point(_leftTop.X + _columnWidth * (col - 1), _leftTop.Y + 5 * _rowHeight), new Point(_leftTop.X + _columnWidth * (col - 1), _leftTop.Y + 9 * _rowHeight)); } //绘制链接楚河汉界左右两端的两条短竖线 g.DrawLine(thinPen, new Point(_leftTop.X, _leftTop.Y), new Point(_leftTop.X, _leftTop.Y + 9 * _rowHeight)); g.DrawLine(thinPen, new Point(_leftTop.X + 8 * _columnWidth, _leftTop.Y), new Point(_leftTop.X + 8 * _columnWidth, _leftTop.Y + 9 * _rowHeight)); //绘制上方大本营的交叉线 g.DrawLine(thinPen, new Point(_leftTop.X + 3 * _columnWidth, _leftTop.Y), new Point(_leftTop.X + 5 * _columnWidth, _leftTop.Y + 2 * _rowHeight)); g.DrawLine(thinPen, new Point(_leftTop.X + 5 * _columnWidth, _leftTop.Y), new Point(_leftTop.X + 3 * _columnWidth, _leftTop.Y + 2 * _columnWidth)); //绘制下方大本营交叉线 g.DrawLine(thinPen, new Point(_leftTop.X + 3 * _columnWidth, _leftTop.Y + 7 * _rowHeight), new Point(_leftTop.X + 5 * _columnWidth, _leftTop.Y + 9 * _rowHeight)); g.DrawLine(thinPen, new Point(_leftTop.X + 5 * _columnWidth, _leftTop.Y + 7 * _rowHeight), new Point(_leftTop.X + 3 * _columnWidth, _leftTop.Y + 9 * _rowHeight)); //书写“楚河”“汉界” Font font1 = new Font("隶书", (float)(_rowHeight * 0.8), FontStyle.Regular, GraphicsUnit.Pixel); SolidBrush fontBrush = new SolidBrush(Color.Black); g.DrawString("楚河", font1, fontBrush, new Point(_leftTop.X + _columnWidth, (inபைடு நூலகம்)(_leftTop.Y + 4.1 * _rowHeight))); g.DrawString("汉界", font1, fontBrush, new Point(_leftTop.X + 5 * _columnWidth, (int)(_leftTop.Y + 4.1 * _rowHeight))); //书写行数字编号 Font font2 = new Font("黑体", (float)(_rowHeight * 0.6), FontStyle.Regular, GraphicsUnit.Pixel);
相关文档
最新文档