Example #1
0
        public void SnakeGame_GameIteration_SnakeCrash()
        {
            Position head = new Position(), tail = new Position();

            eCellType[] field = new eCellType[64];

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

            FieldMatrix.SetCellTypeByPosition(field, new Position()
            {
                row = head.row, col = (byte)(head.col + 1)
            }, eCellType.SnakeDown);

            Assert.ThrowsException <CrashedInSnakeException>(() => GameEngine.ApplyChange(field, head, tail, currentDirection, nextDirection, out bool expanded), "Did not crash moving to the right");

            FieldMatrix.Seed(field, head, tail);

            FieldMatrix.SetCellTypeByPosition(field, new Position()
            {
                row = (byte)(head.row + 1), col = head.col
            }, eCellType.SnakeHead);
            nextDirection = eDirectionType.Down;

            Assert.ThrowsException <CrashedInSnakeException>(() => GameEngine.ApplyChange(field, head, tail, currentDirection, nextDirection, out bool expanded), "Did not crash moving down");
        }