소스 검색

小游戏优化提交

zhangyuqian 1 년 전
부모
커밋
9e1d63594c

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Views/MiniGame/Card.cs

@@ -38,8 +38,8 @@ public class Card : GButton
 
     public void Turn()
     {
-        if (GTween.IsTweening(this))
-            return;
+        //if (GTween.IsTweening(this))
+        //    return;
 
         bool toOpen = !_front.visible;
         GTween.To(0, 180, 0.5f).SetTarget(this).SetEase(EaseType.QuadOut).OnUpdate(TurnInTween).SetUserData(toOpen);

+ 100 - 76
GameClient/Assets/Game/HotUpdate/Views/MiniGame/FlipGameView.cs

@@ -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  };
 
-        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()
         {
@@ -100,9 +103,9 @@ namespace GFGGame
             base.OnHide();
             cardList.Clear();
             Timers.inst.Remove(UpdateTime);
-            Timers.inst.Remove(canTouch);
-            Timers.inst.Remove(UpdateCard);
             Timers.inst.Remove(UpdateBar);
+            Timers.inst.Remove(UpdateHit);
+            Timers.inst.Remove(StartTime);
         }
 
         private void OnClickBtnBack()
@@ -143,7 +146,7 @@ namespace GFGGame
             {
                 cardItem.target.onClick.Add(OnClickCardItem);
             }
-            _c1 = (Card)cardItem.m_card;
+            Card _c1 = (Card)cardItem.m_card;
             _c1.opened = false;
             _c1.SetPerspective();
 
@@ -172,6 +175,8 @@ namespace GFGGame
                         break;
                 }
             }
+            StartHit = true;
+            firstHit = true;
             timeIndex = 0;
             currentGameTime = gameTime;
             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_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_cardList.touchable = true;
             //计时器
             Timers.inst.Add(1.0f, 0, UpdateTime);
             //进度条计时器
@@ -208,98 +214,121 @@ namespace GFGGame
             GObject cardItem = context.sender as GObject;
             Dictionary<string, int> cardInfo = (Dictionary<string, int>)cardItem.data;
             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();
-                        _ui.m_cardList.touchable = false;
-                        Timers.inst.Add(waitTime, 1, canTouch);
-                        //
-                        cardList.RemoveAt(i);
-                        isLast = true;
+                        //.
+                        cardList.Remove(cardInfo);
+                        
                         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();
         }
-
+        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++)
             {
-                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.Turn();
-                    //card = null;
+                    cardList[i - 1]["state"] = 0;
                     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)
         {
@@ -318,11 +347,6 @@ namespace GFGGame
             _ui.m_ScareBar.value = barTime;
         }
 
-        private void canTouch(object param = null)
-        {
-            _ui.m_cardList.touchable = true;
-        }
-
         private void Gameover(bool isPass = false)
         {
             Timers.inst.Remove(UpdateTime);

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Views/MiniGame/GameStartView.cs

@@ -91,6 +91,8 @@ namespace GFGGame
             _ui.m_needNum2.text = NumTicketTwo.ToString();
             _ui.m_needIcon1.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(3000017).res);
             _ui.m_needIcon2.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(3000017).res);
+            _ui.m_needNum2.visible = false;
+            _ui.m_needIcon2.visible = false;
             _ui.m_tipsOne.data = 300026;
             _ui.m_tipsTwo.data = 300027;
             ItemData item;