public void DrawHalfEmptyMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 0, 0, 0, 2, 3, 4, 2, 3, 4, 0 },
                { 1, 1, 2, 2, 4, 4, 4, 0, 4, 1 },
                { 2, 0, 4, 1, 3, 0, 2, 3, 4, 1 },
                { 2, 3, 0, 3, 3, 0, 2, 3, 1, 0 },
                { 0, 1, 2, 2, 3, 0, 2, 3, 4, 1 }
            };

            string actualString = FieldToString.Draw(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 1 2 3 4 5 6 7 8 9 ");
            expected.AppendLine("   ---------------------");
            expected.AppendLine("0 |       2 3 4 2 3 4   |");
            expected.AppendLine("1 | 1 1 2 2 4 4 4   4 1 |");
            expected.AppendLine("2 | 2   4 1 3   2 3 4 1 |");
            expected.AppendLine("3 | 2 3   3 3   2 3 1   |");
            expected.AppendLine("4 |   1 2 2 3   2 3 4 1 |");
            expected.AppendLine("   ---------------------");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
        public void DrawEmptyMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 }
            };

            string actualString = FieldToString.Draw(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 1 2 3 4 5 6 ");
            expected.AppendLine("   ---------------");
            expected.AppendLine("0 |               |");
            expected.AppendLine("1 |               |");
            expected.AppendLine("2 |               |");
            expected.AppendLine("3 |               |");
            expected.AppendLine("4 |               |");
            expected.AppendLine("5 |               |");
            expected.AppendLine("   ---------------");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
        public void DrawOneColumnMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 8 },
                { 1 },
                { 2 },
                { 2 },
                { 8 },
                { 8 },
                { 2 },
                { 8 }
            };

            string actualString = FieldToString.Draw(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 ");
            expected.AppendLine("   ---");
            expected.AppendLine("0 | 8 |");
            expected.AppendLine("1 | 1 |");
            expected.AppendLine("2 | 2 |");
            expected.AppendLine("3 | 2 |");
            expected.AppendLine("4 | 8 |");
            expected.AppendLine("5 | 8 |");
            expected.AppendLine("6 | 2 |");
            expected.AppendLine("7 | 8 |");
            expected.AppendLine("   ---");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
示例#4
0
        void Show(BaseField obj)
        {
            Colors colors = FieldToColors.Convert(obj);

            Console.BackgroundColor = colors.Background;
            Console.ForegroundColor = colors.Foreground;

            Console.Write(FieldToString.Convert(obj));

            Console.BackgroundColor = Colors.DefaultBackground;
            Console.ForegroundColor = Colors.DefaultForeground;
        }
        public void DrawOneRowMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 8, 5, 2, 2, 3, 4, 2, 3, 4, 5, 2 }
            };

            string actualString = FieldToString.Draw(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 1 2 3 4 5 6 7 8 9 10 ");
            expected.AppendLine("   -----------------------");
            expected.AppendLine("0 | 8 5 2 2 3 4 2 3 4 5 2 |");
            expected.AppendLine("   -----------------------");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
示例#6
0
        public GameEngine()
        {
            var rand                = new Random();
            var spawn               = new Spawner(rand);
            var validator           = new CoordinateValidator();
            var pointCalc           = new AxisPointCalculations();
            var correctPlacement    = new PlacementCorrection();
            var predatorSpecial     = new PredatorEssentials(validator, pointCalc, correctPlacement);
            var preySpecial         = new PreyEssentials(validator, correctPlacement);
            var standardMovement    = new Movement(rand, validator);
            var fieldToStrConverter = new FieldToString();

            _factory = new SavannaFactory
                           (validator, spawn, standardMovement, predatorSpecial, preySpecial);
            _field     = new Field();
            _displayer = new ConsoleFieldDisplayer(fieldToStrConverter);
            _user      = new ConsoleUserAddAnimals
                             (standardMovement, validator, predatorSpecial, preySpecial, spawn);
            _animalLists    = new AnimalLists();
            _assemblyLoader = new AssemblyLoader(validator, standardMovement, preySpecial, predatorSpecial);
        }
        public override void RenderGameFieldState(byte[,] fieldClone)
        {
            // the console is cleared only once - at first print of the field
            if (!this.isBackgroundChanged)
            {
                Console.BackgroundColor = ConsoleColor.White;
                Console.Clear();
                this.isBackgroundChanged = true;
            }

            // sets the buffer size to maximum possible, because when printing many lines the cursor gets out of the console and throws an exception
            Console.BufferHeight = short.MaxValue - 1;
            Console.ForegroundColor = ConsoleColor.Black;

            var fieldAsString = FieldToString.DrawEmptyFrame(fieldClone);
            var topCursorPosition = Console.CursorTop;
            Console.WriteLine(fieldAsString);
            var defaultConsoleForegroundColor = Console.ForegroundColor;

            for (int row = 0; row < fieldClone.GetLength(0); row++)
            {
                Console.SetCursorPosition(InitialLeftCursorPosition, topCursorPosition + InitialTopCursorPosition + row);

                for (int col = 0; col < fieldClone.GetLength(1); col++)
                {
                    if (fieldClone[row, col] == 0)
                    {
                        Console.Write("  ");
                        continue;
                    }

                    BaloonColor color = (BaloonColor)fieldClone[row, col];
                    Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), color.ToString());
                    Console.Write("♥ ");
                }
            }

            Console.SetCursorPosition(0, topCursorPosition + InitialTopCursorPosition + 2 + fieldClone.GetLength(0));
            Console.ForegroundColor = defaultConsoleForegroundColor;
        }
        public void DrawRegularMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 8, 5, 2, 2, 3, 4, 2, 3, 4, 5, 2 },
                { 1, 1, 2, 2, 4, 4, 4, 6, 4, 1, 2 },
                { 2, 1, 4, 1, 3, 4, 2, 3, 4, 1, 4 },
                { 2, 3, 7, 3, 3, 1, 2, 3, 1, 3, 7 },
                { 8, 1, 2, 2, 3, 9, 2, 3, 4, 1, 2 },
                { 8, 5, 2, 2, 3, 4, 2, 3, 4, 5, 2 },
                { 1, 1, 2, 2, 4, 4, 4, 6, 4, 1, 2 },
                { 2, 1, 4, 1, 3, 4, 2, 3, 4, 1, 4 },
                { 2, 3, 7, 3, 3, 1, 2, 3, 1, 3, 7 },
                { 8, 1, 2, 2, 3, 9, 2, 3, 4, 1, 2 }
            };
            string actualString = FieldToString.Draw(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 1 2 3 4 5 6 7 8 9 10 ");
            expected.AppendLine("   -----------------------");
            expected.AppendLine("0 | 8 5 2 2 3 4 2 3 4 5 2 |");
            expected.AppendLine("1 | 1 1 2 2 4 4 4 6 4 1 2 |");
            expected.AppendLine("2 | 2 1 4 1 3 4 2 3 4 1 4 |");
            expected.AppendLine("3 | 2 3 7 3 3 1 2 3 1 3 7 |");
            expected.AppendLine("4 | 8 1 2 2 3 9 2 3 4 1 2 |");
            expected.AppendLine("5 | 8 5 2 2 3 4 2 3 4 5 2 |");
            expected.AppendLine("6 | 1 1 2 2 4 4 4 6 4 1 2 |");
            expected.AppendLine("7 | 2 1 4 1 3 4 2 3 4 1 4 |");
            expected.AppendLine("8 | 2 3 7 3 3 1 2 3 1 3 7 |");
            expected.AppendLine("9 | 8 1 2 2 3 9 2 3 4 1 2 |");
            expected.AppendLine("   -----------------------");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
 public void DrawNullMatrixTest()
 {
     string matrixString = FieldToString.Draw(null);
 }
示例#10
0
        public virtual void RenderGameFieldState(byte[,] fieldClone)
        {
            var fieldAsString = FieldToString.Draw(fieldClone);

            Console.WriteLine(fieldAsString);
        }