コード例 #1
0
    public PuzzleBoard(PuzzleBoardHandler handler, StageDefinition stageDefinition, PoemInstance poemInstance)
    {
        this.handler          = handler;
        this.stageDefinition  = stageDefinition;
        this.poemDefinition   = stageDefinition.PoemDefinition;
        this.puzzleDefinition = stageDefinition.PuzzleDefinition;
        this.poemInstance     = poemInstance;

        Vector2 size = TranslateBoardSize(this.puzzleDefinition.BoardSize);

        this.Width  = (int)size.x;
        this.Height = (int)size.y;

        List <string> targetCharacterIds    = ComposeTargetCharIds();
        List <string> appearingCharacterIds = GenerateAppearingCharIds(targetCharacterIds);

        this.PuzzleCharacters = new List <PuzzleCharacter>();
        currentCharacterIndex = 0;
        foreach (string appearingCharId in appearingCharacterIds)
        {
            this.PushCharacter(appearingCharId);
        }

        Debug.Log("Pushed all appearing characters.");

        try
        {
            GenerateAndEnsureMatrix(this.PuzzleCharacters);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
コード例 #2
0
    public void Initialize(PoemInstance poemInstance, bool isBlind)
    {
        this.poemInstance     = poemInstance;
        this.isTotalBlindMode = isBlind;

        this.Width  = poemInstance.Width;
        this.Height = poemInstance.Height;

        float anchorX = anchorStart.transform.localPosition.x;
        float anchorY = anchorStart.transform.localPosition.y;

        float interval = this.anchorInterval.transform.localPosition.x - anchorX;

        // Render the characters onto HintBoard
        for (int i = 0; i < this.Width; i++)
        {
            for (int j = 0; j < this.Height; j++)
            {
                string charId = poemInstance.GetCharacterIdAt(i, j);

                GameObject go = new GameObject("Character_" + (j * Width + i).ToString());
                go.transform.parent = this.transform;

                float posX = anchorX + i * interval;
                float posY = anchorY - j * interval;

                if (this.isTint)
                {
                    posX += j * interval;
                }

                go.transform.localPosition = new Vector3(posX, posY, -1);
                go.transform.localScale    = new Vector3(1.0f, 1.0f, 1);

                SpriteRenderer renderer = go.AddComponent <SpriteRenderer>();
                var            sprite   = GlobalStorage.GetSpriteFromDictionary(charId);
                //// Texture2D texture = (Texture2D)Resources.Load("characters/fzlb/c_" + charId);
                if (sprite != null)
                {
                    renderer.sprite = sprite;
                }

                if (!poemInstance.IsUncoveredAt(i + j * Width))
                {
                    Color theColorToAdjust = renderer.color;
                    theColorToAdjust.a = this.isTotalBlindMode ? 0f : 0.2f;
                    renderer.color     = theColorToAdjust;
                }
                else
                {
                    Color theColorToAdjust = renderer.color;
                    theColorToAdjust.a = 0f;
                    renderer.color     = theColorToAdjust;
                    var fadeIn = go.AddComponent <FadeIn>();
                    fadeIn.SetFadeTime(1.5f);
                }
            }
        }
    }
コード例 #3
0
    public void Initialize(StageDefinition stageDefinition, PoemInstance poemInstance)
    {
        this.StageDefinition = stageDefinition;
        this.poemInstance    = poemInstance;

        this.puzzleBoard = new PuzzleBoard(this, stageDefinition, poemInstance);


        // Render the board
        foreach (PuzzleCharacter character in puzzleBoard.PuzzleCharacters)
        {
            RenderPuzzleNode(character);
        }
    }
コード例 #4
0
    public void InitializeBoard()
    {
        StageDefinition stageDefinition = LoadCurrentStage();

        poem = new PoemInstance(stageDefinition.PoemDefinition, stageDefinition.PuzzleDefinition.SelectedLines,
                                stageDefinition.PuzzleDefinition.UncoveredCharIndexes);

        string backgroundImage = string.Format(@"images/stage_{0}_full", this.StageId);

        background.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>(backgroundImage);
        //// background.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.5f);

        // Read the HintBoard and PuzzleBoard
        if (poem.Height == 2 && poem.Width == 5)
        {
            this.HintBoard = GameObject.Instantiate(this.hint25Prefab);
        }
        if (poem.Height == 2 && poem.Width == 7)
        {
            this.HintBoard = GameObject.Instantiate(this.hint27Prefab);
        }
        if (poem.Height == 4 && poem.Width == 5)
        {
            this.HintBoard = GameObject.Instantiate(this.hint45Prefab);
        }
        if (poem.Height == 4 && poem.Width == 7)
        {
            this.HintBoard = GameObject.Instantiate(this.hint47Prefab);
        }

        this.HintBoard.transform.parent        = this.hintAnchor.transform;
        this.HintBoard.transform.localPosition = new Vector3(0, 0, -1);

        var hintBoardRenderer = this.HintBoard.GetComponent <HintBoardRenderer>();

        hintBoardRenderer.Initialize(poem, !stageDefinition.PuzzleDefinition.IsEasyMode);
        this.HintBoard.transform.localScale = new Vector3(hintBoardRenderer.scaleFactor, hintBoardRenderer.scaleFactor, 1);

        switch (stageDefinition.PuzzleDefinition.BoardSize)
        {
        case PuzzleBoardSize.TINY:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleTinyPrefab);
            break;

        case PuzzleBoardSize.SMALL:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleSmallPrefab);
            break;

        case PuzzleBoardSize.MEDIUM:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleMediumPrefab);
            break;

        case PuzzleBoardSize.LARGE:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleLargePrefab);
            break;

        case PuzzleBoardSize.HUGE:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleHugePrefab);
            break;

        default:
            this.PuzzleBoard = GameObject.Instantiate(this.puzzleMediumPrefab);
            break;
        }

        this.PuzzleBoard.transform.parent        = this.puzzleAnchor.transform;
        this.PuzzleBoard.transform.localPosition = new Vector3(0, 0, -1);

        var puzzleBoardRenderer = this.PuzzleBoard.GetComponent <PuzzleBoardRenderer>();

        puzzleBoardRenderer.Initialize(stageDefinition, poem);
        this.PuzzleBoard.transform.localScale = new Vector3(puzzleBoardRenderer.ScaleFactor, puzzleBoardRenderer.ScaleFactor, 1);

        puzzleBoardRenderer.onReceivedCharacter += PuzzleBoardRenderer_onReceivedCharacter;

        if (!stageDefinition.PuzzleDefinition.IsEasyMode)
        {
            var gameData = GlobalStorage.LoadGameData();

            this.btnReveal.SetActive(true);
            this.txtRevealCount.SetActive(true);
            RefreshRevealButton(gameData?.RevealCount ?? 0);
        }
        else
        {
            this.btnReveal.SetActive(false);
            this.txtRevealCount.SetActive(false);
        }
    }