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

Contenido del Curso

test project

test project

test

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 1
AVAILABLE TO ULTIMATE ONLY
We're sorry to hear that something went wrong. What happened?
some-alt