Sigurd Snørteland



BabySmash7 – a wp7 children’s game (source code included)

BabySmash7 is a wp7 based version of Scott Hanselmans ‘BabySmash

“As babies smash on the phone, colored shapes, letters and numbers appear on the screen”

Go to the bottom of this article to find a link to the source code.

 

The MainPage.xaml is quite small and it’s dominated by the Canvas-object, where the colored shapes, letters and numbers will be added.

    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFA0A0A0" Offset="0"/>
                <GradientStop Color="Black" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>

        <TextBlock x:Name="PageTitle" Opacity="0.8" Text="BabySmash7" Foreground="#FF4C4C4C" Margin="21,10,0,28" Style="{StaticResource PhoneTextTitle1Style}"/>
        <MediaElement x:Name="media" Width="0" Height="0" Visibility="Collapsed" />
        <Canvas Name="figuresCanvas" Background="Transparent" MouseLeftButtonDown="figuresCanvas_MouseLeftButtonDown"/>
    </Grid>

The ‘figuresCanvas_MouseLeftButtonDown’ event is raised each time the user touches the screen.

        private void figuresCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            PageTitle.Visibility = Visibility.Collapsed;

            addRandomUserControl();
            playRandomSound();

            if (figuresCanvas.Children.Count > 6)
            {
                figuresCanvas.Children.RemoveAt(0);
            }
        }
        private void addRandomUserControl()
        {
            int randomNumber = Utils.RandomBetweenTwoNumbers(1, 4);
            //randomNumber = 1;
            switch (randomNumber)
            {
                case 1:
                    addRandomLetter();
                    break;
                case 2:
                    addRandomNumber();
                    break;
                case 3:
                    addRandomSymbol();
                    break;
                case 4:
                    addRandomSymbol();
                    break;
            }
        }

This method adds a random colored letter to the screen.

        private void addRandomLetter()
        {
            UserControl userControl = new UserControl();

            string[] numbers = new string[52] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
            int randomNumber = Utils.RandomBetweenTwoNumbers(0, 51);

            userControl = new Shapes.CoolLetter(numbers[randomNumber].ToString(), Utils.GetRandomColor());

            userControl.Width = 320;
            userControl.Height = 260;

            if (Orientation == PageOrientation.Landscape || Orientation == PageOrientation.LandscapeLeft || Orientation == PageOrientation.LandscapeRight)
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(550)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(250)));
            }
            else
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(260)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(550)));
            }

            figuresCanvas.Children.Add(userControl);
        }

This method adds a random colored number to the screen.

private void addRandomNumber()
        {
            UserControl userControl = new UserControl();

            int[] numbers = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int randomNumber = Utils.RandomBetweenTwoNumbers(0, 9);

            userControl = new Shapes.CoolLetter(numbers[randomNumber].ToString(), Utils.GetRandomColor());

            userControl.Width = 320;
            userControl.Height = 260;

            if (Orientation == PageOrientation.Landscape || Orientation == PageOrientation.LandscapeLeft || Orientation == PageOrientation.LandscapeRight)
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(600)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(250)));
            }
            else
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(300)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(550)));
            }

            figuresCanvas.Children.Add(userControl);
        }

This method adds a random colored symbol to the screen.

        private void addRandomSymbol()
        {
            UserControl userControl = new UserControl();

            int randomNumber = Utils.RandomBetweenTwoNumbers(1, 7);
            Color randomColor = Utils.GetRandomColor();

            switch (randomNumber)
            {
                case 1:
                    userControl = new Shapes.CoolCircle(Utils.GetGradientBrush(randomColor));
                    break;
                case 2:
                    userControl = new Shapes.CoolHeart(Utils.GetGradientBrush(randomColor));
                    break;
                case 3:
                    userControl = new Shapes.CoolHexagon(Utils.GetGradientBrush(randomColor));
                    break;
                case 4:
                    userControl = new Shapes.CoolRectangle(Utils.GetGradientBrush(randomColor));
                    break;
                case 5:
                    userControl = new Shapes.CoolSquare(Utils.GetGradientBrush(randomColor));
                    break;
                case 6:
                    userControl = new Shapes.CoolStar(Utils.GetGradientBrush(randomColor));
                    break;
                case 7:
                    userControl = new Shapes.CoolTrapezoid(Utils.GetGradientBrush(randomColor));
                    break;
                case 8:
                    userControl = new Shapes.CoolTriangle(Utils.GetGradientBrush(randomColor));
                    break;
            }

            userControl.Width = 100;   //Utils.RandomBetweenTwoNumbers(0, 100);
            userControl.Height = 100;  //Utils.RandomBetweenTwoNumbers(0, 100);

            //Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(this.ActualWidth - userControl.Width)));
            //Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(this.ActualHeight - userControl.Height)));

            if (Orientation == PageOrientation.Landscape || Orientation == PageOrientation.LandscapeLeft || Orientation == PageOrientation.LandscapeRight)
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(700)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(300)));
            }
            else
            {
                Canvas.SetLeft(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(200)));
                Canvas.SetTop(userControl, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(600)));
            }

            figuresCanvas.Children.Add(userControl);
        }

