public void Constructor_Can_Drop_Reference()
        {
            var map = new Pillar[4, 4]
            {
                { new Pillar(0, 0, 100), new Pillar(1, 0, 100), new Pillar(2, 0, 1), new Pillar(3, 0, 100) },
                { new Pillar(0, 1, 100), new Pillar(1, 1, 100), new Pillar(2, 1, 2), new Pillar(3, 1, 100) },
                { new Pillar(0, 2, 100), new Pillar(1, 2, 100), new Pillar(2, 2, 3), new Pillar(3, 2, 100) },
                { new Pillar(0, 3, 100), new Pillar(1, 3, 100), new Pillar(2, 3, 4), new Pillar(3, 3, 100) },
            };
            var oldFrame = new BoardFrame(new Map(map));
            var actual   = new BoardFrame(oldFrame);
            int x        = 1;
            int y        = 2;

            var oldColoredPillar = new ColoredPillar(x, y, 4, ConsoleColor.Magenta, ConsoleColor.Black);

            oldFrame.SetInPosition(oldColoredPillar);

            Assert.IsFalse(ReferenceEquals(
                               oldFrame.GetFrom(x, y),
                               actual.GetFrom(x, y)),
                           $"oldframe[{x}, {y}] should not reference actual[{x}, {y}]");

            var oldFramePillar = oldFrame.GetFrom(x, y);

            Assert.That(oldFramePillar.X, Is.EqualTo(x), "oldFramePillar.X");
            Assert.That(oldFramePillar.Y, Is.EqualTo(y), "oldFramePillar.Y");
            Assert.That(oldFramePillar.Height, Is.EqualTo(4), "oldFramePillar.Height");

            var actualFramePillar = actual.GetFrom(x, y);

            Assert.That(actualFramePillar.X, Is.EqualTo(x), "actualFramePillar.X");
            Assert.That(actualFramePillar.Y, Is.EqualTo(y), "actualFramePillar.Y");
            Assert.That(actualFramePillar.Height, Is.EqualTo(100), "actualFramePillar.Height");
        }
        public bool ShowNextFrame()
        {
            Log.Debug($"ShowNextFrame() #{_displayIndex}");

            BoardFrame frame = _frames[_displayIndex];

            _view.Display(frame);

            _displayIndex++;

            return(_displayIndex < _frames.Length);
        }
        /// <summary>
        /// Increase the frame collection with one and
        /// initialize the last frame with the <see cref="Map"/> values.
        /// </summary>
        private void SwitchToNextFrame()
        {
            _setterIndex++;

            Log.Debug("");

            BoardFrame[] oldFrames = _frames;
            _frames = new BoardFrame[oldFrames.Length + 1];

            for (int i = 0; i < oldFrames.Length; i++)
            {
                _frames[i] = new BoardFrame(oldFrames[i]);
            }

            _frames[_frames.Length - 1] = new BoardFrame(oldFrames[oldFrames.Length - 1]);
        }
Beispiel #4
0
        public void Display(BoardFrame frame)
        {
            for (int y = 0; y < frame.Height; y++)
            {
                for (int x = 0; x < frame.Width; x++)
                {
                    ColoredPillar position = frame.GetFrom(x, y);

                    Console.Write(" ");
                    Console.BackgroundColor = position.BackGroundColor;
                    Console.ForegroundColor = position.FontColor;
                    Console.Write("{0, 3}", position.Height);
                    Console.ResetColor();
                    Console.Write(" |");
                }

                Console.WriteLine();
            }

            Console.WriteLine();
        }