我正在使用Unity制作2D国际象棋游戏。
我正在编写代码,告诉该作品是否可以移动到此位置。
以下是关于我是如何做到的解释:
对于典当,没有问题,它运作得很好,但是对于车或骑士来说,这种情况更加复杂,我也有这样的问题。
在这里,我将与骑士合作。
当它位于电路板的中心时,没问题:http://prntscr.com/crcogo
但是当我在董事会的一方时,请自行检查:http://prntscr.com/crcozu
以下是代码:
case "White_Knight(Clone)_0":
int Index_Knight_1 = Array.IndexOf(Board, Square_Selected);
// Les cases en +
if (Index_Knight_1 + 6 <= 64 )
{
Board[Index_Knight_1 + 6].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 + 10 <= 64)
{
Board[Index_Knight_1 + 10].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 + 15 <= 64)
{
Board[Index_Knight_1 + 15].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 + 17 <= 64)
{
Board[Index_Knight_1 + 17].GetComponent<MeshRenderer>().enabled = true;
}
// les cases en -
if (Index_Knight_1 - 6 >= 0)
{
Board[Index_Knight_1 - 6].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 - 10 >= 0)
{
Board[Index_Knight_1 - 10].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 - 15 >= 0)
{
Board[Index_Knight_1 - 15].GetComponent<MeshRenderer>().enabled = true;
}
if (Index_Knight_1 - 17 >= 0)
{
Board[Index_Knight_1 - 17].GetComponent<MeshRenderer>().enabled = true;
}
我thnik我没有使用正确的方法来做这件事,但我想自己编写脚本而不需要在那里或那里取代码。
在这种情况下,我考虑过使用8的倍数,但是我被困在这里:D
有人可以给我一条建议吗?
谢谢!
何,我知道它不应该是&#34; 64&#34;在条件,但63,只是看到它。
答案 0 :(得分:0)
我同意Absinte - 我正在开发一款使用7x7主板的类似游戏。使用2维数组更容易。当我的一件作品被选中时,我会循环查看它可以制作的动作列表 - 这些是+/-偏移,假设该作品位于中心。对于一个棋子,x,y偏移将是: 0,+ 1; 0,+ 2(仅限第一次移动),+ 1,+ 1,-1,+ 1(最后两个是捕获时)。
我将这些中的每一个应用到片段的当前x,y位置,如果x和y都在0和6之内,那么我将把它显示为片段可以移动的可能位置。