|
@@ -52,8 +52,11 @@ namespace GFGGame
|
|
//假数据
|
|
//假数据
|
|
private List<int> cardArray = new List<int> { 1,1, 2,2, 3, 3 , 4, 4 , 5, 5 , 6, 6 , 8, 8 , 8, 8 };
|
|
private List<int> cardArray = new List<int> { 1,1, 2,2, 3, 3 , 4, 4 , 5, 5 , 6, 6 , 8, 8 , 8, 8 };
|
|
|
|
|
|
- Card _c1 = new Card();
|
|
|
|
- private float waitTime = 0.6f;
|
|
|
|
|
|
+ //Card _c1 = new Card();
|
|
|
|
+ //从第一次点击开始超过一秒后禁止点击,然后对翻开列表进行处理并重置,
|
|
|
|
+ private float waitTime = 0.0f;
|
|
|
|
+ private bool StartHit = true;
|
|
|
|
+ private bool firstHit = true;
|
|
|
|
|
|
public override void Dispose()
|
|
public override void Dispose()
|
|
{
|
|
{
|
|
@@ -100,9 +103,9 @@ namespace GFGGame
|
|
base.OnHide();
|
|
base.OnHide();
|
|
cardList.Clear();
|
|
cardList.Clear();
|
|
Timers.inst.Remove(UpdateTime);
|
|
Timers.inst.Remove(UpdateTime);
|
|
- Timers.inst.Remove(canTouch);
|
|
|
|
- Timers.inst.Remove(UpdateCard);
|
|
|
|
Timers.inst.Remove(UpdateBar);
|
|
Timers.inst.Remove(UpdateBar);
|
|
|
|
+ Timers.inst.Remove(UpdateHit);
|
|
|
|
+ Timers.inst.Remove(StartTime);
|
|
}
|
|
}
|
|
|
|
|
|
private void OnClickBtnBack()
|
|
private void OnClickBtnBack()
|
|
@@ -143,7 +146,7 @@ namespace GFGGame
|
|
{
|
|
{
|
|
cardItem.target.onClick.Add(OnClickCardItem);
|
|
cardItem.target.onClick.Add(OnClickCardItem);
|
|
}
|
|
}
|
|
- _c1 = (Card)cardItem.m_card;
|
|
|
|
|
|
+ Card _c1 = (Card)cardItem.m_card;
|
|
_c1.opened = false;
|
|
_c1.opened = false;
|
|
_c1.SetPerspective();
|
|
_c1.SetPerspective();
|
|
|
|
|
|
@@ -172,6 +175,8 @@ namespace GFGGame
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ StartHit = true;
|
|
|
|
+ firstHit = true;
|
|
timeIndex = 0;
|
|
timeIndex = 0;
|
|
currentGameTime = gameTime;
|
|
currentGameTime = gameTime;
|
|
cardNum = columns * rows;
|
|
cardNum = columns * rows;
|
|
@@ -191,7 +196,8 @@ namespace GFGGame
|
|
_ui.m_star1.SetPosition(((float)(gameTime - CustemsNum[0])/(float)gameTime) * _ui.m_ScareBar.width + 70,_ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
_ui.m_star1.SetPosition(((float)(gameTime - CustemsNum[0])/(float)gameTime) * _ui.m_ScareBar.width + 70,_ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
_ui.m_star2.SetPosition(((float)(gameTime - CustemsNum[1]) / (float)gameTime) * _ui.m_ScareBar.width, _ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
_ui.m_star2.SetPosition(((float)(gameTime - CustemsNum[1]) / (float)gameTime) * _ui.m_ScareBar.width, _ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
_ui.m_star3.SetPosition(((float)(gameTime - CustemsNum[2]) / (float)gameTime) * _ui.m_ScareBar.width, _ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
_ui.m_star3.SetPosition(((float)(gameTime - CustemsNum[2]) / (float)gameTime) * _ui.m_ScareBar.width, _ui.m_star1.position.y, _ui.m_star1.position.z);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ _ui.m_cardList.touchable = true;
|
|
//计时器
|
|
//计时器
|
|
Timers.inst.Add(1.0f, 0, UpdateTime);
|
|
Timers.inst.Add(1.0f, 0, UpdateTime);
|
|
//进度条计时器
|
|
//进度条计时器
|
|
@@ -208,98 +214,121 @@ namespace GFGGame
|
|
GObject cardItem = context.sender as GObject;
|
|
GObject cardItem = context.sender as GObject;
|
|
Dictionary<string, int> cardInfo = (Dictionary<string, int>)cardItem.data;
|
|
Dictionary<string, int> cardInfo = (Dictionary<string, int>)cardItem.data;
|
|
UI_cardItem item = UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardInfo["index"]));
|
|
UI_cardItem item = UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardInfo["index"]));
|
|
- Card card = (Card)item.m_card;
|
|
|
|
- if (cardList.Count == 0)
|
|
|
|
|
|
+
|
|
|
|
+ if(StartHit)
|
|
{
|
|
{
|
|
- //当前翻开列表为空,直接处理翻开,添加
|
|
|
|
- cardInfo["state"] = 1;
|
|
|
|
- //翻牌
|
|
|
|
- card.Turn();
|
|
|
|
- _ui.m_cardList.touchable = false;
|
|
|
|
- Timers.inst.Add(waitTime, 1, canTouch);
|
|
|
|
- //
|
|
|
|
- cardList.Add(cardInfo);
|
|
|
|
|
|
+ StartHit = false;
|
|
|
|
+ Timers.inst.Add(1.0f, 1, StartTime);
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ Card card = (Card)item.m_card;
|
|
|
|
+ bool isSame = false;
|
|
|
|
+ for (int i = 0; i < cardList.Count; i++)
|
|
{
|
|
{
|
|
- bool isLast = false;
|
|
|
|
- for (int i = 0; i < cardList.Count; i++)
|
|
|
|
- {
|
|
|
|
- //点击到已翻开的就翻回去,
|
|
|
|
- if (cardInfo["index"] == cardList[i]["index"])
|
|
|
|
- {
|
|
|
|
|
|
+ if (cardInfo["index"] == cardList[i]["index"] && firstHit)
|
|
|
|
+ {
|
|
|
|
+ cardInfo["state"] = 0;
|
|
//翻牌
|
|
//翻牌
|
|
card.Turn();
|
|
card.Turn();
|
|
- _ui.m_cardList.touchable = false;
|
|
|
|
- Timers.inst.Add(waitTime, 1, canTouch);
|
|
|
|
- //
|
|
|
|
- cardList.RemoveAt(i);
|
|
|
|
- isLast = true;
|
|
|
|
|
|
+ //.
|
|
|
|
+ cardList.Remove(cardInfo);
|
|
|
|
+
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!isLast)
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- //翻牌
|
|
|
|
- card.Turn();
|
|
|
|
- _ui.m_cardList.touchable = false;
|
|
|
|
- cardInfo["state"] = 1;
|
|
|
|
- cardList.Add(cardInfo);
|
|
|
|
- Timers.inst.Add(waitTime, 1, UpdateCard);
|
|
|
|
-
|
|
|
|
|
|
+ if (cardInfo["index"] == cardList[i]["index"])
|
|
|
|
+ {
|
|
|
|
+ isSame = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ firstHit = false;
|
|
|
|
+ //翻牌
|
|
|
|
+ if (!isSame)
|
|
|
|
+ {
|
|
|
|
+ cardInfo["state"] = 1;
|
|
|
|
+ card.Turn();
|
|
|
|
+ cardList.Add(cardInfo);
|
|
|
|
+ }
|
|
UI_cardItem.ProxyEnd();
|
|
UI_cardItem.ProxyEnd();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ private void StartTime(object param = null)
|
|
|
|
+ {
|
|
|
|
+ Timers.inst.Remove(StartTime);
|
|
|
|
+ _ui.m_cardList.touchable = false;
|
|
|
|
+ UpdateCard();
|
|
|
|
+ }
|
|
//这里是处理已翻开的数量
|
|
//这里是处理已翻开的数量
|
|
- private void UpdateCard(object param = null)
|
|
|
|
|
|
+ private void UpdateCard()
|
|
{
|
|
{
|
|
- bool isClear = true;
|
|
|
|
|
|
+ List<Dictionary<string, int>> removeList = new List<Dictionary<string, int>>();
|
|
for (int i = 1; i < cardList.Count; i++)
|
|
for (int i = 1; i < cardList.Count; i++)
|
|
{
|
|
{
|
|
- if(cardList[0]["id"] != cardList[i]["id"])
|
|
|
|
|
|
+ if(cardList[i]["id"] == cardList[i-1]["id"])
|
|
{
|
|
{
|
|
- isClear = false;
|
|
|
|
- break;
|
|
|
|
|
|
+ cardList[i]["state"] = 2;
|
|
|
|
+ //消除
|
|
|
|
+ _ui.m_cardList.GetChildAt(cardList[i]["index"]).visible = false;
|
|
|
|
+ _ui.m_cardList.GetChildAt(cardList[i - 1]["index"]).visible = false;
|
|
|
|
+ currentCardNum -= 2;
|
|
|
|
+ removeList.Add(cardList[i-1]);
|
|
|
|
+ removeList.Add(cardList[i]);
|
|
}
|
|
}
|
|
- isClear = true;
|
|
|
|
}
|
|
}
|
|
- if(isClear)
|
|
|
|
|
|
+ if(currentCardNum <= 0)
|
|
{
|
|
{
|
|
- if (cardList.Count == needNum)
|
|
|
|
- {
|
|
|
|
- for (int i = 0; i < cardList.Count; i++)
|
|
|
|
- {
|
|
|
|
- cardList[i]["state"] = 2;
|
|
|
|
- //消除
|
|
|
|
- _ui.m_cardList.GetChildAt(cardList[i]["index"]).visible = false;
|
|
|
|
- }
|
|
|
|
- currentCardNum -= cardList.Count;
|
|
|
|
- cardList.Clear();
|
|
|
|
- if(currentCardNum <= 0)
|
|
|
|
- {
|
|
|
|
- Gameover(true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- _ui.m_cardList.touchable = true;
|
|
|
|
|
|
+ Gameover(true);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //先处理消除的列表
|
|
|
|
+ for(int i = 0;i<removeList.Count;i++)
|
|
|
|
+ {
|
|
|
|
+ cardList.Remove(removeList[i]);
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ removeList.Clear();
|
|
|
|
+ //后处理翻牌的列表
|
|
|
|
+ for (int i = 1; i < cardList.Count; i++)
|
|
{
|
|
{
|
|
- _ui.m_cardList.touchable = false;
|
|
|
|
- //= UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardList[0]["index"]));
|
|
|
|
- for (int i = 0; i < cardList.Count; i++)
|
|
|
|
- {
|
|
|
|
- UI_cardItem item = UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardList[i]["index"]));
|
|
|
|
|
|
+
|
|
|
|
+ UI_cardItem item = UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardList[i - 1]["index"]));
|
|
//翻回去
|
|
//翻回去
|
|
Card card = (Card)item.m_card;
|
|
Card card = (Card)item.m_card;
|
|
card.Turn();
|
|
card.Turn();
|
|
- //card = null;
|
|
|
|
|
|
+ cardList[i - 1]["state"] = 0;
|
|
UI_cardItem.ProxyEnd();
|
|
UI_cardItem.ProxyEnd();
|
|
|
|
+ if (cardList.Count % 2 == 0 && i == cardList.Count - 1)
|
|
|
|
+ {
|
|
|
|
+ UI_cardItem carditem = UI_cardItem.Proxy(_ui.m_cardList.GetChildAt(cardList[i]["index"]));
|
|
|
|
+ //翻回去
|
|
|
|
+ Card cardLast = (Card)carditem.m_card;
|
|
|
|
+ cardLast.Turn();
|
|
|
|
+ cardList[i]["state"] = 0;
|
|
|
|
+ UI_cardItem.ProxyEnd();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (cardList.Count % 2 == 0)
|
|
|
|
+ {
|
|
|
|
+ cardList.Clear();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ int j = cardList.Count;
|
|
|
|
+ for(int i = 0;i < j-1;i++)
|
|
|
|
+ {
|
|
|
|
+ cardList.RemoveAt(0);
|
|
}
|
|
}
|
|
- Timers.inst.Add(waitTime, 1, canTouch);
|
|
|
|
- cardList.Clear();
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Timers.inst.Add(0.5f, 1, UpdateHit);
|
|
|
|
+ }
|
|
|
|
+ private void UpdateHit(object param = null)
|
|
|
|
+ {
|
|
|
|
+ Timers.inst.Remove(UpdateHit);
|
|
|
|
+ StartHit = true;
|
|
|
|
+ firstHit = true;
|
|
|
|
+ _ui.m_cardList.touchable = true;
|
|
}
|
|
}
|
|
private void UpdateTime(object param = null)
|
|
private void UpdateTime(object param = null)
|
|
{
|
|
{
|
|
@@ -318,11 +347,6 @@ namespace GFGGame
|
|
_ui.m_ScareBar.value = barTime;
|
|
_ui.m_ScareBar.value = barTime;
|
|
}
|
|
}
|
|
|
|
|
|
- private void canTouch(object param = null)
|
|
|
|
- {
|
|
|
|
- _ui.m_cardList.touchable = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void Gameover(bool isPass = false)
|
|
private void Gameover(bool isPass = false)
|
|
{
|
|
{
|
|
Timers.inst.Remove(UpdateTime);
|
|
Timers.inst.Remove(UpdateTime);
|