BizVB

Live blogging a XAML project with CodePlex - handling failure

I bet you all think that I mean failing at writing  the game, didn't ya?  Hmm?  Ha!  Not so fast my friend, I mean handling the last requirement in the project - failing the press the correct letter before the letterbox hits the bottom of the screen.

So what I want to do is check on timer click of the letter has hit the bottom, and if it has then fire off a new message (Oh no instead of Wow) and get a net letter at the top,  Should be good enough for a three year old, I figure.  As I get better in XAML I can make more features, right?

To start off I will modify the ShowWow so that it accepts a TextBlock and renders its transform no matter what it is.  I changed the name of the function to ShowMessage and used the VB refactoring feature to change all references.  Then I altered the signature to accept a textblock as a parameter, and used that object in the code instead of WowTextblock.  Finally, I changed the calling function so that it passes un WowTextblock.  Sounds like a lot, but it just took a second.  ShowMessage now looks like this:

Public Sub ShowMessage(ByVal blockToTransform As TextBlock)
    'Make an animation for the scale
    Dim blockAnimation As New DoubleAnimation(0, 100, New Duration(New TimeSpan(0, 0, 3)))
    'Make another for the opacity
    Dim blockOpacity As New DoubleAnimation(1.0, 0.0, New Duration(New TimeSpan(0, 0, 3)))
    'Go grab the ScaleTransformation from the XAML and se tthe properties
    Dim blockTransform As ScaleTransform = DirectCast(blockToTransform.RenderTransform, ScaleTransform)
    blockTransform.CenterX = 11
    blockTransform.CenterY = 7
    blockTransform.ScaleX = 1
    blockTransform.ScaleY = 1
    'Then run all of the animations
    blockTransform.BeginAnimation(ScaleTransform.ScaleXProperty, blockAnimation)
    blockTransform.BeginAnimation(ScaleTransform.ScaleYProperty, blockAnimation)
    blockToTransform.BeginAnimation(TextBlock.OpacityProperty, blockOpacity)
End Sub


Alright, now I need to add a XAML element that has the Oh No! text in it.  I think I'll make it red.  I just copied the Wow! textblock and edited it.

<TextBlock x:Name="ohNoTextblock" Opacity="0" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Text="Oh no!" Visibility="visible">
    <TextBlock.RenderTransform>
        <ScaleTransform></ScaleTransform>
    </TextBlock.RenderTransform>
</TextBlock>


So now clockCheck looks like this:

Private Sub ClockCheck() Handles gameClock.Tick
    letterBoxTop = letterBoxTop + 10
    letterBox.Margin = New Thickness(letterBoxLeft, letterBoxTop, 0, 0)
    'Check to see if it is at the bottom
    Dim bottom As Double = gameBoard.Height
    If letterBoxTop + letterBox.Height > bottom Then
        'It has hit the bottom.  
        gameClock.Stop()
        scoreCount = scoreCount - 1
        'Fire the Oh No message
        ohNoTextblock.Opacity = 100
        ShowMessage(ohNoTextblock)
        'Restart the letter
        SetupLetterBox()
        gameClock.Start()
    End If
End Sub


And there we are!  Kid tested, mother approved too.  I'll post a video of Adam playing it this weekend, when I do my post about further enhancements.  Also, I will check in the changes to CodePlex right now before I forget.

To create a release in CodePlex, I just had to go to the releases tab and Add a New Release.  That gives me a really nice little mini-wiki for the release, and an upload facility for the binary.  I made a few notes and loaded it up!  CodePlex is a really nice, simple facility for opensource work - better than SourceForge for simple projects.  I like it a lot.

I hope this little series has been helpful to everyone - it sure has for me.  I think that XAML is likely the future of Microsoft UI programming, so it behooves us all to get our feet wet as soon as we can, to make the curve less steep when our projects make the move.  Please leave any thoughts in the comments.

Comments are closed
Mastodon