This method plays a random sound.

        private void playRandomSound()
        {
            int randomSound = Utils.RandomBetweenTwoNumbers(1, 7);
            media.Source = new Uri("Audio/" + randomSound + ".wav", UriKind.Relative);
            media.Play();
        }

Download the source code:

Advertisements

Trackbacks & Pingbacks

  1. Tweets that mention BabySmash7 – a wp7 children’s game (source code included) « Sigurd Snørteland -- Topsy.com pingbacked on 6 years, 4 months ago
  2. Media coverage « Sigurd Snørteland pingbacked on 6 years, 4 months ago
  3. Media coverage « Sigurd Snørteland pingbacked on 6 years, 4 months ago
  4. BabySmash7 – a wp7 children’s game (source code included) | www.nalli.net pingbacked on 6 years, 3 months ago

Comments

  1. * Mark Monster says:

    Are you planning to submit it to the Market Place?

    | Reply Posted 6 years, 4 months ago
    • * sigurdsnorteland says:

      Yes, I have added it as a free app. The marketplace status now is ‘Testing in progress’

      | Reply Posted 6 years, 4 months ago
  2. * Mike says:

    Hi,

    are you still supporting your (other) apps?
    On codeplex are some questions and issues, but it look like nobody cares 😦

    | Reply Posted 6 years, 4 months ago
  3. * Latest Games says:

    I almost never leave remarks, however i did a few searching
    and wound up here BabySmash7 – a wp7 childrens game (source code included) Sigurd Snørteland.
    And I do have a couple of questions for you if it’s allright. Is it only me or does it look like some of the responses look as if they are coming from brain dead visitors? 😛 And, if you are writing on other online sites, I’d like to
    keep up with anything fresh you have to post. Would you
    make a list of all of your shared pages like your
    linkedin profile, Facebook page or twitter feed?

    | Reply Posted 4 years, 5 months ago
  4. “BabySmash7 – a wp7 childrens game (source
    code included) Sigurd Snørteland” ended up being a terrific blog.

    In case it included alot more photos it could be perhaps even better.

    Cya -Zack

    | Reply Posted 4 years, 4 months ago
  5. “BabySmash7 – a wp7 childrens game (source code included) | Sigurd Snørteland” honestly enables me
    personally imagine a somewhat further. I actually treasured each and
    every single element of it. Thanks for your effort ,Stewart

    | Reply Posted 4 years, 4 months ago
  6. “BabySmash7 – a wp7 childrens game (source code included) | Sigurd Snørteland” was indeed definitely enjoyable and helpful!

    Within the present day universe that is very hard
    to carry out. Many thanks, Porfirio

    | Reply Posted 4 years, 4 months ago
  7. “BabySmash7 – a wp7 childrens game (source code included)
    Sigurd Snørteland” was in fact a fantastic blog. If merely there were even more websites
    such as this particular one on the cyberspace.

    Anyway, thank you for ur time, Gus

    | Reply Posted 4 years, 4 months ago
  8. * Everett says:

    If you are going for best contents like myself, only go
    to see this website every day for the reason that it presents feature contents, thanks

    | Reply Posted 3 years, 10 months ago
  9. Nice weblog here! Also your site rather a lot
    up very fast! What web host are you the usage of? Can I am getting your associate
    hyperlink for your host? I desire my web site loaded up as quickly
    as yours lol

    | Reply Posted 3 years, 3 months ago


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: