Beispiel #1
0
        public void SnakeGame_PlaceNextPiece()
        {
            Position head = new Position(), tail = new Position();

            eCellType[] field = new eCellType[64];

            FieldMatrix.Seed(field, head, tail);
            var rnd = new Random();

            while (field.Any(f => f == eCellType.None))
            {
                var currentEmpty = field.Count(f => f == eCellType.None);

                FieldMatrix.PlaceNextPiece(field, (byte)rnd.Next());

                var nextEmpty = field.Count(f => f == eCellType.None);

                Assert.AreEqual(currentEmpty - 1, nextEmpty, "Did not place next piece");
            }

            Assert.ThrowsException <GameCompletedException>(() => FieldMatrix.PlaceNextPiece(field, 10));
        }
Beispiel #2
0
        public void SnakeGame_GameIteration_TurnUp()
        {
            Position head = new Position(), tail = new Position();

            eCellType[] field = new eCellType[64];

            FieldMatrix.Seed(field, head, tail);
            eDirectionType currentDirection = eDirectionType.None, nextDirection = eDirectionType.Up;

            GameEngine.ApplyChange(field, head, tail, currentDirection, nextDirection, out bool expanded);

            Assert.AreEqual(3, field.Count(c => c != eCellType.None));

            Assert.AreEqual(eCellType.SnakeRight, field[TestOffset(3, 3)], "Tail did not move to the right");
            Assert.AreEqual(eCellType.SnakeUp, field[TestOffset(3, 4)], "Body did not move to the right");
            Assert.AreEqual(eCellType.SnakeHead, field[TestOffset(2, 4)], "Head did not move up");
        }
Beispiel #3
0
        public void SnakeGame_GameIteration_Expanded()
        {
            Position head = new Position(), tail = new Position();

            eCellType[] field = new eCellType[64];

            FieldMatrix.Seed(field, head, tail);

            field[TestOffset(3, 5)] = eCellType.NextPart;
            eDirectionType currentDirection = eDirectionType.None, nextDirection = eDirectionType.Right;

            GameEngine.ApplyChange(field, head, tail, currentDirection, nextDirection, out bool expanded);

            Assert.IsTrue(expanded, "Snake did not expand");

            Assert.AreEqual(4, field.Count(c => c != eCellType.None));

            Assert.AreEqual(eCellType.SnakeRight, field[TestOffset(3, 2)], "Tail moved");
            Assert.AreEqual(eCellType.SnakeRight, field[TestOffset(3, 3)], "Body moved");
            Assert.AreEqual(eCellType.SnakeRight, field[TestOffset(3, 4)], "Body moved");
            Assert.AreEqual(eCellType.SnakeHead, field[TestOffset(3, 5)], "Head did not extend");
        }