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);
}
}
}
中国象棋2
最新推荐文章于 2024-07-26 13:02:56 发布