Cars SmashPack©
My 2 year old son is currently on a Cars phase! From the morning he wakes up till the evening he goes to bed all he wants to watch is Cars! I have been playing around with BabySmash and decided to modify it a little so that it randomly create characters from the cars movie (if he pressed the non alphanumerical keys). Unfortunately I am not going to release the modified code (The pictures might be copyright protected) but I will show what I did to make it work… here is a screen capture of the application running:
Before you begin, please read the following blog entry:
Learning WPF with BabySmash - Factories, Interfaces, Delegates and Lambdas, oh my!
Currently, BabySmash creates UserControls for each “cool” shapes using the FigureGenerator. I created a UserControl for each “character”. Here is the UserControl
<UserControl x:Class="BabySmash.McQueen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Image x:Name="Face" Source="Images\McQueen.png" Stretch="Uniform"/>
</Grid>
</UserControl>
All this UserControl does is render the picture of the character
public partial class McQueen : IHasFace
{
public McQueen(Brush x)
: this()
{
//this.Body.Fill = x;
}
public McQueen()
{
InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
Each UserControl also derives from IHasFace and must have a constuctor that can take a Brush as a parameter!
Now that we have all our characters, all that is left to do is modify the FigureGenerator
private static readonly List<KeyValuePair<string, BrushControlFunc>> hashTableOfFigureGenerators = new List<KeyValuePair<string, BrushControlFunc>>
{
new KeyValuePair<string, BrushControlFunc>("Mater", x => new Mater(x) ),
new KeyValuePair<string, BrushControlFunc>("McQueen", x => new McQueen(x) ),
new KeyValuePair<string, BrushControlFunc>("Tractor", x => new Tractor(x) ),
new KeyValuePair<string, BrushControlFunc>("Hudson", x => new Hudson(x) ),
new KeyValuePair<string, BrushControlFunc>("Red", x => new Red(x) ),
new KeyValuePair<string, BrushControlFunc>("Sally", x => new Sally(x) ),
new KeyValuePair<string, BrushControlFunc>("Mack", x => new Mack(x) ),
new KeyValuePair<string, BrushControlFunc>("Luigi", x => new Luigi(x) ),
new KeyValuePair<string, BrushControlFunc>("Chick", x => new Chick(x) ),
};
And that is it!!! Now you have a hacked SmashPack©