Press "Enter" to skip to content

Lesson 03.1: Creating the Solution and Game Screen

In this lesson, we’ll start to create the game. We’ll create the “solution”, to hold the files that will make the game, and we’ll create the beginnings of the game screen.

Summary

  • A “solution” is the files that make up a program.
  • A “solution” has at least one “project” – although, it can have more.
  • A “project” has related files that are grouped together, to make them easier to find/work with.
  • A “WPF project” holds a program’s screens, using XAML files.
  • “XAML” is used to define the format of “controls” (grids, buttons, text, etc.) on the screens of a program.
  • XAML controls are declared with “tags”.
  • XAML controls need opening tag and closing tags.
    • For example: “<Grid>” and “</Grid>
  • Some tags have “attributes” that you can set in the opening tag (such as the “Title” of a Window).
  • Sometimes, XAML controls are “child” controls. They are more detailed information for the “parent” control, and must be placed between the “parent” controls opening and closing tags.
  • If there are no items between an opening and closing XAML tag, you can make it self-closing by placing the “/” before the “>” in the tag. These is called “self-closing”.
    • For example: “<br/>“.
  • A common way to place objects on a XAML screen is to use a “grid”.
  • A grid has rows and columns. You can define their height and width as “Auto” (to make it the size of the controls inside of it), a number (to use a specific number of pixels), or “*” (to use all the remaining available space).
  • The top row is number “0”. The leftmost column is number “0”. As you move down (for rows), or to the right (for columns), the index increases by 1.
  • You place other controls on the screen by setting their row and column positions in the grid.

Source Code

MainWindow.xaml
<Window x:Class="WPFUI.MainWindow"
        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="clr-namespace:WPFUI"
        mc:Ignorable="d"
        Title="Scott's Awesome Game" Height="768" Width="1024">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="225"/>
        </Grid.RowDefinitions>
 
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
 
        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="Menu" Background="AliceBlue"/>
        <Label Grid.Row="1" Grid.Column="0" Content="Player Data" Background="Aquamarine"/>
        <Label Grid.Row="1" Grid.Column="1" Content="Game Data" Background="Beige"/>
        <Label Grid.Row="2" Grid.Column="0" Content="Inventory/Quests" Background="BurlyWood"/>
        <Label Grid.Row="2" Grid.Column="1" Content="Combat/Movement Controls" Background="Lavender"/>
 
    </Grid>
</Window>

NEXT LESSON: Lesson 03.2: Creating and Using a Subversion Repository

PREVIOUS LESSON: Lesson 02.1: Planning the Game

7 Comments

  1. Thomas
    Thomas 2022-05-06

    It would be nice if each lesson page had pagination; maybe just a previous and next button for lesson before and after the current one.

    • SOSCSRPG
      SOSCSRPG 2022-05-07

      Hi Thomas,

      I’m going to take a look at the lessons, now that there moved over to a new server. I’ll see if I can add “previous” and “next” links to the lessons. I looked for an easy (automated) way to do that before, but couldn’t find one.

  2. Dane Joe
    Dane Joe 2023-06-26

    Dude you are the bestest! Thank you so much!!

  3. yourboyypablo
    yourboyypablo 2024-02-08

    Dude Thank you so much for making these!! You’re awesome!

    • SOSCSRPG
      SOSCSRPG 2024-02-08

      You’re welcome! I’m glad to hear you’re enjoying them.

  4. Gary Woodward
    Gary Woodward 2024-04-03

    Scott

    I have a query, in the first part you downloaded the VS Community verson 2022, but in this one you start the programming process with VS version 2015. Are there any major differences between the 2?

    also are we using .NET(Framework) or just .NET?

    • SOSCSRPG
      SOSCSRPG 2024-04-04

      Hi Gary,

      I updated the installation lesson since people would be installing the latest version of Visual Studio, but didn’t redo the other videos and screenshots. The look of Visual Studio has changed a bit, but almost everything works the same.

      The big difference is when creating the projects, and making sure you select the correct version (as you noticed). It’s probably best to use .NET 8.0, the latest version. The only known problems are with the .NET and .NET Core families. For a while, the images may not display, due to a change in how .NET Core and .NET work. However, after the changes in Lesson 14.3, the images should display in all .NET families.

      The important thing is to make sure all of your projects use the same .NET family/version. You can’t mix .NET Framework and .NET (or .NET Core) in the same project.

Leave a Reply

Your email address will not be published. Required fields are marked *