Пример #1
0
        public WinController(MissionConstruct mc, GameBoard gB, BubblesShooter bubblesShooter, Action LevelWin, Action LevelLoose, Action CheckTargetResult, TextMesh outTimerText, TextMesh outMovesText)
        {
            bGrid                   = gB.grid;
            anchor                  = gB.anchor;
            LevelWinEvent          += LevelWin;
            LevelLooseEvent        += LevelLoose;
            CheckTargetResultEvent += CheckTargetResult;

            timeCostrain  = mc.TimeConstrain;
            movesCostrain = mc.MovesConstrain;
            movesRest     = movesCostrain;
            loopTopRow    = mc.LoopTopRow;
            TopRowBubblesCountToCollect = Mathf.Min(mc.BubblesCount, bGrid.TopObjectRow.GetNotEmptyCells().Count); // default 6 bubbles in mission construct
            // Debug.Log( "loop: " + mc.BubblesCount + " : " + bGrid.TopObjectRow.GetNotEmptyCells().Count);
            raiseAnchor   = mc.RaiseAnchor;
            targets       = mc.Targets;
            GameLevelType = mc.GetLevelType();

            topRowBubblesCountAtStart = bGrid.TopObjectRow.GetNotEmptyCells().Count;

            targetsToCollect          = new Dictionary <int, int>();
            onBoardTargetsAtStart     = new Dictionary <int, int>();
            onBoardTargetsAtCheckTime = onBoardTargetsAtStart;

            useObjecTargets = (targets != null && targets.Count > 0);


            if (useObjecTargets)
            {
                foreach (var item in targets.ObjectsList) // use only first target
                {
                    targetID = item.ID;
                    int id     = item.ID;
                    int count  = item.Count;
                    int bCount = bGrid.GetObjectsCountByID(id);
                    Debug.Log("target: " + id + " : " + Mathf.Min(count, bCount));
                    if (!targetsToCollect.ContainsKey(id) && Mathf.Min(count, bCount) > 0)
                    {
                        targetsToCollect.Add(id, Mathf.Min(count, bCount));
                        onBoardTargetsAtStart.Add(id, Mathf.Min(count, bCount));
                        Debug.Log(" add target: " + id + " : " + Mathf.Min(count, bCount));
                    }

                    break; // use only first target
                }
            }

            GameResult = GameResult.None;
            if (timeCostrain > 0)
            {
                Timer = new SessionTimer(timeCostrain);
                //Timer.Start();

                UseTimer = true;
                Timer.OnTickRestSeconds = (sec) => { timeRest = (int)sec; if (timeRest <= 30 && !timeLeftShowed)
                                                     {
                                                         timeLeftShowed = true; GuiController.Instance.ShowMessageTimeLeft("Warning!", "30 seconds left", 1);
                                                     }
                };
                Timer.OnTimePassed = () => { if (GameResult == GameResult.None)
                                             {
                                                 CheckResult(false, false);
                                             }
                };

                if (outMovesText)
                {
                    outMovesText.gameObject.SetActive(false);
                }

                if (outTimerText)
                {
                    if (outTimerText)
                    {
                        outTimerText.gameObject.SetActive(true);
                    }
                    Timer.OnTickRestSeconds += (sec) => { outTimerText.text = sec.ToString(); };
                }
            }
            else
            {
                if (outTimerText)
                {
                    if (outTimerText)
                    {
                        outTimerText.gameObject.SetActive(false);
                    }
                }
                if (outMovesText)
                {
                    outMovesText.gameObject.SetActive(true);
                    outMovesText.text = movesRest.ToString();
                }
                bubblesShooter.ShootEvent += () =>
                {
                    if (!UseTimer)
                    {
                        movesRest--;
                        if (outMovesText)
                        {
                            outMovesText.text = movesRest.ToString();
                            if (movesRest == 5)
                            {
                                counterTweenID = SimpleTween.Value(outMovesText.gameObject, 1.0f, 0.5f, 0.5f).SetEase(EaseAnim.EaseLinear).
                                                 SetOnUpdate((float val) => { if (this != null && outMovesText)
                                                                              {
                                                                                  outMovesText.color = new Color(1, val, val, 1);
                                                                              }
                                                                              else
                                                                              {
                                                                                  SimpleTween.Cancel(counterTweenID, false);
                                                                              } }).SetCycled().ID;
                            }
                            if (movesRest == 0)
                            {
                                SimpleTween.Cancel(outMovesText.gameObject, false);
                            }
                        }
                    }
                };
            }

            Debug.Log("GameLevelType : " + GameLevelType);
            CheckTopRow();
            CheckTargetsOnBoard();
        }