北大青鸟 中国象棋 实习项目 (项目源代码级说明五)
2008-07-19 19:54
393 查看
棋子马
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace chess
{
/// <summary>
/// 棋子马
/// </summary>
[Serializable()]
class chessItemMa : ChessItemBase
{
/// <summary>
/// 判断绊脚
/// </summary>
/// <param name="begin">起始点</param>
/// <param name="end">结束点</param>
/// <returns>是否有绊脚情况bool</returns>
public bool HaveChess(Point begin, Point end)
{
//判断是否绊脚
Panel panel = (Panel)this.Parent;
ControlCollection colection = panel.Controls;
bool flag = true;
Point temp = new Point();
//往上跳
if ((end.Y < begin.Y) && ((end.X - begin.X == 1) || (end.X - begin.X == -1)))
{
temp = new Point(begin.X, begin.Y - 1);
}
//往下跳
if ((end.Y > begin.Y )&& ((end.X - begin.X == 1) || (end.X - begin.X == -1)))
{
temp = new Point(begin.X,begin.Y+1);
}
//往左方跳
if ((end.X < begin.X) && ((end.X - begin.X == 2) || (end.X - begin.X == -2)))
{
temp = new Point(begin.X-1,begin.Y);
}
//往右方跳
if ((end.X > begin.X) && ((end.X - begin.X == 2) || (end.X - begin.X == -2)))
{
temp = new Point(begin.X+1,begin.Y);
}
foreach (Control control in colection)
{
Point point = PointToGrid(control.Location.X, control.Location.Y);
point.Offset(1, 1);
if ((temp.X == point.X) && (temp.Y == point.Y))
{
flag = false;
}
}
return flag;
}
/// <summary>
/// 重写父类限制走法方法
/// </summary>
/// <param name="ChessX">坐标点的X坐标</param>
/// <param name="ChessY">坐标点的Y坐标</param>
/// <returns>返回结果bool</returns>
protected override bool LimitPoint(int ChessX, int ChessY)
{
//先执行基类中的方法
if (base.LimitPoint(ChessX, ChessY))
{
Point begin = PointToGrid(this.Location.X, this.Location.Y);
begin.Offset(1, 1);
Point end = PointToGrid(ChessX, ChessY);
//是否走的日字格
if (((begin.X - end.X) == -1) || ((begin.X - end.X) == 1))
{
if (((begin.Y - end.Y) == -2) || ((begin.Y - end.Y) == 2))
{
if (this.chesstype == ChessTypes.black)
{
if (HaveChess(begin, end))
{
return true;
}
}
else if (this.chesstype == ChessTypes.blue)
{
if (HaveChess(begin, end))
{
return true;
}
}
}
}
if (((begin.X - end.X) == -2) || ((begin.X - end.X) == 2))
{
if (((begin.Y - end.Y) == -1) || ((begin.Y - end.Y) == 1))
{
if (this.chesstype == ChessTypes.black)
{
if (HaveChess(begin, end))
{
return true;
}
}
else if (this.chesstype == ChessTypes.blue)
{
if (HaveChess(begin, end))
{
return true;
}
}
}
}
}
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace chess
{
/// <summary>
/// 棋子马
/// </summary>
[Serializable()]
class chessItemMa : ChessItemBase
{
/// <summary>
/// 判断绊脚
/// </summary>
/// <param name="begin">起始点</param>
/// <param name="end">结束点</param>
/// <returns>是否有绊脚情况bool</returns>
public bool HaveChess(Point begin, Point end)
{
//判断是否绊脚
Panel panel = (Panel)this.Parent;
ControlCollection colection = panel.Controls;
bool flag = true;
Point temp = new Point();
//往上跳
if ((end.Y < begin.Y) && ((end.X - begin.X == 1) || (end.X - begin.X == -1)))
{
temp = new Point(begin.X, begin.Y - 1);
}
//往下跳
if ((end.Y > begin.Y )&& ((end.X - begin.X == 1) || (end.X - begin.X == -1)))
{
temp = new Point(begin.X,begin.Y+1);
}
//往左方跳
if ((end.X < begin.X) && ((end.X - begin.X == 2) || (end.X - begin.X == -2)))
{
temp = new Point(begin.X-1,begin.Y);
}
//往右方跳
if ((end.X > begin.X) && ((end.X - begin.X == 2) || (end.X - begin.X == -2)))
{
temp = new Point(begin.X+1,begin.Y);
}
foreach (Control control in colection)
{
Point point = PointToGrid(control.Location.X, control.Location.Y);
point.Offset(1, 1);
if ((temp.X == point.X) && (temp.Y == point.Y))
{
flag = false;
}
}
return flag;
}
/// <summary>
/// 重写父类限制走法方法
/// </summary>
/// <param name="ChessX">坐标点的X坐标</param>
/// <param name="ChessY">坐标点的Y坐标</param>
/// <returns>返回结果bool</returns>
protected override bool LimitPoint(int ChessX, int ChessY)
{
//先执行基类中的方法
if (base.LimitPoint(ChessX, ChessY))
{
Point begin = PointToGrid(this.Location.X, this.Location.Y);
begin.Offset(1, 1);
Point end = PointToGrid(ChessX, ChessY);
//是否走的日字格
if (((begin.X - end.X) == -1) || ((begin.X - end.X) == 1))
{
if (((begin.Y - end.Y) == -2) || ((begin.Y - end.Y) == 2))
{
if (this.chesstype == ChessTypes.black)
{
if (HaveChess(begin, end))
{
return true;
}
}
else if (this.chesstype == ChessTypes.blue)
{
if (HaveChess(begin, end))
{
return true;
}
}
}
}
if (((begin.X - end.X) == -2) || ((begin.X - end.X) == 2))
{
if (((begin.Y - end.Y) == -1) || ((begin.Y - end.Y) == 1))
{
if (this.chesstype == ChessTypes.black)
{
if (HaveChess(begin, end))
{
return true;
}
}
else if (this.chesstype == ChessTypes.blue)
{
if (HaveChess(begin, end))
{
return true;
}
}
}
}
}
return false;
}
}
}
相关文章推荐
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明六)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明七)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明二)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明十一)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明一)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明八)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明三)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明九)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明四)
- 北大青鸟 中国象棋 实习项目 (项目源代码级说明十)
- 北大青鸟 中国象棋 实习项目 (老师点评)
- 开源密码管理软件项目说明(附源代码)
- C++项目开发中国象棋
- [原创]C#中国象棋网络版源代码-C# Chinese Chess Source Code
- 实习第二天(查看项目源代码)
- (转)用Java写的中国象棋源代码
- 中国象棋源代码
- 【完全开源】知乎日报UWP版:项目结构说明、关键源代码解释
- [置顶] 中国象棋程序的设计与实现(高级版)(项目截图)
- 用html+css+js实现中国象棋小游戏开发项目