Click here to Skip to main content
15,879,095 members
Articles / Programming Languages / C#

My First Windows 8 Application – Metro Puzzle

Rate me:
Please Sign up or sign in to vote.
4.83/5 (52 votes)
7 Apr 2012Ms-PL4 min read 128.3K   6.4K   97  
My first Windows 8 application, Metro Puzzle.
<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="using:PuzzleMetro" x:Class="PuzzleMetro.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="768" d:DesignWidth="1366" Loaded="UserControl_Loaded" PointerPressed="UserControl_PointerPressed">

    <Grid x:Name="LayoutRoot"  Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="98"/>
            <RowDefinition Height="21*"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="15"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="16"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="18"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="195"/>

        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="30"/>
            <ColumnDefinition Width="100*"/>
            <ColumnDefinition Width="22"/>
            <ColumnDefinition Width="100*"/>
            <ColumnDefinition Width="18"/>
            <ColumnDefinition Width="100*"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="102*"/>
            <ColumnDefinition Width="875*"/>
        </Grid.ColumnDefinitions>
        <!--ContentPanel - place additional content here-->
        <Canvas x:Name="ContentPanel" Grid.ColumnSpan="9" Grid.RowSpan="10">
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="390" Canvas.Top="474"  />
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="270" Canvas.Top="474" >
                <TextBlock Text="15" Tag="15" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="150" Canvas.Top="473" >
                <TextBlock Text="14" Tag="14" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="30" Canvas.Top="474" >
                <TextBlock Text="13" Tag="13" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="390" Canvas.Top="356" >
                <TextBlock Text="12" Tag="12" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="270" Canvas.Top="356" >
                <TextBlock Text="11" Tag="11" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="150" Canvas.Top="356">
                <TextBlock Text="10" Tag="10" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="30" Canvas.Top="356">
                <TextBlock Text="9" Tag="9" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="390" Canvas.Top="238" >
                <TextBlock Text="8" Tag="8" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="270" Canvas.Top="238" >
                <TextBlock Text="7" Tag="7" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="150" Canvas.Top="238"  >
                <TextBlock Text="6" Tag="6" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="30" Canvas.Top="238" >
                <TextBlock Text="5" Tag="5" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="390" Canvas.Top="120" >
                <TextBlock Text="4" Tag="4" Style="{StaticResource NumberStyle}" />
            </Border>

            <Border Style="{StaticResource BorderStyle}" Canvas.Left="270" Canvas.Top="120" >
                <TextBlock Text="3" Tag="3" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="150" Canvas.Top="120" >
                <TextBlock Text="2" Tag="2" Style="{StaticResource NumberStyle}" />
            </Border>
            <Border Style="{StaticResource BorderStyle}" Canvas.Left="30" Canvas.Top="120" >
                <TextBlock Text="1" Tag="1" Style="{StaticResource NumberStyle}" />
            </Border>

            <TextBlock Canvas.Left="273" Style="{StaticResource H3Style}" Text="Moves:" Canvas.Top="62" Margin="0" />
            <TextBlock Canvas.Left="352" x:Name="txtMoves" Text="0" Canvas.Top="62" Style="{StaticResource H2Style}"/>
            <TextBlock Canvas.Left="33"  Text="Time:"   Style="{StaticResource H3Style}" Canvas.Top="62" Margin="0"/>
            <TextBlock Canvas.Left="94" x:Name="txtTime" Text="00:00:00" Style="{StaticResource H2Style}" Canvas.Top="62"/>
            <TextBlock  Style="{StaticResource H1Style}" Text="{StaticResource AppName}" Height="51" Margin="0" Canvas.Left="8" Canvas.Top="8" />
            
            <TextBlock Height="488" Canvas.Left="614" TextWrapping="Wrap" Text="The 15-puzzle (also called Gem Puzzle, Boss Puzzle, Game of Fifteen, Mystic Square and many others) is a sliding puzzle that consists of a frame of numbered square tiles in random order with one tile missing. The puzzle also exists in other sizes, particularly the smaller 8-puzzle. If the size is 3×3 tiles, the puzzle is called the 8-puzzle or 9-puzzle, and if 4×4 tiles, the puzzle is called the 15-puzzle or 16-puzzle named, respectively, for the number of tiles and the number of spaces. The object of the puzzle is to place the tiles in order (see diagram) by making sliding moves that use the empty space." Canvas.Top="120" Width="609" FontSize="18" Style="{StaticResource TextStyle}" LineHeight="36"/>
            <TextBlock Canvas.Left="614" TextWrapping="Wrap" Text="What is Puzzle 15?" Canvas.Top="62" Style="{StaticResource H3Style}"/>
        </Canvas>

        <Grid Grid.ColumnSpan="9" Grid.RowSpan="10" x:Name="WinGrid" Visibility="Collapsed"  Background="#BFE6E6E6">
            <TextBlock HorizontalAlignment="Center" Text="Congratulations You Won!!!" Margin="8,92,8,568" FontSize="72" FontWeight="Bold" />
            <Button x:Name="btnGame" Click="btnGame_Click" Content="Again" Margin="304,366,0,286" Height="116" Width="258" FontSize="24" />
            <Button x:Name="btnShare" Click="btnShare_Click" Content="Share Your Win" Margin="850,366,0,286" Height="116" Width="258" FontSize="24" />
        </Grid>
<ApplicationBar Grid.ColumnSpan="9" Height="88" Grid.Row="9" VerticalAlignment="Bottom">
    <StackPanel Orientation="Horizontal">
        <Button Content="Exit" Style="{StaticResource BackButtonStyle}" x:Name="btnBack" Click="btnBack_Click" />
        <Button Content="New Game" Style="{StaticResource RefreshButtonStyle}" x:Name="btnnewGame" Click="btnnewGame_Click"/>
    </StackPanel>
</ApplicationBar>

    </Grid>

</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Sela
Israel Israel
Shai Raiten is VS ALM MVP, currently working for Sela Group as a ALM senior consultant and trainer specializes in Microsoft technologies especially Team System and .NET technology. He is currently consulting in various enterprises in Israel, planning and analysis Load and performance problems using Team System, building Team System customizations and adjusts ALM processes for enterprises. Shai is known as one of the top Team System experts in Israel. He conducts lectures and workshops for developers\QA and enterprises who want to specialize in Team System.

My Blog: http://blogs.microsoft.co.il/blogs/shair/

Comments and Discussions