中国象棋
来源:互联网 发布:数据库系统概论知识点 编辑:程序博客网 时间:2024/04/28 14:31
本来很早就很想写个中国象棋,但是一直没有机会,前几天看到有人写了个,然后我也就写了个,代码没有那么短,只是给它分了类,我将它分成四个类;首先一个基类是所有的棋子的抽象类,然后有个具体类,将所有的需要特别设置的放到子类中实现,还有一个棋盘类,他是管理棋子和操作等步骤,最后一个是标志类,用来说明那个棋子被选中.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;namespace ChineseChess{ public abstract class APiece { public event EventHandler<EventArgs> Dying; public APiece(ChessBoard cb) { this.ChessBoard = cb; } public Image Image { get; set; } private bool isdead = false; public bool IsDead { get { return isdead; } set { if (value) { if (Dying != null) Dying(this, EventArgs.Empty); // this.ChessBoard.PieceList.Remove(this); } isdead = value; } } public string Name { get; set; } public ChessBoard ChessBoard { get; private set; } public Point Location { get; set; } public bool IsRed { get; set; } public virtual void Eat(APiece p) { p.IsDead = true; } public virtual bool Move(Point node) { if (this.Location == node) return false; var t = this.ChessBoard.GetPiece(node); if (t == null) { this.Location = node; } else { if (t.IsRed != this.IsRed) { this.Eat(t); this.Location = node; } } return true; } protected int Stop(Point Target) { int qry = 0; if (this.Location.X == Target.X) { int max = this.Location.Y > Target.Y ? this.Location.Y : Target.Y; int min = this.Location.Y + Target.Y - max; qry = (from p in this.ChessBoard.PieceList where p.Location.X == this.Location.X && p.Location.Y < max && p.Location.Y > min && !p.IsDead select p).Count(); } if (this.Location.Y == Target.Y) { int max = this.Location.X > Target.X ? this.Location.X : Target.X; int min = this.Location.X + Target.X - max; qry = (from p in this.ChessBoard.PieceList where p.Location.Y == this.Location.Y && p.Location.X < max && p.Location.X > min && !p.IsDead select p).Count(); } return qry; } protected int Step(Point Target) { var dx = Target.X - this.Location.X; var dy = Target.Y - this.Location.Y; return dx * dx + dy * dy; } public virtual void Draw(Graphics g) { if (!IsDead) { g.DrawImage(this.Image, this.ChessBoard.GetPixelRantangle(this.Location)); } } }}
- 中国象棋
- 中国象棋
- 中国象棋
- 中国象棋
- 中国象棋
- 中国象棋源代码
- 中国象棋规则
- ajax中国象棋
- 中国象棋心得
- 中国象棋程序
- 中国象棋2
- 中国象棋3
- 中国象棋源码
- 中国象棋心得
- Qt中国象棋
- 中国象棋机器人
- [HAOI2009]中国象棋
- Android--中国象棋
- 一个 Linux 狂人的语录
- 一个 Linux 高手写给初学者的话
- box2d判断物体脱离地图边界
- Android 应用五大核心块 --- Service后台服务
- warning: check_safe_call: could not restore current frame
- 中国象棋
- http://www.cnblogs.com/qqloving/archive/2012/02/25/2367813.html
- photoshop 怎么用参考线将页面平分
- Java中文件选择框JFileChooser的用法
- objective-c中的cocoa特性:KVC-键值编码(十三)
- Unable to find the wrapper "https"错误的解决办法
- 数据库实现同数据结构的关系
- streams 都验证过的
- C++第5周任务1-4使用默认参数的构造函数,不给定实参时,默认边长为1