コード例 #1
0
ファイル: ConsoleUI.cs プロジェクト: Baloons-Pop-4/Main
        public void PrintField(IBalloon[,] matrix)
        {
            Console.Clear();
            this.PrintColumnIndeces();

            this.PrintDashedLine(1 + (matrix.GetLength(1) * 2));

            for (byte i = 0; i < matrix.GetLongLength(0); i++)
            {
                this.PrintRowBeggining(i);

                for (byte j = 0; j < matrix.GetLongLength(1); j++)
                {
                    this.PrintBalloon(matrix[i, j]);
                }

                this.SetConsoleColorToDefault();
                this.PrintRowEnd();
            }

            this.PrintDashedLine(1 + (matrix.GetLength(1) * 2));
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Memento"/> class which stores the board's state.
 /// </summary>
 /// <param name="board">the object that is being stored for restoration at a later point.</param>
 public Memento(IBalloon[,] board)
 {
     this.Board = board;
     this.Rows = board.GetLength(0);
     this.Cols = board.GetLength(1);
 }
コード例 #3
0
ファイル: GnomController.cs プロジェクト: Baloons-Pop-4/Main
        private void InitializeField(IBalloon[,] matrix)
        {
            int rows = matrix.GetLength(0);
            int columns = matrix.GetLength(1);

            this.cachedField = new TextElement[rows, columns];

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    // TODO: extract in resource provider
                    var childToAdd = new TextElement(WholeBalloonContent);

                    childToAdd.Style = new Style()
                    {
                        PaddingLeft = j * BalloonPaddingLeftMultiplier,
                        PaddingTop = i * BalloonPaddingTopMultiplier,
                        Color = Colors[matrix[i, j].IsPopped ? 0 : matrix[i, j].Number]
                    };

                    childToAdd.Id = i + " " + j;

                    // cache
                    this.cachedField[i, j] = childToAdd;

                    this.View.AddChildToParent(this.field, childToAdd);

                    // link to neighbors
                    if (i > 0)
                    {
                        childToAdd.LinkTo(ConsoleKey.UpArrow, this.cachedField[i - 1, j]);
                    }

                    if (j > 0)
                    {
                        childToAdd.LinkTo(ConsoleKey.LeftArrow, this.cachedField[i, j - 1]);
                    }
                }
            }

            for (int i = columns - 1; i >= 0; i--)
            {
                this.cachedField[rows - 1, i].LinkTo(ConsoleKey.DownArrow, this.View[RestartButtonId]);
            }
        }
コード例 #4
0
ファイル: GnomController.cs プロジェクト: Baloons-Pop-4/Main
        /// <summary>
        /// Updates the view with information from the provided balloon matrix.
        /// </summary>
        /// <param name="matrix"></param>
        public void PrintField(IBalloon[,] matrix)
        {
            if (this.cachedField == null)
            {
                this.InitializeField(matrix);

                return;
            }

            int rows = matrix.GetLength(0);
            int columns = matrix.GetLength(1);

            int popped = 0;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    var childToUpdate = this.cachedField[i, j];
                    childToUpdate.Style.Color = Colors[matrix[i, j].IsPopped ? 0 : matrix[i, j].Number];

                    if (matrix[i, j].IsPopped)
                    {
                        childToUpdate.Content = PoppedBalloonContent;
                        popped++;
                    }
                }
            }

            if (popped >= (rows * columns) - 1)
            {
                foreach (var element in this.cachedField)
                {
                    element.Content = WholeBalloonContent;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Introduces updates on the view bases on the provided IBalloon two-dimensional array.
        /// </summary>
        /// <param name="matrix">The array which is used as a blueprint for introducing changes to the view.</param>
        public void PrintField(IBalloon[,] matrix)
        {
            var rowsCount = matrix.GetLength(0);
            var colsCount = matrix.GetLength(1);

            if (this.balloons == null)
            {
                this.InitializeBalloonImageMatrix(rowsCount, colsCount);
            }

            for (int row = 0; row < rowsCount; row++)
            {
                for (int col = 0; col < colsCount; col++)
                {
                    var colorNumber = matrix[row, col].IsPopped ? 0 : matrix[row, col].Number;
                    var sourcePath = string.Format(this.Resources.ImagePathTemplate, this.Resources.Colors[colorNumber]);
                    this.balloons[row, col].SetSource(sourcePath);
                }
            }

            this.Window.UserMoves = 3.ToString();
        }