Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
test | test project
test project
course content

Course Content

test project

test project

booktest

TUTORIAL HOW TO INSTALL VS

Introduction

In this project we will learn how to the Snake game using Python. By the end of this project you will have learnt the following:

  • Importing and using libraries in Python;
  • Setting up Pygame using an Object-Oriented approach;
  • Problem-Solving, writing optimized and readable code;
  • Various tip and tricks related to Python;
  • Game development using Pygame.

Step 1

The first step is to import the pygame library and create an empty class called ‘Game’.

The pygame library will help us in creating the game and we will use the ‘Game’ class for structing the game in an object-oriented manner so that code is neater and it’s easier to control.

copy

Step 2

We want to be able to pass values to the constructor so that we can set up the game’s basic properties in the constructor.

Task

Remove the pass keyword. Create a constructor for the class ‘Game’ and add the parameters title, width and height to the constructor (in addition to self). Initialize pygame in the Game class constructor.

Hint

  1. The __init__(self) method is used as the constructor for a Python class.
  2. It is possible to add custom parameters to the constructor by modifying the __init__(self) method’s parameters.
  3. Pygame has an init method which can be used for initializing pygame and creating a window.

Task code

Copy and modify this code part via your IDE.

copy

Click here to download the solution for this step.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

TUTORIAL HOW TO INSTALL VS

Introduction

In this project we will learn how to the Snake game using Python. By the end of this project you will have learnt the following:

  • Importing and using libraries in Python;
  • Setting up Pygame using an Object-Oriented approach;
  • Problem-Solving, writing optimized and readable code;
  • Various tip and tricks related to Python;
  • Game development using Pygame.

Step 1

The first step is to import the pygame library and create an empty class called ‘Game’.

The pygame library will help us in creating the game and we will use the ‘Game’ class for structing the game in an object-oriented manner so that code is neater and it’s easier to control.

copy

Step 2

We want to be able to pass values to the constructor so that we can set up the game’s basic properties in the constructor.

Task

Remove the pass keyword. Create a constructor for the class ‘Game’ and add the parameters title, width and height to the constructor (in addition to self). Initialize pygame in the Game class constructor.

Hint

  1. The __init__(self) method is used as the constructor for a Python class.
  2. It is possible to add custom parameters to the constructor by modifying the __init__(self) method’s parameters.
  3. Pygame has an init method which can be used for initializing pygame and creating a window.

Task code

Copy and modify this code part via your IDE.

copy

Click here to download the solution for this step.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 1
AVAILABLE TO ULTIMATE ONLY
some-alt