|
@@ -18,13 +18,14 @@ namespace GFGGame
|
|
|
private System.Random rand;
|
|
|
|
|
|
//这个是数组的行数和列数,mapLength一般采用行列一样
|
|
|
- private int rows = 5;
|
|
|
- private int columns = 5;
|
|
|
+ private int rows = 4;
|
|
|
+ private int columns = 4;
|
|
|
private int mapLength = 5;
|
|
|
//得分
|
|
|
private int score = 0;
|
|
|
private int scoreMax = 0;
|
|
|
- private int targetNum = 2048;
|
|
|
+ //目标分数
|
|
|
+ private int targetNum = 128;
|
|
|
private bool isMove;
|
|
|
private bool isMerge;
|
|
|
private struct NumPos
|
|
@@ -35,7 +36,7 @@ namespace GFGGame
|
|
|
}
|
|
|
//需要播放动效的列表
|
|
|
private List<NumPos> numPosArray = new List<NumPos>();
|
|
|
-
|
|
|
+ private int time = 0;
|
|
|
|
|
|
public override void Dispose()
|
|
|
{
|
|
@@ -58,6 +59,7 @@ namespace GFGGame
|
|
|
_ui.target.onTouchBegin.Add(OnClickBegin);
|
|
|
_ui.target.onTouchEnd.Add(OnClickEnd);
|
|
|
_ui.m_backBtn.onClick.Add(OnClickBtnBack);
|
|
|
+ _ui.m_mergeBtn.onClick.Add(OnClickMergeTips);
|
|
|
Map = new int[rows, columns];
|
|
|
}
|
|
|
|
|
@@ -70,6 +72,7 @@ namespace GFGGame
|
|
|
}
|
|
|
protected override void OnHide()
|
|
|
{
|
|
|
+ Timers.inst.Remove(UpdateTime);
|
|
|
base.OnHide();
|
|
|
}
|
|
|
|
|
@@ -88,10 +91,13 @@ namespace GFGGame
|
|
|
}
|
|
|
private void UpdateView()
|
|
|
{
|
|
|
+ time = 0;
|
|
|
score = 0;
|
|
|
- targetNum = 2048;
|
|
|
+ targetNum = 64;
|
|
|
_ui.m_score.text = string.Format("分数:{0}", score.ToString());
|
|
|
+ _ui.m_score.visible = false;
|
|
|
rand = new System.Random();
|
|
|
+ Timers.inst.Add(1.0f, 0, UpdateTime);
|
|
|
}
|
|
|
private void UpdateScore()
|
|
|
{
|
|
@@ -108,17 +114,15 @@ namespace GFGGame
|
|
|
UI_numItem numItem = UI_numItem.Proxy(item);
|
|
|
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;
|
|
|
+ numItem.m_icon.visible = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- numItem.m_numTxt.visible = true;
|
|
|
+ numItem.m_icon.url = string.Format("ui://MiniGame/sgll2_{0}", Map[x, y]);
|
|
|
+ numItem.m_icon.visible = true;
|
|
|
}
|
|
|
- //这个后续根据数组内容替换图片
|
|
|
- //_ui.m_icon.url =
|
|
|
//播放生成和合并动效
|
|
|
for(int i=0; i<numPosArray.Count; i++)
|
|
|
{
|
|
@@ -158,7 +162,9 @@ namespace GFGGame
|
|
|
}
|
|
|
if(!gameOver)
|
|
|
{
|
|
|
- // 还需要加,无法移动,无法合并时,游戏结束
|
|
|
+ // 游戏结束
|
|
|
+ GameOver(false);
|
|
|
+ return;
|
|
|
}
|
|
|
while (true)
|
|
|
{
|
|
@@ -205,7 +211,7 @@ namespace GFGGame
|
|
|
{
|
|
|
row[pos] = row[i];
|
|
|
|
|
|
- //-----这里修改需要播放动效的列表-----
|
|
|
+ //-----这里修改需要播放动效的数字位置列表-----
|
|
|
int x = 0;
|
|
|
int y = 0;
|
|
|
int nextX = 0;
|
|
@@ -287,14 +293,15 @@ namespace GFGGame
|
|
|
UpdateScore();
|
|
|
if (row[i] == targetNum)
|
|
|
{
|
|
|
- //游戏结束
|
|
|
+ //游戏成功
|
|
|
+ GameOver(true);
|
|
|
}
|
|
|
isMerge = true;
|
|
|
}
|
|
|
}
|
|
|
Remove0(row,dir,xy);
|
|
|
}
|
|
|
- //将合并的数字放入列表的准备
|
|
|
+ //将合并的数字位置放入列表的准备
|
|
|
private NumPos MoveAddNum(int i, int xy, Direction dir,int length)
|
|
|
{
|
|
|
NumPos item = new NumPos();
|
|
@@ -418,6 +425,7 @@ namespace GFGGame
|
|
|
UpdateList();
|
|
|
numPosArray.Clear();
|
|
|
}
|
|
|
+ CheckArray();
|
|
|
}
|
|
|
|
|
|
private void OnClickBegin()
|
|
@@ -450,5 +458,84 @@ namespace GFGGame
|
|
|
touchFirst = touchSecond;
|
|
|
}
|
|
|
|
|
|
+ private void OnClickMergeTips()
|
|
|
+ {
|
|
|
+ ViewManager.Show<SyntheticRoutetipView>() ;
|
|
|
+ }
|
|
|
+ private void UpdateTime(object param = null)
|
|
|
+ {
|
|
|
+ _ui.m_timeNum.text = sec_to_hms(time);
|
|
|
+ time++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将秒数转化为时分秒 duration为秒数
|
|
|
+ private string sec_to_hms(int duration)
|
|
|
+ {
|
|
|
+ TimeSpan ts = new TimeSpan(0, 0, duration);
|
|
|
+ int _hours = 0;
|
|
|
+ if (ts.Days > 0)
|
|
|
+ {
|
|
|
+ _hours = ts.Days * 24;
|
|
|
+ }
|
|
|
+ string str = "";
|
|
|
+ if (ts.Hours > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ str = String.Format("{0:00}", ts.Hours + _hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
|
|
|
+ }
|
|
|
+ if (ts.Hours == 0 && ts.Minutes > 0)
|
|
|
+ {
|
|
|
+ str = "00:";
|
|
|
+ if (_hours > 0)
|
|
|
+ {
|
|
|
+ str = String.Format("{0:00}", ts.Hours + _hours) + ":";
|
|
|
+ }
|
|
|
+ str += String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
|
|
|
+ }
|
|
|
+ if (ts.Hours == 0 && ts.Minutes == 0)
|
|
|
+ {
|
|
|
+ str = "00";
|
|
|
+ if (_hours > 0)
|
|
|
+ {
|
|
|
+ str = String.Format("{0:00}", ts.Hours + _hours);
|
|
|
+ }
|
|
|
+ str += ":00:" + String.Format("{0:00}", ts.Seconds);
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ private void CheckArray()
|
|
|
+ {
|
|
|
+ bool gameOver = false;
|
|
|
+ for (int i = 0; i < rows; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < columns; j++)
|
|
|
+ {
|
|
|
+ if (Map[i, j] == 0)
|
|
|
+ {
|
|
|
+ gameOver = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!gameOver)
|
|
|
+ {
|
|
|
+ // 游戏结束
|
|
|
+ GameOver(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GameOver(bool target)
|
|
|
+ {
|
|
|
+ Timers.inst.Remove(UpdateTime);
|
|
|
+ if (target)
|
|
|
+ {
|
|
|
+ ViewManager.Show<ResultTipsView>(new object[]{target, typeof(TZFEGameView).FullName, time });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ViewManager.Show<ResultTipsView>(new object[]{target,typeof(TZFEGameView).FullName });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|