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.
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
- The
__init__(self)
method is used as the constructor for a Python class. - It is possible to add custom parameters to the constructor by modifying the
__init__(self)
method’s parameters. - 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.
Click here to download the solution for this step.
¡Gracias por tus comentarios!
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.
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
- The
__init__(self)
method is used as the constructor for a Python class. - It is possible to add custom parameters to the constructor by modifying the
__init__(self)
method’s parameters. - 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.
Click here to download the solution for this step.