|
@@ -12,7 +12,7 @@ namespace GFGGame
|
|
|
private UI_TZFEGameView _ui;
|
|
|
|
|
|
private int[,] Map;
|
|
|
- enum Direction { up, down, left, right };
|
|
|
+ enum Direction { up, down, left, right};
|
|
|
private Vector2 touchFirst = Vector2.zero;//手指开始按下的位置
|
|
|
private Vector2 touchSecond = Vector2.zero;//手指拖动的位置
|
|
|
private System.Random rand;
|
|
@@ -33,8 +33,10 @@ namespace GFGGame
|
|
|
public int y;
|
|
|
public bool isCreat;
|
|
|
}
|
|
|
+ //需要播放动效的列表
|
|
|
private List<NumPos> numPosArray = new List<NumPos>();
|
|
|
|
|
|
+
|
|
|
public override void Dispose()
|
|
|
{
|
|
|
if (_ui != null)
|
|
@@ -107,8 +109,35 @@ namespace GFGGame
|
|
|
int x = index / rows;
|
|
|
int y = index % columns;
|
|
|
numItem.m_numTxt.text = Map[x,y].ToString();
|
|
|
+ if(Map[x,y] == 0)
|
|
|
+ {
|
|
|
+ numItem.m_numTxt.visible = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ numItem.m_numTxt.visible = true;
|
|
|
+ }
|
|
|
//这个后续根据数组内容替换图片
|
|
|
//_ui.m_icon.url =
|
|
|
+ //播放生成和合并动效
|
|
|
+ for(int i=0; i<numPosArray.Count; i++)
|
|
|
+ {
|
|
|
+ if(x == numPosArray[i].x && y == numPosArray[i].y)
|
|
|
+ {
|
|
|
+ if(numPosArray[i].isCreat)
|
|
|
+ {
|
|
|
+ numItem.m_t0.Play();
|
|
|
+ numPosArray.RemoveAt(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ numItem.m_t1.Play();
|
|
|
+ numPosArray.RemoveAt(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
UI_numItem.ProxyEnd();
|
|
|
}
|
|
|
|
|
@@ -162,7 +191,7 @@ namespace GFGGame
|
|
|
/// 去零
|
|
|
/// </summary>
|
|
|
/// <param name="row">对于一行或一列元素</param>
|
|
|
- private void Remove0(int[] row)
|
|
|
+ private void Remove0(int[] row,Direction dir,int xy = 0)
|
|
|
{
|
|
|
int pos = 0;
|
|
|
int[] rowB = new int[row.Length];
|
|
@@ -175,7 +204,54 @@ namespace GFGGame
|
|
|
if (row[i] != 0)
|
|
|
{
|
|
|
row[pos] = row[i];
|
|
|
+
|
|
|
+ //-----这里修改需要播放动效的列表-----
|
|
|
+ int x = 0;
|
|
|
+ int y = 0;
|
|
|
+ int nextX = 0;
|
|
|
+ int nextY = 0;
|
|
|
+ for (int t = 0; t < numPosArray.Count; t++)
|
|
|
+ {
|
|
|
+ switch (dir)
|
|
|
+ {
|
|
|
+ case Direction.up:
|
|
|
+ x = i;
|
|
|
+ y = xy;
|
|
|
+ nextX = pos;
|
|
|
+ nextY = xy;
|
|
|
+ break;
|
|
|
+ case Direction.down:
|
|
|
+ x = row.Length - 1 - i;
|
|
|
+ y = xy;
|
|
|
+ nextX = row.Length - 1 - pos;
|
|
|
+ nextY = xy;
|
|
|
+ break;
|
|
|
+ case Direction.left:
|
|
|
+ x = xy;
|
|
|
+ y = i;
|
|
|
+ nextX = xy;
|
|
|
+ nextY = pos;
|
|
|
+ break;
|
|
|
+ case Direction.right:
|
|
|
+ x = xy;
|
|
|
+ y = row.Length - 1 - i;
|
|
|
+ nextX = xy;
|
|
|
+ nextY = row.Length - 1 - pos;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(numPosArray.Count != 0 && numPosArray[t].x == x && numPosArray[t].y == y && pos != i)
|
|
|
+ {
|
|
|
+ numPosArray.RemoveAt(t);
|
|
|
+ NumPos item;
|
|
|
+ item.x = nextX;
|
|
|
+ item.y = nextY;
|
|
|
+ item.isCreat = false;
|
|
|
+ numPosArray.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //---------------------------------------
|
|
|
pos++;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
for (; pos < row.Length; ++pos) row[pos] = 0;
|
|
@@ -192,9 +268,9 @@ namespace GFGGame
|
|
|
/// 合并
|
|
|
/// </summary>
|
|
|
/// <param name="row">对于一行或一列元素,完成一次向左合并的操作</param>
|
|
|
- private void Merge(int[] row , int colrow = 0)
|
|
|
+ private void Merge(int[] row , Direction dir, int xy)
|
|
|
{
|
|
|
- Remove0(row);
|
|
|
+ Remove0(row,dir,xy);
|
|
|
// 相邻相同则合并
|
|
|
for (int i = 0; i < row.Length - 1; ++i)
|
|
|
{
|
|
@@ -202,6 +278,11 @@ namespace GFGGame
|
|
|
{
|
|
|
row[i] *= 2;
|
|
|
row[i + 1] = 0;
|
|
|
+ //将合并的数字放入列表
|
|
|
+ NumPos item;
|
|
|
+ item = MoveAddNum(i, xy, dir, row.Length-1);
|
|
|
+ numPosArray.Add(item);
|
|
|
+ //-------
|
|
|
score += row[i];
|
|
|
UpdateScore();
|
|
|
if (row[i] == targetNum)
|
|
@@ -211,9 +292,37 @@ namespace GFGGame
|
|
|
isMerge = true;
|
|
|
}
|
|
|
}
|
|
|
- Remove0(row);
|
|
|
+ Remove0(row,dir,xy);
|
|
|
+ }
|
|
|
+ //将合并的数字放入列表的准备
|
|
|
+ private NumPos MoveAddNum(int i, int xy, Direction dir,int length)
|
|
|
+ {
|
|
|
+ NumPos item = new NumPos();
|
|
|
+ switch (dir)
|
|
|
+ {
|
|
|
+ case Direction.up:
|
|
|
+ item.x = i;
|
|
|
+ item.y = xy;
|
|
|
+ item.isCreat = false;
|
|
|
+ break;
|
|
|
+ case Direction.down:
|
|
|
+ item.x = length - i;
|
|
|
+ item.y = xy;
|
|
|
+ item.isCreat = false;
|
|
|
+ break;
|
|
|
+ case Direction.left:
|
|
|
+ item.x = xy;
|
|
|
+ item.y = i;
|
|
|
+ item.isCreat = false;
|
|
|
+ break;
|
|
|
+ case Direction.right:
|
|
|
+ item.x = xy;
|
|
|
+ item.y = length - i;
|
|
|
+ item.isCreat = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return item;
|
|
|
}
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 上移
|
|
|
/// </summary>
|
|
@@ -224,8 +333,11 @@ namespace GFGGame
|
|
|
int[] arr = new int[rows];
|
|
|
for (int j = 0; j < columns; ++j)
|
|
|
{
|
|
|
- for (int i = 0; i < rows; ++i) arr[i] = map[i, j];
|
|
|
- Merge(arr);
|
|
|
+ for (int i = 0; i < rows; ++i)
|
|
|
+ {
|
|
|
+ arr[i] = map[i, j];
|
|
|
+ }
|
|
|
+ Merge(arr,Direction.up,j);
|
|
|
for (int i = 0; i < rows; ++i) map[i, j] = arr[i];
|
|
|
}
|
|
|
}
|
|
@@ -237,8 +349,11 @@ namespace GFGGame
|
|
|
int[] arr = new int[rows];
|
|
|
for (int j = 0; j < columns; ++j)
|
|
|
{
|
|
|
- for (int i = 0; i < rows; ++i) arr[rows - 1 - i] = map[i, j];
|
|
|
- Merge(arr);
|
|
|
+ for (int i = 0; i < rows; ++i)
|
|
|
+ {
|
|
|
+ arr[rows - 1 - i] = map[i, j];
|
|
|
+ }
|
|
|
+ Merge(arr,Direction.down ,j);
|
|
|
for (int i = 0; i < rows; ++i) map[i, j] = arr[rows - 1 - i];
|
|
|
}
|
|
|
return map;
|
|
@@ -252,13 +367,15 @@ namespace GFGGame
|
|
|
int[] arr = new int[columns];
|
|
|
for (int i = 0; i < rows; ++i)
|
|
|
{
|
|
|
- for (int j = 0; j < columns; ++j) arr[j] = map[i, j];
|
|
|
- Merge(arr);
|
|
|
+ for (int j = 0; j < columns; ++j)
|
|
|
+ {
|
|
|
+ arr[j] = map[i, j];
|
|
|
+ }
|
|
|
+ Merge(arr,Direction.left,i);
|
|
|
for (int j = 0; j < columns; ++j) map[i, j] = arr[j];
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 右移
|
|
|
/// </summary>
|
|
@@ -267,8 +384,11 @@ namespace GFGGame
|
|
|
int[] arr = new int[columns];
|
|
|
for (int i = 0; i < rows; ++i)
|
|
|
{
|
|
|
- for (int j = 0; j < columns; ++j) arr[columns - 1 - j] = map[i, j];
|
|
|
- Merge(arr);
|
|
|
+ for (int j = 0; j < columns; ++j)
|
|
|
+ {
|
|
|
+ arr[columns - 1 - j] = map[i, j];
|
|
|
+ }
|
|
|
+ Merge(arr,Direction.right,i);
|
|
|
for (int j = 0; j < columns; ++j) map[i, j] = arr[columns - 1 - j];
|
|
|
}
|
|
|
return map;
|