Exemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string    id        = (string)value;
            GameBoard gameBoard = GameBoardXmlIo.ReadGameBoard(id, UnityResourcesFolder);

            string types = gameBoard != null?gameBoard.GetContainBlockTypesString() : string.Empty;

            return(types);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string    id        = (string)value;
            GameBoard gameBoard = GameBoardXmlIo.ReadGameBoard(id, UnityResourcesFolder);

            int rows = gameBoard != null?gameBoard.GetTrimmedBoard().GetLength(0) : 0;

            return(rows);
        }
Exemplo n.º 3
0
        public void CanReadWriteGameBoardXml()
        {
            string gameBoardPath = GameBoardXmlIo.WriteGameBoard(this.gameBoard, "Test");
            string fileName      = Path.GetFileName(gameBoardPath);

            GameBoard readGameBoard = GameBoardXmlIo.ReadGameBoard(fileName, "Test");

            Assert.AreEqual(this.gameBoard.GetBoardString(), readGameBoard.GetBoardString());
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string    id        = (string)value;
            GameBoard gameBoard = GameBoardXmlIo.ReadGameBoard(id, UnityResourcesFolder);

            string difficulty = gameBoard == null
                                    ? string.Empty
                                    : string.Format(
                "Diff: {0:00.00}\t Successes {1}\t Failures {2}",
                gameBoard.GetDifficulty(),
                gameBoard.Successes,
                gameBoard.Failures);

            return(difficulty);
        }
Exemplo n.º 5
0
        public void CanReadWriteGameBoardXmlFromFile()
        {
            GameBoard readGameBoard = GameBoardXmlIo.ReadGameBoard("gameboardXml.txt", "TestData");

            Assert.AreEqual(this.gameBoard.GetBoardString(), readGameBoard.GetBoardString());
        }
Exemplo n.º 6
0
    private void LoadPuzzleIntoTable()
    {
        // Clear the animation queue
        this.setAnimationQueue.Clear();

        // Clear the history
        this.movesHistory = new Stack <BlockMovement>();

        // Fudge Factor so it doesn't use up the whole space, just most of it
        const float FudgeFactor = .95f;

        string puzzleName = this.specialStageMode
                                                                ? this.SpecialStage.LevelMapping.Mapping[this.Level]
                                                                : this.levelMapping.Mapping[this.Level];

        this.GameBoard = GameBoardXmlIo.ReadGameBoard(puzzleName);

        TutorialMessage tutorial = null;

        if (!this.specialStageMode)
        {
            tutorial = this.Tutorials.FirstOrDefault(t => t.Level == this.Level);
        }

        // Set the number of columns
        IGameBlock[,] trimmedBoard = this.GameBoard.GetTrimmedBoard();
        int rows    = trimmedBoard.GetLength(0);
        int columns = trimmedBoard.GetLength(1);

        this.Table.columns = columns;

        GamePiece[,] gamePieces = new GamePiece[rows, columns];

        // Calculate what is available for width and height
        float availableWidth  = this.TableLimits.localSize.x * FudgeFactor;
        float availableHeight = this.TableLimits.localSize.y * FudgeFactor;

        // Show the tutorial
        if (tutorial != null)
        {
            // Account for the size of the tutorial tip
            availableHeight -= this.TutorialSize;
            this.TutorialTipStripObject.SetActive(true);
            this.TutorialTipStripMessage.text = tutorial.Message;
        }
        else
        {
            this.TutorialTipStripObject.SetActive(false);
        }

        availableWidth  /= columns;
        availableHeight /= rows;

        // Choose the smallest size otherwise it will be too big to fit
        this.BlockSize = Math.Min((int)Math.Floor(Math.Min(availableWidth, availableHeight)), this.MaxBlockSize);

        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
            {
                IGameBlock gameBlock = trimmedBoard[i, j];
                GamePiece  block     = NGUITools.AddChild(this.Table.gameObject, this.GamePiece.gameObject).GetComponent <GamePiece>();
                block.GameBlock = gameBlock;
                block.SetBlockSize(this.BlockSize);
                block.SetAnimationMappings(this.animationMappingsDictionary);
                block.LoadImage();
                block.SubscribeToGameBlockEvents();

                if (gameBlock != null)
                {
                    block.name = string.Format("{0}-{1}: {2}", gameBlock.IndexRow, gameBlock.IndexColumn, gameBlock.GetBlockString());
                }
                else
                {
                    block.name = "Null Block";
                }

                this.Table.children.Add(block.transform);
                gamePieces[i, j] = block;
            }
        }

        // Center the table
        float heightOffset = (float)(rows * this.BlockSize) / 2;
        float widthOffset  = -(float)(columns * this.BlockSize) / 2;

        this.Table.transform.localPosition = new Vector3(widthOffset, heightOffset + this.VerticalOffset);

        this.Table.enabled       = true;
        this.Table.repositionNow = true;

        this.firstMove = true;

        // Show the indicator that this is the first time the level is played
        string key = this.specialStageMode
                                                 ? string.Format("{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level)
                                                 : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level);

        int timesPlayed = PlayerPrefsFast.GetInt(key, 0);

        this.FirstTimeIndicator.SetActive(timesPlayed == 0);

        this.CurrentLevelText.text = string.Format("Level {0}", this.Level);

        if (!this.specialStageMode)
        {
            foreach (TutorialAnimation tutorialAnimation in this.TutorialAnimations)
            {
                if (tutorialAnimation.Level == this.Level)
                {
                    NGUITools.AddChild(gamePieces[tutorialAnimation.Row, tutorialAnimation.Column].gameObject, tutorialAnimation.Animation);
                }
            }
        }
    }