Libs/DirectionCellMergeStrategy.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace VS2048
{
/// <summary>
/// 通过方向键来控制合并Cell的策略
/// </summary>
public class DirectionCellMergeStrategy : ICellMergeStrategy
{
CellStyleDictionary _csd = new CellStyleDictionary();
/// <summary>
/// 返回当前合并得分
/// </summary>
/// <param name="keyVal"></param>
/// <param name="celltable"></param>
/// <returns></returns>
public int Merge(int keyVal, ICell[,] celltable)
{
int score = 0;
switch (keyVal)
{
case 37:
AlignLeft(celltable);
score = MergeLeft(celltable);
AlignLeft(celltable);
break;
case 38:
AlignTop(celltable);
score = MergeTop(celltable);
AlignTop(celltable);
break;
case 39:
AlignRight(celltable);
score = MergeRight(celltable);
AlignRight(celltable);
break;
case 40:
AlignBottom(celltable);
score = MergeBottom(celltable);
AlignBottom(celltable);
break;
}
return score;
}
//<-
private int MergeLeft(ICell[,] celltable)
{
int score = 0;
if (celltable != null)
{
for (int i = 0; i < celltable.GetLength(0); i++)
{
for (int j = 0; j < celltable.GetLength(1) - 1; j++)
{
if ((celltable[i, j] == null) || (celltable[i, j + 1] == null)) continue;
if (celltable[i, j].DisplayNum == celltable[i, j + 1].DisplayNum)
{
int num = int.Parse(celltable[i, j].DisplayNum) * 2;
celltable[i, j].DisplayNum = num.ToString();
celltable[i, j].BackColor = _csd[num].BackColor;
celltable[i, j].TextColor = _csd[num].TextColor;
后面还有 211 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
