Exemplo n.º 1
0
        public void FixBlock_BlockIsDrawnWhenFixed()
        {
            Field f = new Field(1,1);
            f.SetBlock(new Block(), new Vector2(0, 0));
            GameMechanics mech = new GameMechanics(f, new BlockFactory());
            mech.AdvanceIfPossible();

            Color? color = f.ColorAt(new Vector2(0, 0));
            Assert.IsNotNull(color);
        }
Exemplo n.º 2
0
        public void Test_ColorAt_OutOfBounds_RaisesException()
        {
            Field subject = new Field(2, 2);

            try
            {
                subject.ColorAt(new Vector2(2, 0));
                Assert.Fail();
            }
            catch (Exception) { }
        }
Exemplo n.º 3
0
        public void Test_ColorAt_WhenBlockIsThereWithColor_ReturnsBlockColorAt()
        {
            Field subject = new Field(10, 10);

            Mock<IBlock> block = new Mock<IBlock>();
            block.Setup(b => b.ColorAt(new Vector2(1, 2))).Returns(Color.White);
            block.Setup(b => b.Width).Returns(2);
            block.Setup(b => b.Height).Returns(3);
            subject.SetBlock(block.Object, new Vector2(4, 4));

            Color? result = subject.ColorAt(new Vector2(5, 6));
            Assert.AreEqual(Color.White, result.Value);
        }
Exemplo n.º 4
0
        private void DrawField()
        {
            spriteBatch.Begin();

            drawEmptyBackground(spriteBatch);

            for (int x = 0; x < field.Width; x++)
            {
                for (int y = 0; y < field.Height; y++)
                {
                    Color?color = field.ColorAt(new Vector2(x, y));

                    if (color.HasValue)
                    {
                        spriteBatch.Draw(blockTexture, new Rectangle((int)x * blockTexture.Width, (int)y * blockTexture.Height, blockTexture.Width, blockTexture.Height), color.Value);
                    }
                }
            }

            spriteBatch.End();
        }
Exemplo n.º 5
0
        public void Test_ColorAt_WhenBlockIsThereAndNoColor_ItReturnsFieldColorAt()
        {
            Field subject = new Field(4, 4);
            Color white = Color.White;

            subject.SetContentsForTest(new Color?[,]
            { { null, null,  null,  null},
              { null, white, white, null },
              { null, white, white, null },
              { null, null,  null,  null} });

            Mock<IBlock> block = new Mock<IBlock>();
            Color? nullColor = null;

            block.Setup(b => b.Width).Returns(2);
            block.Setup(b => b.Height).Returns(2);
            block.Setup(b => b.ColorAt(new Vector2(0, 1))).Returns(nullColor);

            subject.SetBlock(block.Object, new Vector2(1, 1));

            Color? result = subject.ColorAt(new Vector2(1, 2));
            Assert.AreEqual(Color.White, result.Value);
        }
Exemplo n.º 6
0
        public void Test_SetContentsForTest()
        {
            Field subject = new Field(2, 2);

            subject.SetContentsForTest(new Color?[,] {
                { Color.Red, null },
                { null, Color.Blue }
            });

            Assert.AreEqual(Color.Red, subject.ColorAt(new Vector2(0, 0)));
            Assert.AreEqual(Color.Blue, subject.ColorAt(new Vector2(1, 1)));
            Assert.IsNull(subject.ColorAt(new Vector2(0, 1)));
            Assert.IsNull(subject.ColorAt(new Vector2(1, 0)));
        }
Exemplo n.º 7
0
 public void FixSquareBlockTest()
 {
     Field field = new Field( 2, 10 );
     IBlock block = new Block();
     block.Grid [ 0 ] [ 0 ] = Color.Tomato;
     block.Grid [ 0 ] [ 1 ] = Color.Tomato;
     block.Grid [ 1 ] [ 0 ] = Color.Tomato;
     block.Grid [ 1 ] [ 1 ] = Color.Tomato;
     field.SetBlock( block, new Point( 0, 0 ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 0, 9 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 1, 9 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 0, 8 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 1, 8 ) ) );
     field.FixBlock();
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 0, 9 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 1, 9 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 0, 8 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 1, 8 ) ) );
 }
Exemplo n.º 8
0
        public void Test_ColorAt_WhenNoBlockIsThere_ReturnsNull()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(), new Vector2(3, 4));

            Assert.IsNull(subject.ColorAt(new Vector2(3, 3)));
        }
Exemplo n.º 9
0
 public void Test_ColorAt_WhenBlockIsNull_ReturnsNull()
 {
     Field subject = new Field(10, 10);
     Assert.IsNull(subject.ColorAt(new Vector2(3, 3)));
 }