ARTICLE

Slide Puzzle game in WPF

Posted by Sapna Articles | WPF using VB.NET November 12, 2010
In this article, I am trying to create a slide puzzle game in WPF Application.
 
Reader Level:

This article is about a simple 9 piece puzzle game using ImageBrush. In the puzzle one square is blank, and the image portions in the other 8 squares were randomly scattered.

You had to try and recreate the whole image, by sliding the image portion squares into the blank space, and repeating this until you had the whole image again. Lets see the code snippets for the puzzle:

Code Sample

<Window x:Class="SlideGame.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <DockPanel LastChildFill="True">
 
        <Button x:Name="btnPickImage" Content="Pick Image" Click="btnPickImage_Click" DockPanel.Dock="Top"/>
 
       <!-- Puzzle -->   
       
<Grid x:Name="gridMain">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
 
       </Grid>
    </DockPanel>
</
Window>

Puzzle Output

puzzle1.gif

Here we solve the above puzzle and the recreated picture look like as:

puzzle2.gif

I hope you will enjoy this.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor