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©
Published Tuesday, July 29, 2008 2:41 PM by rudi
Filed under: , ,

Comments

# Cars SmashPack

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Tuesday, July 29, 2008 2:47 PM by DotNetKicks.com

# Dew Drop - July 30, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - July 30, 2008 | Alvin Ashcraft's Morning Dew

Wednesday, July 30, 2008 1:07 PM by Dew Drop - July 30, 2008 | Alvin Ashcraft's Morning Dew

# re: Cars SmashPack©

Hi:

My son passed this phase of life after watching Cars, approximately 2574389 times!

Monday, August 04, 2008 5:16 AM by AVEbrahimi

# re: Cars SmashPack©

Lol.. I just made exactly the same modifications except used other cartoon characters for my daugther.  Guess great minds think alike

Friday, August 08, 2008 3:46 AM by anonymous

# re: Cars SmashPack©

good idea, thanks

Monday, August 11, 2008 6:42 PM by funt