Example #1
0
        public void CheckIfConsoleViewIsCreatedCorrect()
        {
            ConsoleView testView = new ConsoleView(5, 5, ConsoleColor.Green, ConsoleColor.Black, '*');
            bool arePropertiesSetCorrectly = (testView.X == 5 && testView.Y == 5 &&
                                              testView.Foreground == ConsoleColor.Green &&
                                                testView.Background == ConsoleColor.Black && testView.Symbol == '*');

            Assert.AreEqual(arePropertiesSetCorrectly, true, string.Format("Expected to receive ConsoleView with x=5, y=5, foreground=green, background=black, symbol=*. Received x={0}, y={1}, foreground={2}, background={3}, symbol={4}", testView.X, testView.Y, testView.Foreground, testView.Background, testView.Symbol));
        }
Example #2
0
        public void CheckIfConsoleViewIsDrawCorrectly()
        {
            ConsoleView testView = new ConsoleView(0, 0, ConsoleColor.Black, ConsoleColor.White, '*');

            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                testView.Draw();

                string expected =
                    string.Format("*");
                Assert.AreEqual<string>(expected, sw.ToString(), string.Format("Expected ConsoleView to draw \'*\' symbol. Received {0}",sw.ToString()));
            }
        }
Example #3
0
        /// <summary>
        /// A method for creating new <see cref="ICellView" /> derived classes. Concrete implementations should
        /// implement this method and return the proper type of object for their rendering environment.
        /// This method is used by <see cref="Renderer.CreateCellViews" /> to get the right type of object needed.
        /// </summary>
        /// <param name="cell">The <see cref="ICell" /> object that will get displayed by returned object.</param>
        /// <param name="isBackgroundChanged">A boolean.</param>
        /// <returns>CellView object to be added to Renderer's list of controlled objects.</returns>
        protected override ICellView CreateCellView(ICell cell, bool isBackgroundChanged)
        {
            ICellView view;
            switch (cell.CellType)
            {
                case CellType.Bomb:
                    view = new ConsoleView(cell.X, cell.Y, ConsoleColor.Red, isBackgroundChanged ? ConsoleColor.Green : ConsoleColor.Blue, (char)cell.CellView);
                    break;
                case CellType.BlownCell:
                    view = new ConsoleView(cell.X, cell.Y, ConsoleColor.Red, ConsoleColor.Gray, '*');
                    break;
                case CellType.EmptyCell:
                    view = new ConsoleView(cell.X, cell.Y, ConsoleColor.Cyan, isBackgroundChanged ? ConsoleColor.Green : ConsoleColor.Blue, ' ');
                    break;
                default:
                    throw new NotImplementedException();
            }

            return view;
        }