// Start is called before the first frame update
    void Start()
    {
        GlobalStorage.LoadSpriteDictionary();

        this.SelectedCategory = GlobalStorage.CurrentCategory;

        if (btnBack != null && btnBack.GetComponent <CommonButton>() != null)
        {
            btnBack.GetComponent <CommonButton>().SetCallback(() => { this.BtnBackClicked(); });
        }

        if (categoryTitle != null)
        {
            categoryTitle.GetComponent <SpriteRenderer>().sprite =
                Resources.Load <Sprite>(string.Format(@"images/category-title-{0}", this.SelectedCategory));
        }

        // Ensure the first Stage
        var stage101 = GlobalStorage.LoadRecord(101);

        if (stage101 == null)
        {
            stage101 = StageRecord.Create(101);
            GlobalStorage.SaveRecord(stage101);
        }


        // Play animation to show title and pre
        activityManager = this.gameObject.GetComponent <ActivityManager>();
        if (activityManager == null)
        {
            return;
        }
        activityManager.Initialize(false);

        var moveTo = categoryTitle.AddComponent <MoveTo>();

        moveTo.Initialize(new Vector2(0, 5.5f), 0.6f);

        var delay = new DelayActivity(0.5f);

        activityManager.PushActivity(delay);

        var bundle = new BundleActivity();

        for (int i = 0; i < 9; i++)
        {
            GameObject previewAnchor = this.previewAnchors[i];
            GameObject preview       = GameObject.Instantiate(StagePreviewPrefab);

            // preview.transform.parent = previewAnchor.transform;
            preview.transform.localPosition = previewAnchor.transform.position;
            preview.transform.localScale    = new Vector3(1.5f, 1.5f, 1);
            var renderer = preview.GetComponent <StagePreviewRenderer>();

            int stageId = this.SelectedCategory * 100 + i + 1;
            renderer.Initialize(stageId);
            renderer.SetCallback((stage) => { this.EnterStage(stage); });

            var fadeIn = new FadeInActivity(preview, 0.6f);
            fadeIn.InitObject();
            bundle.AddActivity(fadeIn);
        }

        activityManager.PushActivity(bundle);
    }
Beispiel #2
0
    public void OnGameWin()
    {
        Debug.Log("OnGameWin");

        // Save record
        StageRecord record = GlobalStorage.LoadRecord(this.StageId);

        if (record == null)
        {
            record              = new StageRecord();
            record.StageId      = this.StageId;
            record.HighestScore = 0;
        }

        record.JustCompleted = true;

        int score           = CalculateScore();
        int gainRevealCount = 0;

        if (record.HighestScore < score)
        {
            gainRevealCount     = score - record.HighestScore;
            record.HighestScore = score;
        }
        GlobalStorage.SaveRecord(record);

        if (gainRevealCount > 0)
        {
            var gameData = GlobalStorage.LoadGameData();
            gameData.RevealCount += gainRevealCount;
            GlobalStorage.SaveGame(gameData);
        }

        int nextStageId = 0;

        if (this.StageId == 109)
        {
            nextStageId = 201;
        }
        else if (this.StageId == 209)
        {
            nextStageId = 301;
        }
        else
        {
            nextStageId = this.StageId + 1;
        }

        if (nextStageId > 0 && GlobalStorage.LoadRecord(nextStageId) == null)
        {
            StageRecord next = new StageRecord();
            next.StageId      = nextStageId;
            next.HighestScore = 0;
            GlobalStorage.SaveRecord(next);
        }

        if (this.StageId % 10 < 8 && GlobalStorage.LoadRecord(this.StageId + 2) == null)
        {
            StageRecord next = new StageRecord();
            next.StageId      = this.StageId + 2;
            next.HighestScore = 0;
            GlobalStorage.SaveRecord(next);
        }

        // Play animation to close the panels and show poem in full
        var activityManager = AquireActivityManager();
        var fadeOut1        = new FadeOutActivity(this.PuzzleBoard, 1.5f);
        var fadeOut2        = new FadeOutActivity(this.HintBoard, 1.5f);
        var fadeOut3        = new FadeOutActivity(this.btnReveal, 1.5f);
        var fadeOut4        = new FadeOutActivity(this.btnBack, 1.5f);
        var fadeOut5        = new FadeOutActivity(this.btnReshuffle, 1.5f);

        ////var fadeOut6 = new FadeOutActivity(this.txtRevealCount, 1.5f);

        this.txtRevealCount.SetActive(false);
        this.btnRestart.SetActive(false);

        var bundle = new BundleActivity();

        bundle.AddActivity(fadeOut1);
        bundle.AddActivity(fadeOut2);
        bundle.AddActivity(fadeOut3);
        bundle.AddActivity(fadeOut4);
        bundle.AddActivity(fadeOut5);
        ////bundle.AddActivity(fadeOut6);

        var gameObject = new GameObject("WinningPoem");
        var renderer   = gameObject.AddComponent <SpriteRenderer>();

        renderer.sprite = Resources.Load <Sprite>(string.Format(@"images/stage_{0}_win", this.StageId));
        renderer.color  = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        gameObject.transform.localScale = new Vector3(0.55f, 0.55f, 1.0f);
        gameObject.transform.position   = new Vector3(0f, 0f, -2.0f);
        activityManager.PushActivity(bundle);

        var fadeIn = new FadeInActivity(gameObject, 1.5f);

        activityManager.PushActivity(fadeIn);

        var receiveStar1 = new ReceiveCharActivity(this.gameObject, this.successStar1);

        receiveStar1.SetScales(3.0f, 6.0f);
        activityManager.PushActivity(receiveStar1);

        if (score > 1)
        {
            var receiveStar2 = new ReceiveCharActivity(this.gameObject, this.successStar2);
            receiveStar2.SetScales(3.0f, 6.0f);
            activityManager.PushActivity(receiveStar2);
        }

        if (score > 2)
        {
            var receiveStar3 = new ReceiveCharActivity(this.gameObject, this.successStar3);
            receiveStar3.SetScales(3.0f, 6.0f);
            activityManager.PushActivity(receiveStar3);
        }

        var showSuccess = new ReceiveCharActivity(this.gameObject, this.btnSuccess);

        showSuccess.SetScales(0.2f, 0.4f);
        activityManager.PushActivity(showSuccess);
    }