本文整理汇总了C#中Figure.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# Figure.Reverse方法的具体用法?C# Figure.Reverse怎么用?C# Figure.Reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Figure
的用法示例。
在下文中一共展示了Figure.Reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMoves
public MyList<Position> GetMoves(Figure figure, ChessField cf)
{
Position pos = figure.Position;
Position tmppos;
MyList<Position> l = new MyList<Position>();
switch (figure.GetFigureType())
{
case FigureTypes.Pawn:
{
if (figure.Side == Side.Black)
pos = figure.Reverse(pos);
if (pos.GetY() == 2)
{
Position middlepos = new Position(pos.GetX(), pos.GetY()+1);
middlepos = figure.Side == Side.White ? middlepos : figure.Reverse(middlepos);
if (cf.GetFigureAt(middlepos) == null)
{
tmppos = new Position(pos.GetX(), pos.GetY() + 2);
l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos));
}
}
int y = pos.GetY();
if (y+1 <9)
{
tmppos = new Position(pos.GetX(), y+1);
l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos) );
}
break;
}
case FigureTypes.King:
{
if (pos.GetY() >1)
l.Add(new Position(pos.GetX(), pos.GetY()-1));
if (pos.GetY() < 8)
l.Add(new Position(pos.GetX(), pos.GetY()+1));
break;
}
default: // Bishop, Queen & etc.
{
// +
for (int i = pos.GetY() + 1; i <= 8; i++)
{
l.Add(new Position(pos.GetX(), i));
if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null)
break;
}
//--
for (int i = pos.GetY() - 1; i > 0; i--)
{
l.Add(new Position(pos.GetX(), i));
if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null)
break;
}
break;
}
}
return l;
}
示例2: GetMoves
public MyList<Position> GetMoves(Figure figure, ChessField cf)
{
Position pos = figure.Position, tmppos;
MyList<Position> l = new MyList<Position>();
switch (figure.GetFigureType())
{
case FigureTypes.Pawn:
{
if (figure.Side == Side.Black)
pos = figure.Reverse(pos);
if (pos.GetY() < 8)
{
if (pos.GetX() < 8)
{
tmppos = new Position(pos.GetX()+1, pos.GetY()+1);
l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos));
}
if (pos.GetX() > 1)
{
tmppos = new Position(pos.GetX()- 1, pos.GetY() + 1);
l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos));
}
}
break;
}
case FigureTypes.King:
{
int x,y;
x = pos.GetX();
y = pos.GetY();
if (x<8)
{
if (y<8)
l.Add(new Position(x+1,y+1));
if (y>1)
l.Add(new Position(x+1,y-1));
}
if (x>1)
{
if (y<8)
l.Add(new Position(x-1,y+1));
if (y>1)
l.Add(new Position(x-1, y-1));
}
break;
}
default:
{
for (int i = pos.GetX()+1, j = pos.GetY()+1; i <= 8 && j <= 8; i++, j++)
{
l.Add(new Position(i, j));
if (cf.GetFigureAt(new Position(i, j)) != null)
break;
}
for (int i = pos.GetX() - 1, j = pos.GetY() - 1; i >=1 && j >=1 ; i--, j--)
{
l.Add(new Position(i, j));
if (cf.GetFigureAt(new Position(i, j)) != null)
break;
}
for (int i = pos.GetX() + 1, j = pos.GetY() - 1; i <= 8 && j >= 1; i++, j--)
{
l.Add(new Position(i, j));
if (cf.GetFigureAt(new Position(i, j)) != null)
break;
}
for (int i = pos.GetX() -1, j = pos.GetY() + 1; i >= 1 && j <= 8; i--, j++)
{
l.Add(new Position(i, j));
if (cf.GetFigureAt(new Position(i, j)) != null)
break;
}
break;
}
}
return l;
}