Screen Layout

This project uses a similar window setup to the project of Chapter 2. This requires the member variables mainWindow, canvas, and label. It also defines two Rectangles (tongue and snowflake) that will also be part of the layout. The animation effect of the game will be achieved by moving the positions of these rectangles.

You will also see a group of int variables:

int tongueLeftPosition = 150;
int snowflakeLeftPosition = 150;
int snowflakeTopPosition = 50;
int tongueWidth = 30;

These are used to manage the position of those rectangles in the game, as well as to define the size of the tongue and snowflake.

The project uses two timers: one to control the tongue, which is called every 30 milliseconds, and another that is responsible for the movement of the snowflake.

The apparently random movement of the snowflake uses a random number generator:

Random randomNumberGenerator = new Random();

One instance of this class is created, and every time we need a new random number, we can ask for one.

Note

These numbers are not truly random, they are actually in a sequence and are an example of pseudorandom numbers. If you are interested, you can find more information on pseudorandom number generation here: http://en.wikipedia.org/wiki/Pseudorandom_number_generator.

Figure 3-3 shows the structure of the screen. You can see how the background, label, and two Rectangles make up the items to be displayed.

Figure 3-3. Screen Objects

The SetupUI method, which creates this structure, is quite similar ...

Get Getting Started with .NET Gadgeteer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.