Example #1
0
        public WinController(MissionConstruct mc, MatchBoard gB)
        {
            Result = GameResult.None;

            mGrid         = gB.grid;
            mBoard        = gB;
            movesCostrain = mc.MovesConstrain;
            MovesRest     = movesCostrain;
            ScoreTarget   = mc.ScoreTarget;
            botDynCells   = mBoard.grid.GetBottomDynCells();

            #region time
            timeCostrain = mc.TimeConstrain;
            IsTimeLevel  = mc.IsTimeLevel;
            if (IsTimeLevel)
            {
                MovesRest = 0;
                Timer     = new SessionTimer(timeCostrain);
                Timer.TickRestFullSecondsEvent += (s) => { TimerTickEvent?.Invoke(s); };
                Timer.TickRestFullSecondsEvent += (sec) => { TimeRest = (int)sec; if (TimeRest == 30)
                                                             {
                                                                 TimerLeft30Event?.Invoke();
                                                             }
                };
                Timer.TimePassedEvent += () => { if (Result == GameResult.None)
                                                 {
                                                     CheckResult();
                                                 }
                };
            }
            #endregion time
        }
 void OnEnable()
 {
     // Debug.Log("onenable " + ToString());
     if (levelMission == null)
     {
         levelMission = new MissionConstruct();
     }
     levelMission.SaveEvent = SetAsDirty;
 }
Example #3
0
 public void RefreshTimeMoves()
 {
     if (MatchBoard.GMode == GameMode.Edit)
     {
         MissionConstruct mc = MBoard.LcSet.levelMission;
         if (MovesCountText)
         {
             MovesCountText.text = mc.MovesConstrain.ToString();
         }
         if (TimerText)
         {
             TimerText.text = mc.TimeConstrain.ToString();
         }
         if (MovesBlock)
         {
             MovesBlock.SetActive(!mc.IsTimeLevel);
         }
         if (TimerBlock)
         {
             TimerBlock.SetActive(mc.IsTimeLevel);
         }
     }
     else
     {
         WinController winContr = MBoard.WinContr;
         if (!winContr.IsTimeLevel)
         {
             if (MovesCountText)
             {
                 MovesCountText.text = winContr.MovesRest.ToString();
             }
         }
         else
         {
             if (TimerText)
             {
                 TimerText.text = winContr.TimeRest.ToString();
             }
         }
     }
 }
        public override void RefreshWindow()
        {
            LevelConstructSet lCS   = GameBoard.LcSet;
            MissionConstruct  lM    = lCS.levelMission;
            LevelType         lType = lM.GetLevelType();

            int           time  = lM.TimeConstrain;
            int           moves = lM.MovesConstrain;
            int           level = BubblesPlayer.CurrentLevel + 1;
            WinController wC    = GameBoard.Instance.WController;

            if (descriptionText)
            {
                descriptionText.text = lM.Description;
            }

            if (levelNumberText)
            {
                levelNumberText.text = level.ToString();
            }

            if (TimeLevelGO)
            {
                TimeLevelGO.SetActive(lType == LevelType.TimeLevel);
            }
            if (FishLevelGO)
            {
                FishLevelGO.SetActive(lType == LevelType.FishLevel);
            }
            if (AnchorLevelGO)
            {
                AnchorLevelGO.SetActive(lType == LevelType.AnchorLevel);
            }
            if (LoopTopRowLevelGO)
            {
                LoopTopRowLevelGO.SetActive(lType == LevelType.LoopTopRowLevel);
            }

            switch (lType)
            {
            case LevelType.LoopTopRowLevel:
                if (bubblesCountText)
                {
                    bubblesCountText.text = "x " + wC.TopRowBubblesCountToCollect;
                }
                break;

            case LevelType.TimeLevel:
                if (timeLimitText)
                {
                    timeLimitText.text = "x " + time;
                }
                break;

            case LevelType.AnchorLevel:
                if (anchorCountText)
                {
                    anchorCountText.text = "x " + 1;
                }
                break;

            case LevelType.FishLevel:
                int fishCount          = 0;
                int fishCountCollected = 0;
                wC.GetCurrTarget(out fishCountCollected, out fishCount);
                if (targetCountText)
                {
                    targetCountText.text = "x " + fishCount;
                }
                break;
            }
            base.RefreshWindow();
        }
