?? classes.cs
字號:
&& ((situation[toX,toY] == null)
|| ((situation[toX,toY] != null)
&&(situation[toX,toY].color != this.color))))
{
if (((Math.Abs(this.x-toX) == 1)
&&(Math.Abs(this.y-toY) == 2))
||((Math.Abs(this.x-toX) == 2)
&&(Math.Abs(this.y-toY) == 1)))
{
int i = -1;
int j = -1;
if (toX-this.x == 2)
{
i = this.x + 1;
j = this.y;
}
else if (this.x-toX == 2)
{
i = this.x - 1;
j = this.y;
}
else if (toY-this.y == 2)
{
i = this.x;
j = this.y + 1;
}
else if (this.y-toY == 2)
{
i = this.x;
j = this.y - 1;
}
if (situation[i,j] == null)
{
return true;
}
}
}
return false;
}
}
class Chariot:ChessMan
{
public Chariot(int color, int x, int y, int boardside) : base(color, CHARIOT, x, y, boardside) { }
public Chariot(int color,int number,int boardside):base(color, CHARIOT, number,boardside)
{
}
public bool isNormal(int posX,int posY)
{
return true;
}
public override bool canGo(int toX, int toY)
{
if (isNormal(toX, toY)
&& ((situation[toX, toY] == null)
|| ((situation[toX, toY] != null)
&& (situation[toX, toY].color != this.color))))
{
if ((this.x != toX) && (this.y != toY))
{
return false;
}
else
{
if (this.y == toY)
{
if (this.x < toX)
{
for (int x = this.x + 1; x < toX; x++)
{
if ((situation[x, this.y] != null)
&& (situation[x, this.y].color != GREY))
{
return false;
}
}
return true;
}
if (this.x > toX)
{
for (int x = this.x - 1; x > toX; x--)
{
if ((situation[x, this.y] != null)
&& (situation[x, this.y].color != GREY))
{
return false;
}
}
return true;
}
return false;
}
else
{
if (this.y < toY)
{
for (int y = this.y + 1; y < toY; y++)
{
if ((situation[this.x, y] != null)
&& (situation[this.x, y].color != GREY))
{
return false;
}
}
return true;
}
if (this.y > toY)
{
for (int y = this.y - 1; y > toY; y--)
{
if ((situation[this.x, y] != null)
&& (situation[this.x, y].color != GREY))
{
return false;
}
}
return true;
}
return false;
}
}
}
else
{
return false;
}
}
}
class Cannon:ChessMan
{
public Cannon(int color, int x, int y, int boardside) : base(color, CANNON, x, y, boardside) { }
public Cannon(int color,int number,int boardside):base(color, CANNON, number,boardside)
{
}
public bool isNormal(int posX,int posY)
{
return true;
}
public override bool canGo(int toX, int toY)
{
if (isNormal(toX, toY)
&& ((situation[toX,toY] == null)
|| ((situation[toX,toY] != null)
&&(situation[toX,toY].color != this.color))))
{
if ((this.x!=toX) && (this.y!=toY))
{
return false;
}
else
{
if (situation[toX,toY] == null)
{
if (this.y == toY)
{
if (this.x < toX)
{
for (int x=this.x+1; x<toX; x++)
{
if ((situation[x,this.y] != null)
&& (situation[x,this.y].color != GREY))
{
return false;
}
}
return true;
}
if (this.x > toX)
{
for (int x=this.x-1; x>toX; x--)
{
if ((situation[x,this.y] != null)
&& (situation[x,this.y].color != GREY))
{
return false;
}
}
return true;
}
}
else
{
if (this.y < toY)
{
for (int y=this.y+1; y<toY; y++)
{
if ((situation[this.x,y] != null)
&& (situation[this.x,y].color != GREY))
{
return false;
}
}
return true;
}
if (this.y > toY)
{
for (int y=this.y-1; y>toY; y--)
{
if ((situation[this.x,y] != null)
&& (situation[this.x,y].color != GREY))
{
return false;
}
}
return true;
}
}
}
else
{
int count = 0;
if (this.y == toY)
{
if (this.x < toX)
{
for (int x=this.x+1; x<toX; x++)
{
if ((situation[x,this.y] != null)
&& (situation[x,this.y].color != GREY))
{
count ++;
}
}
if (count == 1)
{
return true;
}
}
if (this.x > toX)
{
for (int x=this.x-1; x>toX; x--)
{
if ((situation[x,this.y] != null)
&& (situation[x,this.y].color != GREY))
{
count ++;
}
}
if (count == 1)
{
return true;
}
}
}
else
{
if (this.y < toY)
{
for (int y=this.y+1; y<toY; y++)
{
if ((situation[this.x,y] != null)
&& (situation[this.x,y].color != GREY))
{
count ++;
}
}
if (count == 1)
{
return true;
}
}
if (this.y > toY)
{
for (int y=this.y-1; y>toY; y--)
{
if ((situation[this.x,y] != null)
&& (situation[this.x,y].color != GREY))
{
count ++;
}
}
if (count == 1)
{
return true;
}
}
}
}
}
}
return false;
}
}
class Soldier:ChessMan
{
public Soldier(int color,int x, int y, int boardside): base(color, SOLDIER, x, y, boardside){}
public Soldier(int color,int number,int boardside):base(color, SOLDIER, number,boardside)
{
}
public bool isNormal(int posX,int posY)
{
if (this.color == BLACK)
{
if ((posY < 3)
|| ((posY < 5) && (posX % 2 == 1)))
{
return false;
}
}
if (this.color == RED)
{
if ((posY > 6)
|| ((posY > 4) && (posX % 2 == 1)))
{
return false;
}
}
return true;
}
public override bool canGo(int toX, int toY)
{
if (isNormal(toX, toY)
&& ((situation[toX,toY] == null)
|| ((situation[toX,toY] != null)
&&(situation[toX,toY].color != this.color))))
{
if (this.color == BLACK)
{
if (toY < this.y)
{
return false;
}
else
{
if (Math.Abs(toX-this.x) + toY-this.y != 1)
{
return false;
}
}
}
if (this.color == RED)
{
if (toY > this.y)
{
return false;
}
else
{
if (Math.Abs(toX-this.x) + this.y-toY != 1)
{
return false;
}
}
}
return true;
}
return false;
}
}
class Blank:ChessMan
{
public Blank(int x, int y, int boardside)
: base(GREY, BLANK, x, y, boardside)
{
}
public override bool canGo(int toX, int toY)
{
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -