Design Patterns and Video Games

The purpose of this blog is to present solutions based on Design Patterns illustrated by the development of video games.
0 comments
20 entries
Advertisement
phylyp
September 28, 2020
Discover Python and Patterns (11): Class

I propose to introduce Python classes to implement the Game Loop pattern. Using these tools, I show how to refactor the code in the previous post to get a more robust and readable program.

This post is part of the Discover Python and Patterns series

Create a class with Python

In this post, I introduc…

5,959 views
phylyp
July 14, 2020
Discover Python and Patterns (10): Keyboard

Thanks to the Pygame library we installed in the previous post, we can draw 2D graphics. In this post, I propose to introduce controls with the keyboard as well as some improvements like window centering and frame rate handling.

This post is part of the Discover Python and Patterns series

Keyboard e…
3,764 views
phylyp
May 02, 2020
Discover Python and Patterns (9): Pygame

In the previous posts, I introduced enough of Python and patterns to start creating games with graphics using the Pygame library.

This post is part of the Discover Python and Patterns series

Install Pygame

Pygame is a popular library for creating 2D games. Like the random library we used before, the …

5,814 views
phylyp
March 11, 2020
Discover Python and Patterns (8): Game Loop pattern

The time has come to see our first design pattern: the Game Loop Pattern! This pattern can give us many good ideas to refactor our game in a very effective way.

This post is part of the Discover Python and Patterns series

The Game Loop pattern

There is several version of the Game Loop pattern. Here I…

6,797 views
phylyp
February 26, 2020
Discover Python and Patterns (7): Functions

It is now time to organize/refactor our code! When you begin, this is a strange process since the final code does the same as before. However, refactoring is the only way to create a code easy to maintain and expand.

This post is part of the Discover Python and Patterns series

Define a function

In th…

4,063 views
phylyp
January 03, 2020
Discover Python and Patterns (6): Random

In the previous post, the magic number is always the same. I propose now to introduce random numbers to change the magic number every time we launch the game. I also present imports and more on integers.

This post is part of the Discover Python and Patterns series

Library import

In the previous progr…

3,372 views
phylyp
December 31, 2019
Discover Python and Patterns (5): Integers

In previous posts, I only used strings and booleans. In this one, I use a new data type called “int” (for integer) that allows the storage and computation of natural numbers (numbers without a decimal part). I use them to create the famous “guess the number” game!

This post is part of the Discover P…

2,718 views
Advertisement
phylyp
December 11, 2019
Discover Python and Patterns (4): Loops

The previous game only allows one try: you have to restart it to propose another word. In this post, I introduce loops, and I use them to repeat the game until the player finds the magic word.

This post is part of the Discover Python and Patterns series

While statement

The while statement allows to r…

3,380 views
phylyp
November 24, 2019
Discover Python and Patterns (3): Branching

Programs in the previous post always lead to the same result. Here, I show you the basics of branching, or how to change the flow of a program depending on cases.

If statement

If we want to display a message when the player types a specific word, we can use the following syntax:

word = input("Enter t…
3,058 views
phylyp
November 14, 2019
Discover Python and Patterns (2): Basic interaction

In the first post, we saw how to install an IDE and how to display a message; it is time to add some interaction with the player.

Wait for a key

Create a new python program and type the following line:

input("Press Enter to continue...")

If you run the program, you get the fol…

3,931 views
Advertisement

Popular Blogs

shawnhar
Generalist
101 Entries
14 Followers
klg71
Generalist
57 Entries
2 Followers
ApochPiQ
Generalist
628 Entries
45 Followers
15 Entries
14 Followers
johnhattan
Programmer
1,277 Entries
50 Followers
Advertisement