中国象棋2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace ChineseChess
{
    class RBoss : APiece
    {
        public RBoss(ChessBoard cb)
            : base(cb)
        {
            this.Name = "帅";
            this.IsRed = true;
            this.Image = Properties.Resources.RBoss;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(4, 1, 3, 3);
            if (!rec.Contains(node) || base.Step(node) != 1) return false; //判断是否在边界里面

            return base.Move(node);
        }
    }
    class BBoss : APiece
    {
        public BBoss(ChessBoard cb)
            : base(cb)
        {
            this.Name = "将";
            this.IsRed = false;
            this.Image = Properties.Resources.BBoss;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(4, 8, 3, 3);
            if (!rec.Contains(node) || base.Step(node) != 1) return false; //判断是否在边界里面

            return base.Move(node);
        }
    }
    class RShi : APiece
    {
        public RShi(ChessBoard cb)
            : base(cb)
        {
            this.Name = "仕";
            this.IsRed = true;
            this.Image = Properties.Resources.RShi;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(4, 1, 3, 3);
            if (!rec.Contains(node) || base.Step(node) != 2) return false;//判断是否在边界里面

            return base.Move(node);
        }
    }
    class BShi : APiece
    {
        public BShi(ChessBoard cb)
            : base(cb)
        {
            this.Name = "士";
            this.IsRed = false;
            this.Image = Properties.Resources.BShi;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(4, 8, 3, 3);
            if (!rec.Contains(node) || base.Step(node) != 2) return false;//判断是否在边界里面

            return base.Move(node);
        }
    }
    class RXiang : APiece
    {
        public RXiang(ChessBoard cb)
            : base(cb)
        {
            this.Name = "相";
            this.IsRed = true;
            this.Image = Properties.Resources.RXiang;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 5);
            if (!rec.Contains(node) || base.Step(node) != 8) return false;  //判断是否在边界里面

            var a = new Point((node.X + this.Location.X) / 2, (node.Y + this.Location.Y) / 2); //不能被填心
            if (this.ChessBoard.GetPiece(a) != null) return false;

            return base.Move(node);
        }
    }
    class BXiang : APiece
    {
        public BXiang(ChessBoard cb)
            : base(cb)
        {
            this.Name = "象";
            this.IsRed = false;
            this.Image = Properties.Resources.BXiang;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 5);
            if (!rec.Contains(node) || base.Step(node) != 8) return false;  //判断是否在边界里面
            var a = new Point((node.X + this.Location.X) / 2, (node.Y + this.Location.Y) / 2); //不能被填心
            if (this.ChessBoard.GetPiece(a) != null) return false;

            return base.Move(node);

        }
    }
    class RMa : APiece
    {
        public RMa(ChessBoard cb)
            : base(cb)
        {
            this.Name = "马";
            this.IsRed = true;
            this.Image = Properties.Resources.RMa;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node) || base.Step(node) != 5) return false;//判断是否在边界里面

            var a = new Point(); //不能被拐脚
            if (Math.Abs(node.X - this.Location.X) == 1)
            {
                a = new Point(this.Location.X, (node.Y + this.Location.Y) / 2);
            }
            else
            {
                a = new Point((node.X + this.Location.X) / 2, this.Location.Y);
            }
            if (this.ChessBoard.GetPiece(a) != null) return false;

            return base.Move(node);
        }
    }
    class BMa : APiece
    {
        public BMa(ChessBoard cb)
            : base(cb)
        {
            this.Name = "马";
            this.IsRed = false;
            this.Image = Properties.Resources.BMa;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 8, 9);
            if (!rec.Contains(node) || base.Step(node) != 5) return false; //判断是否在边界里面


            var a = new Point(); //不能被拐脚
            if (Math.Abs(node.X - this.Location.X) == 1)
            {
                a = new Point(this.Location.X, (node.Y + this.Location.Y) / 2);
            }
            else
            {
                a = new Point((node.X + this.Location.X) / 2, this.Location.Y);
            }
            if (this.ChessBoard.GetPiece(a) != null) return false;
            return base.Move(node);
        }
    }
    class RJu : APiece
    {
        public RJu(ChessBoard cb)
            : base(cb)
        {
            this.Name = "车";
            this.IsRed = true;
            this.Image = Properties.Resources.RJu;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node)) return false; //判断是否在边界里面
            if ((node.X != this.Location.X) && (node.Y != this.Location.Y)) return false; //走法规则
            if (base.Stop(node) != 0) return false;

            return base.Move(node);
        }
    }
    class BJu : APiece
    {
        public BJu(ChessBoard cb)
            : base(cb)
        {
            this.Name = "车";
            this.IsRed = false;
            this.Image = Properties.Resources.BJu;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node)) return false; //判断是否在边界里面
            if ((node.X != this.Location.X) && (node.Y != this.Location.Y)) return false; //走法规则
            if (base.Stop(node) != 0) return false;

            return base.Move(node);
        }
    }
    class RPao : APiece
    {
        public RPao(ChessBoard cb)
            : base(cb)
        {
            this.Name = "炮";
            this.IsRed = true;
            this.Image = Properties.Resources.RPao;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node)) return false; //判断是否在边界里面

            if ((node.X != this.Location.X) && (node.Y != this.Location.Y)) return false; //走法规则
            var n = base.Stop(node);
            var t = this.ChessBoard.GetPiece(node);
            if (n == 0)
            {
                if (t == null)
                {
                    this.Location = node;
                    return true;
                }
            }
            else if (n == 1)
            {
                if (t != null && t.IsRed != this.IsRed)
                {
                    t.IsDead = true;
                    this.Location = node;
                    return true;
                }
            }
            return false;
        }
    }
    class BPao : APiece
    {
        public BPao(ChessBoard cb)
            : base(cb)
        {
            this.Name = "炮";
            this.IsRed = false;
            this.Image = Properties.Resources.BPao;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node)) return false; //判断是否在边界里面

            if ((node.X != this.Location.X) && (node.Y != this.Location.Y)) return false; //走法规则
            var n = base.Stop(node);
            var t = this.ChessBoard.GetPiece(node);
            if (n == 0)
            {
                if (t == null)
                {
                    this.Location = node;
                    return true;
                }
            }
            else if (n == 1)
            {
                if (t != null && t.IsRed != this.IsRed)
                {
                    t.IsDead = true;
                    this.Location = node;
                    return true;
                }
            }
            return false;
        }
    }
    class RBin : APiece
    {
        public RBin(ChessBoard cb)
            : base(cb)
        {
            this.Name = "兵";
            this.IsRed = true;
            this.Image = Properties.Resources.RBin;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node) || base.Step(node) != 1) return false;  //判断是否在边界里面和步长

            if (this.Location.Y < 6)
            {
                if (node.Y <= this.Location.Y) return false;
            }
            else
            {
                if (node.Y < this.Location.Y) return false;
            }

            return base.Move(node);
        }
    }
    class BBin : APiece
    {
        public BBin(ChessBoard cb)
            : base(cb)
        {
            this.Name = "兵";
            this.IsRed = false;
            this.Image = Properties.Resources.BBin;
        }
        public override bool Move(Point node)
        {
            var rec = new Rectangle(1, 1, 9, 10);
            if (!rec.Contains(node) || base.Step(node) != 1) return false; //判断是否在边界里面

            if (this.Location.Y < 6)
            {
                if (node.Y > this.Location.Y) return false;
            }
            else
            {
                if (node.Y >= this.Location.Y) return false;
            }

            return base.Move(node);
        }
    }

}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值