Example #5
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();
        }
        //#region gift
        //public void OpenGiftPanel_Click()
        //{
        //    Debug.Log("open click");
        //    ScrollPanelController sRC = GiftPanelContainer.ScrollPanel;
        //    if (sRC) //
        //    {
        //        if (sRC) sRC.CloseScrollPanel(true, null);
        //    }
        //    else
        //    {
        //        //instantiate ScrollRectController
        //        sRC = GiftPanelContainer.InstantiateScrollPanel();
        //        sRC.textCaption.text = "Gift panel";

        //        LevelConstructSet lcSet = GameBoard.Instance.gcSet.GetLevelConstructSet(BubblesPlayer.CurrentLevel);
        //        GameConstructSet gcSet = GameBoard.Instance.gcSet;
        //        GiftConstruct levelGift = gcSet.gift;

        //        //create life gift
        //        IncDecInputPanel.Create(sRC.scrollContent, IncDecPanelPrefab, "Life", levelGift.Life.ToString(),
        //            () => { levelGift.AddLifes(1); },
        //            () => { levelGift.AddLifes(-1); },
        //            (val) => { int res; bool good = int.TryParse(val, out res); if (good) { levelGift.SetLifesCount(res); }},
        //            () => { return levelGift.Life.ToString(); },
        //            null);

        //        //create coins gift
        //        IncDecInputPanel.Create(sRC.scrollContent, IncDecPanelPrefab, "Coins", levelGift.Coins.ToString(),
        //        () => { levelGift.AddCoins(1); },
        //        () => { levelGift.AddCoins(-1); },
        //        (val) => { int res; bool good = int.TryParse(val, out res); if (good) { levelGift.SetCoinsCount(res); } },
        //        () => { return levelGift.Coins.ToString(); },
        //        null);

        //        //create booster gift
        //        GameObjectsSet goSet = lcSet.Matchset;
        //        IList<BoosterObjectData> bDataL = goSet.BoosterObjects;
        //        foreach (var item in bDataL)
        //        {
        //            int id = item.ID;
        //            IncDecInputPanel.Create(sRC.scrollContent, IncDecPanelPrefab, "Booster", levelGift.GetBoosterCount(id).ToString(),
        //            () => { levelGift.AddBooster(id); },
        //            () => { levelGift.RemoveBooster(id); },
        //            (val) => { int res; bool good = int.TryParse(val, out res); if (good) { levelGift.SetBoosterCount(res, id); } },
        //            () => { return levelGift.GetBoosterCount(id).ToString(); },
        //            item.GuiImage);
        //        }

        //        sRC.OpenScrollPanel(null);
        //    }
        //}
        //#endregion gift

        #region mission
        public void OpenMissionPanel_Click()
        {
            Debug.Log("open mission click");
            BubbleGrid grid = GameBoard.Instance.grid;

            ScrollPanelController sRC = MissionPanelContainer.ScrollPanel;

            if (sRC) //
            {
                sRC.CloseScrollPanel(true, null);
            }
            else
            {
                CloseOpenedPanels();
                //instantiate ScrollRectController
                sRC = MissionPanelContainer.InstantiateScrollPanel();
                sRC.textCaption.text = "Mission panel";

                LevelConstructSet lcSet        = GameBoard.Instance.gcSet.GetLevelConstructSet(BubblesPlayer.CurrentLevel);
                MissionConstruct  levelMission = lcSet.levelMission;

                //create mission moves constrain
                IncDecInputPanel.Create(sRC.scrollContent, IncDecPanelPrefab, "Moves", levelMission.MovesConstrain.ToString(),
                                        () => { levelMission.AddMoves(1); },
                                        () => { levelMission.AddMoves(-1); },
                                        (val) => { int res; bool good = int.TryParse(val, out res); if (good)
                                                   {
                                                       levelMission.SetMovesCount(res);
                                                   }
                                        },
                                        () => { return(levelMission.MovesConstrain.ToString()); },
                                        null);

                //create time constrain
                IncDecInputPanel.Create(sRC.scrollContent, IncDecPanelPrefab, "Time", levelMission.TimeConstrain.ToString(),
                                        () => { levelMission.AddTime(1); },
                                        () => { levelMission.AddTime(-1); },
                                        (val) => { int res; bool good = int.TryParse(val, out res); if (good)
                                                   {
                                                       levelMission.SetTime(res);
                                                   }
                                        },
                                        () => { return(levelMission.TimeConstrain.ToString()); },
                                        null);

                //description input field
                IncDecInputPanel.Create(sRC.scrollContent, InputTextPanelMissionPrefab, "Description", levelMission.Description,
                                        null,
                                        null,
                                        (val) => { levelMission.SetDescription(val); },
                                        () => { return(levelMission.Description); },
                                        null);

                // create clean top row check box condition
                IncDecInputPanel.Create(sRC.scrollContent, TogglePanelMissionPrefab, "Clean top row", null,
                                        levelMission.LoopTopRow,
                                        null,
                                        null,
                                        null,
                                        (val) => { levelMission.SetLoopTopRow(val); },
                                        null,
                                        null);

                // create raise anchor check box condition
                IncDecInputPanel.Create(sRC.scrollContent, TogglePanelMissionPrefab, "Raise anchor", null,
                                        levelMission.RaiseAnchor,
                                        null,
                                        null,
                                        null,
                                        (val) => { levelMission.SetRaiseAnchor(val); },
                                        null,
                                        null);


                //create object targets
                GameObjectsSet         goSet  = lcSet.Matchset;
                IList <BaseObjectData> tDataL = goSet.TargetObjects;
                foreach (var item in tDataL)
                {
                    if (item != null)
                    {
                        Debug.Log("target ID: " + item.ID);
                        int id = item.ID;
                        IncDecInputPanel.Create(sRC.scrollContent, IncDecTogglePanelMissionPrefab, "Target", levelMission.GetTargetCount(id).ToString(),
                                                levelMission.GetTargetCount(id) == 10000,
                                                () => { levelMission.AddTarget(id, 1); },
                                                () => { levelMission.RemoveTarget(id, 1); },
                                                (val) => { int res; bool good = int.TryParse(val, out res); if (good)
                                                           {
                                                               levelMission.SetTargetCount(id, res);
                                                           }
                                                },
                                                (val) => { if (val)
                                                           {
                                                               levelMission.SetTargetCount(id, 10000);
                                                           }
                                                           else
                                                           {
                                                               levelMission.SetTargetCount(id, 0);
                                                           } },
                                                () => { return(levelMission.GetTargetCount(id).ToString()); }, // grid.GetObjectsCountByID(id).ToString()); },
                                                item.GuiImage);
                    }
                }

                sRC.OpenScrollPanel(null);
            }
        }
        public void OpenGridSettingsPanel_Click()
        {
            Debug.Log("open grid settings click");
            BubbleGrid grid = GameBoard.Instance.grid;

            ScrollPanelController sRC = GridPanelContainer.ScrollPanel;

            if (sRC) //
            {
                if (sRC)
                {
                    sRC.CloseScrollPanel(true, null);
                }
            }
            else
            {
                CloseOpenedPanels();
                //instantiate ScrollRectController
                sRC = GridPanelContainer.InstantiateScrollPanel();
                sRC.textCaption.text = "Grid panel";

                LevelConstructSet lcSet        = GameBoard.Instance.gcSet.GetLevelConstructSet(BubblesPlayer.CurrentLevel);
                MissionConstruct  levelMission = lcSet.levelMission;

                //create  vert size block
                IncDecInputPanel.Create(sRC.scrollContent, IncDecGridPrefab, "VertSize", grid.Rows.Count.ToString(),
                                        () => { IncVertSize(); },
                                        () => { DecVertSize(); },
                                        (val) => {  },
                                        () => { return(grid.Rows.Count.ToString()); },
                                        null);

                //create hor size block
                IncDecInputPanel.Create(sRC.scrollContent, IncDecGridPrefab, "HorSize", lcSet.HorSize.ToString(),
                                        () => { IncHorSize(); },
                                        () => { DecHorSize(); },
                                        (val) => { },
                                        () => { return(lcSet.HorSize.ToString()); },
                                        null);

                //create background block
                IncDecInputPanel.Create(sRC.scrollContent, IncDecGridPrefab, "BackGrounds", lcSet.backGroundNumber.ToString(),
                                        () => { IncBackGround(); },
                                        () => { DecBackGround(); },
                                        (val) => { },
                                        () => { return(lcSet.backGroundNumber.ToString()); },
                                        null);

                //create game object set block
                GameObjectsSet ms      = lcSet.Matchset;
                int            indexMS = MatchSets.IndexOf(ms);
                IncDecInputPanel.Create(sRC.scrollContent, IncDecGridPrefab, "GameSets", ms.name.ToString(),
                                        () => { if (indexMS < 0 || MatchSets.Count < 1)
                                                {
                                                    return;
                                                }
                                                indexMS = (int)Mathf.Repeat(++indexMS, MatchSets.Count); lcSet.Matchset = MatchSets[indexMS]; ShowLevelData(); },
                                        () => { if (indexMS < 0 || MatchSets.Count < 1)
                                                {
                                                    return;
                                                }
                                                indexMS = (int)Mathf.Repeat(--indexMS, MatchSets.Count); lcSet.Matchset = MatchSets[indexMS]; ShowLevelData(); },
                                        (val) => { },
                                        () => { return(lcSet.Matchset.name.ToString()); },
                                        null);


                sRC.OpenScrollPanel(null);
            }
        }