Click here to Skip to main content
15,894,017 members
Articles / Desktop Programming / WPF

WPF Grand Prix

Rate me:
Please Sign up or sign in to vote.
4.97/5 (110 votes)
14 Dec 2010CPOL10 min read 385.3K   6.3K   176  
An article showing how to create a race game using the powerful WPF capabilities
<Window x:Class="GrandPrix.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:uc="clr-namespace:GrandPrix"
        xmlns:track="clr-namespace:GrandPrix.TrackSegments"
        xmlns:local="clr-namespace:GrandPrix"
        xmlns:circuits="clr-namespace:GrandPrix.Circuits"
        Title="WPF Grand Prix" Height="600" Width="600"
        Icon="Images\Icon.png"
        WindowStyle="ToolWindow">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
        <Canvas x:Name="cnvTrack" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Canvas.RenderTransform>
                <TransformGroup>
                    <RotateTransform x:Name="cnvTrackRotation" CenterX="0" CenterY="0" Angle="0"/>
                    <TranslateTransform x:Name="cnvTrackTranslation" X="0" Y="0"/>
                    <ScaleTransform x:Name="cnvTrackScale" ScaleX="1.0" ScaleY="1.0" CenterX="0" CenterY="0"/>
                </TransformGroup>
            </Canvas.RenderTransform>
            <WrapPanel x:Name="pnlTrack" Width="1000" Height="1000">
                <WrapPanel.RenderTransform>
                    <TranslateTransform x:Name="pnlTrackTranslate" X="0" Y="0"/>
                </WrapPanel.RenderTransform>
            </WrapPanel>
            <Ellipse x:Name="midPoint" Width="16" Height="16" Fill="Red" Margin="0,0,0,0" Visibility="Hidden"/>
            <Ellipse x:Name="trackCenter" Width="16" Height="16" Fill="Green" Margin="0,0,0,0" Visibility="Hidden"/>
        </Canvas>
        <local:StatsPanel x:Name="statsPanel" Grid.Row="1"/>
        <Grid x:Name="grdMap">
            <circuits:Interlagos Width="800" Height="524" Opacity="0.5"/>
        </Grid>
        <StackPanel x:Name="pnlMessage" Visibility="Hidden" VerticalAlignment="Center">
            <Grid>
                <Image Source="Images\ChequeredFlag.png" HorizontalAlignment="Center" VerticalAlignment="Top" Stretch="None">
                </Image>
            </Grid>
            <Grid>
                <TextBlock x:Name="txtLargeMessage1" Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="40" FontWeight="Bold" Margin="5,5,0,0" TextWrapping="Wrap"/>
                <TextBlock x:Name="txtLargeMessage2" Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="40" FontWeight="Bold" Foreground="White" TextWrapping="Wrap"/>
            </Grid>
            <Grid>
                <TextBlock x:Name="txtSmallMessage1" Text="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold" Margin="2,2,0,0" TextWrapping="Wrap"/>
                <TextBlock x:Name="txtSmallMessage2" Text="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="White" TextWrapping="Wrap"/>
            </Grid>
            <Button x:Name="btnContinue" FontSize="20" Width="120" Click="btnContinue_Click">Continue</Button>
        </StackPanel>
    </Grid>
</Window>

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 Code Project Open License (CPOL)


Written By
Instructor / Trainer Alura Cursos Online
Brazil Brazil

Comments and Discussions