Black Jack using Windows Workflow Part 3
Here is a screenshot of the workflow for my Black Jack game using Windows Workflow Foundation. I’ve changed some of the names from my design but as you can see it looks a lot better.

Important to note is that an event driven activity can have multiple outcomes. If you look at the DrawCard event driven activity in the PlayersTurn you’ll see it redirects either to the PlayersTurn again or to FinishGame. This is because I evaluate the player’s hand when he draws a card and if he’s under 21 then he’s still in the game otherwise he went bust and the game is over.
It’s slightly irritating that you can’t have any finalization code in your Terminating State. Initially I wanted to put my evaluation code here but because I need to check the player’s hand value when he draws a card this became unnecessary. I also wanted to congratulate the user from the workflow but I realised that was an implementation concern and should be done from the WorkflowCompleted event (I should be able to pass some arguments back saying who the winner was).
I need to tell you all about the differences between a CodeCondition and a RuleConditionReference (used for evaluating expressions in loops and IF statements) and why the RuleConditionReference kicks ass. But that’ll have to wait until the next part of this Black Jack adventure.


