We may earn an affiliate commission when you visit our partners.
Course image
Maurício Aniche

Did you just learn how to program in Python and needs to practice a bit more? Are you looking for some mildly complex project to challenge your skills? In this Python 102 course, we'll implement a text-based pac-game together, from scratch. Throughout the videos, we'll go together through all the challenges of implementing a game (how to design the map, how to move the characters, how to understand that the game is over) while exercising all the basics of the Python language.

This entire course is basically a live coding session. You will see:

Read more

Did you just learn how to program in Python and needs to practice a bit more? Are you looking for some mildly complex project to challenge your skills? In this Python 102 course, we'll implement a text-based pac-game together, from scratch. Throughout the videos, we'll go together through all the challenges of implementing a game (how to design the map, how to move the characters, how to understand that the game is over) while exercising all the basics of the Python language.

This entire course is basically a live coding session. You will see:

  • How to create simple data structures to store things like the map and game points

  • How to write complex ifs to take the different game decisions

  • How to properly use loops, e.g., to control the main game loop

  • How to get data from the keyboard and react to it

  • How to test your program using basic automated unit testing

  • How to make mistakes, understand why your program is failing, and how to learn from the mistakes

I speak out loud every step I take, including my mistakes. In the end of every video, you are asked to implement the pac-man yourself. Did you get lost? No worries, you can find the source code of the game at every point in time in the resources of the course.

If you are looking for a nice way to reinforce your recently acquired Python skills, this is the course for you.

Enroll now

What's inside

Learning objectives

  • Get more fluent with python through a series of coding lectures
  • Understand and use the main language constructors, such as ifs, for and while loops
  • Develop and manipulate more complex data structures to support the game
  • Learn the basics of automated testing
  • Understand how a professional programmers thinks when programming

Syllabus

Building a pac-man game!
  • Get your IDE ready! If you want to use Pycharm like I do, just download it at JetBrains website.

  • Before starting to write any code, reflect with yourself:

    • How would you implement a Pac-Man game?

    • What are the most important features of a Pac-Man game to you?

    • How would you represent the map where the pac-man and ghosts and all the characters walk in?

Read more

Our first step in the code will be to model the map of the game.

WHAT TO DO AFTER THE LECTURE?

  • Create an empty project, add a pacman.py file and write up a map like I did.

  • Think about what would be the first function you would implement.

The first function we implement finds the coordinates of the pacman in a given map.

WHAT TO DO AFTER THE LECTURE?

  • Implement the find_pacman() function. This function receives a map (a data structure that follows the idea we discussed in the previous video) and returns x, y, the two coordinates pointing to where the pacman is. The function should return -1,-1 if the pacman is not in the map.

  • Try the function out a bit. Put the pacman in different positions and check if the function always returns the correct coordinates.

Let us now properly test the find_pacman() function we just created.

WHAT TO DO AFTER THE LECTURE?

  • It is time to write your first test using the unittest library. Create a pacman_tests.py file and write your first set of tests.

  • Go beyond the tests I wrote. What else would you test to make sure things work? Can you think of boundary tests or corner case scenarios that we may want to exercise?

Our next step is to actually move the pacman from one position to another.

WHAT TO DO AFTER THE LECTURE?

  • Implement the move_pacman() function. Feel free to go for a different implementation! As long as the goal of the function is the same (i.e., move the pacman from one coordinate to another), we should be fine!

  • Can you remove the redudancy that we have now in the test code? How can we avoid the map variable being copied so many times there?

Let's show the pacman game for the first time to the player. It's a very simplistic map, but that's how we start!

WHAT TO DO AFTER THE LECTURE?

  • Implement the ui_print() function. I suggest you start simple like I did, because we will make it better later!

We now move the pacman according to the key that the user pressed.

WHAT TO DO AFTER THE LECTURE?

  • Implement the play() and the next_position functions. If you want to try Pycharm’s refactoring options, do like me: code everything in the play() method, and then, call the Extract Method refactoring.

  • Write automated tests for the next_position function. I can see at least 5 tests: one for each direction, and one for a random key.

Moving is not that simple. The pacman should only move if a valid key was pressed or if the new position is within the borders of the map. Let's check that.

WHAT TO DO AFTER THE LECTURE:

  • Implement the illegal moves and the within borders check.

  • Write automated tests for the within_borders function. For this one, there are lots of test cases to think: one for each border of the map, for example. Also, remember that bugs often happen in corner cases! The pacman should be able to go to the left most position of the map (e.g., column “0”) but not more than that!

We now check if we hit a wall or if we hit a ghost. The play() function is getting more and more complicated.

WHAT TO DO AFTER THE LECTURE?

  • Implement the checks for wall and ghost.

  • As always, write tests!

The pacman wins the game if it collects all the pills. Let's find a way to count all the pills in the map.

WHAT TO DO AFTER THE LECTURE?

  • Implement the total_pills() function and plug it in the play() function. As always, write unit tests for the total_pills(). Two test cases should be enough: a map with pills, a map with zero pills.

  • The play() function returns three booleans now… It is getting complicated. Can you see a way of simplifying that?

It is time for the main loop of the game: we get the key from the user, we move the pacman, we repeat!

WHAT TO DO AFTER THE LECTURE?

  • Create the program.py file and write the first main loop there.

  • At the end of this video, the program.py file has a line of code that should not be there… It belongs to another one of our Python files. Can you identify what it is?

We now let the user know when s/he won or lost the game. The complex return of the play() function starts to pay off.

WHAT TO DO AFTER THE LECTURE?

  • Improve the main loop in the program.py.

  • Move what belongs to the UI module to the UI module! As a rule of thumb, make sure you always separate user interface from the rest!

The ghosts should move randomly in the map. How do we do it? We first find all the ghosts in the map, and then, randomly select a direction for them. In this video, you also see that copying and pasting code is really prone to errors!

WHAT TO DO AFTER THE LECTURE?

  • Create the move_ghosts() and the find_ghosts() functions.

  • Can you think of a way to extract the “ugly code” that moves the pac-man and the ghost to a single place? We don’t want that ugly code spread in many places!

The ghosts should also respect the rules of the game: they should not go through walls or eat the pills. Let us add those checks.

WHAT TO DO AFTER THE LECTURE?

  • Improve the move_ghosts() function to make sure it checks for all the required conditions before moving a ghost.

  • The so many is_a_X() functions are very similar to each other. Can you think of a way to reuse some code there?

Our UI is very simplistic. Let's make use of some ASCII art and make the UI a little bit more attractive.

WHAT TO DO AFTER THE LECTURE?

  • Implement the new UI. As an exceptional case, feel free to copy the code from my sources as typing the ASCII art drawings might be too boring.

  • Can you think of other things to improve in the UI? I sure can! For example, if you win the game, the program prints the message but does not update the map. Print the map again once the game is over.

It seems we are done! Let's revisit the code and discuss about our main coding decisions one more time.

WHAT TO DO AFTER THE LECTURE?

  • What would you do differently?

  • You can be bold and implement more features, such as:

    • A new pill appears in a random position of the map every 5 moves.

    • A new type of pill that enables pacman to eat ghosts for the next 10 moves.

    • Points and a leaderboard

    • Read the map from a file

    • A menu where the user can choose which map to play (the list of all the available maps can come from a directory)

I show you a repository where you can see different implementations of the pacman game, even using some object-oriented programming!

Traffic lights

Read about what's good
what should give you pause
and possible dealbreakers
Reinforces Python skills by applying them to a practical project, which is a great way to solidify understanding of fundamental concepts
Develops skills in creating data structures, writing conditional statements, and using loops, which are essential for game development and general programming
Includes guidance on testing programs using basic automated unit testing, which is a valuable skill for writing robust and reliable code
Focuses on a text-based game, which may not appeal to learners interested in graphical game development or more advanced game design principles
Emphasizes learning from mistakes and debugging, which is a crucial aspect of programming and helps build problem-solving skills
Requires learners to download and install PyCharm, which may be an inconvenience for those who prefer other IDEs or text editors

Save this course

Create your own learning path. Save this course to your list so you can find it easily later.
Save

Reviews summary

Build a pac-man game with python

According to learners, this course provides a highly practical and engaging way to solidify Python fundamentals by building a text-based Pac-Man game from scratch. Students particularly appreciate the live coding format, where the instructor demonstrates problem-solving and even shows how to debug common errors, which many found incredibly valuable. It's described as a perfect next step after an introductory Python course, offering plenty of hands-on practice using core concepts like loops, conditionals, and basic data structures within a fun project context. While the text-based UI is simple, the focus is effectively on the underlying code and practical application, making it ideal for reinforcing recently acquired skills and learning how to structure a small program. Basic unit testing is also introduced.
Interface is functional but not visual.
"The text-based UI is a bit simple, but that's expected."
"My only minor complaint is the text-based interface isn't visually appealing, but the focus is the code."
"Understand it's text-based, but some visuals would have been nice."
Helpful reference for getting unstuck.
"The source code being available was a lifesaver when I got stuck."
"Having the code provided after each section was very helpful for checking my work or catching up."
"The resources with the source code are a big plus."
Covers fundamentals of unit testing.
"Learned a lot about structuring a small project and basic unit testing."
"Loved the emphasis on testing and thinking through problems."
"The testing part was a valuable addition."
"It's good that they include unit tests; it's an important habit to build."
Instructor shows coding process and debugging.
"The instructor explained things clearly and showing mistakes was very helpful. Highly recommend for beginners."
"Fantastic course! The live coding format where the instructor debugs in real-time is invaluable. It feels like pairing with an experienced developer."
"The live coding style is unique and effective."
"I really appreciated how the instructor demonstrated finding and fixing errors during the lectures."
Builds core skills through a fun project.
"Loved building the Pac-Man game! It was a great way to practice basic Python concepts like loops and if statements."
"Good course for solidifying Python basics. The project-based approach is effective."
"The game project is a fun way to learn. Instructor is clear and the pace is good for someone with basic knowledge."
"Excellent way to reinforce Python skills. The game project is a fun way to learn."
Excellent for practicing Python basics.
"It was a great way to practice basic Python concepts like loops and if statements."
"Good course for solidifying Python basics."
"Perfect next step after a Python intro. The project was challenging enough to be engaging but not so hard it was frustrating."
"Helped me understand how to put Python concepts together into a real program."
Some found explanations less clear.
"Okay course... The explanation of data structures could be clearer."
"Most parts were clear, but a few concepts felt a bit rushed or not fully explained."
Might be slow for experienced coders.
"Was hoping for something more advanced. This is very basic Python applied to a simple text game."
"If you know Python fundamentals already, it might be too slow."
"Someone with solid Python fundamentals might not gain much new knowledge, but it's good practice."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Intro to Python: Learn while developing a pac-man game with these activities:
Review Python Fundamentals
Solidify your understanding of Python syntax, data structures, and control flow before diving into game development.
Browse courses on Python Basics
Show steps
  • Review online tutorials covering basic Python concepts.
  • Complete practice exercises on variables, loops, and functions.
  • Write simple programs to reinforce your understanding.
Review 'Automate the Boring Stuff with Python'
Reinforce your Python skills with a practical guide that covers essential programming concepts.
Show steps
  • Read relevant chapters on Python basics and control flow.
  • Complete the practice projects at the end of each chapter.
Review 'Python Crash Course'
Reinforce your Python skills with a comprehensive guide that covers essential programming concepts and includes hands-on projects.
Show steps
  • Read relevant chapters on Python basics and game development.
  • Complete the practice projects at the end of each chapter.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Practice Python Coding Challenges
Sharpen your problem-solving skills by tackling coding challenges that involve loops, conditionals, and data structures.
Show steps
  • Solve coding problems on platforms like HackerRank or LeetCode.
  • Focus on problems that involve manipulating lists and dictionaries.
  • Analyze your solutions and identify areas for improvement.
Simple Text-Based Game
Apply your Python knowledge by creating a simple text-based adventure game before starting the Pac-Man project.
Show steps
  • Design a simple game with a few rooms and items.
  • Implement the game logic using loops and conditional statements.
  • Add user input to allow the player to interact with the game.
  • Test the game thoroughly and fix any bugs.
Document Your Pac-Man Game Development
Improve your understanding and retention by documenting your progress and challenges while developing the Pac-Man game.
Show steps
  • Create a blog or journal to record your development process.
  • Document the design decisions you make and the challenges you face.
  • Share your code and documentation with others for feedback.
Contribute to a Python Game Project
Deepen your understanding of game development by contributing to an existing open-source Python game project.
Show steps
  • Find an open-source Python game project on GitHub.
  • Read the project's documentation and understand its codebase.
  • Identify a bug or feature to work on.
  • Submit a pull request with your changes.

Career center

Learners who complete Intro to Python: Learn while developing a pac-man game will develop knowledge and skills that may be useful to these careers:
Game Developer
Game developers are responsible for creating video games for various platforms. Beginning the journey as a game developer with this Intro to Python course, which involves building a Pac-Man game, provides valuable experience in game design and implementation. The course covers key aspects of game development, such as designing the map, moving characters, and determining game over conditions. In addition, the course's lessons on using loops, handling keyboard input, and implementing game logic provide game developers with practical experience. This is especially useful for understanding the workflow and testing involved in creating games.
Python Developer
Python developers specialize in building applications using the Python programming language. This Intro to Python course, centered around developing a Pac-Man game, offers a practical way to reinforce Python skills. The course guides developers through creating data structures, writing conditional statements, using loops, and handling keyboard input. Also, the course's live coding sessions, addressing mistakes and debugging, are a significant advantage for aspiring Python developers. They help understand the practical challenges of Python development in a professional setting. The course's exercises, along with the source code, are great resources for honing Python skills.
Software Engineer
Software engineers design, develop, and test software applications. This Intro to Python course focused on building a Pac-Man game helps software engineers learn how to create simple data structures to store things, write complex conditionals to take different decisions, and properly use loops. These are fundamental to software engineering. The course emphasizes hands-on coding and problem-solving, which are crucial skills for any software engineer. Moreover, the course's exploration of automated testing can help in ensuring the reliability of software projects.
Software Developer
Software developers create applications and systems that run on computers or other devices. With its emphasis on building a Pac-Man game, the Intro to Python course offers a great way to practice and enhance programming skills. The course provides a foundation in core programming concepts such as data structures, conditional statements, loops, and user input. Also, the course's exploration of automated testing helps emphasize the importance of code quality and reliability. Through hands-on coding exercises and debugging sessions, this course helps software developers gain experience in a practical setting.
QA Engineer
Quality assurance engineers are responsible for testing software and ensuring it meets quality standards. This Intro to Python course, centered around developing a Pac-Man game, provides experience with automated testing. The course's emphasis on testing using the unittest library is especially valuable for QA engineers, as it helps them understand testing concepts and methodologies. This is especially helpful for understanding the workflow and testing involved in automation.
Data Scientist
Data scientists analyze and interpret complex data to identify trends and insights. This Intro to Python course, involving the development of a Pac-Man game, may be useful for learning the basics of Python programming. Data scientists use Python for data manipulation, analysis, and visualization. The course helps establish a foundation in Python programming, which is essential for data scientists. The course may also help improve their ability to write code, test, and debug, all of which are important skills for data scientists.
Web Developer
Web developers build and maintain websites and web applications. This Intro to Python course, focused on building a practical Pac-Man game, may be useful for learning fundamental programming concepts. Web developers often use Python for back-end development and automation tasks. The course's hands-on approach to learning Python, combined with the experience of building a complete project, can be a valuable start. This course is helpful for individuals looking to gain foundational skills in Python programming.
Automation Engineer
Automation engineers design, develop, and implement automated systems and processes. This Intro to Python course, which culminates in the creation of a Pac-Man game, may be useful by helping engineers learn to write automated tests. The course not only helps to understand the fundamentals of Python but also reinforces critical software development skills. The practical experience gained through this course can be beneficial for automation engineers looking to enhance their coding abilities.
DevOps Engineer
DevOps engineers are responsible for automating and streamlining software development and deployment processes. The Intro to Python course, which involves building a functional Pac-Man game, may be useful for learning how to automate tasks. DevOps engineers use Python scripting for automation, configuration management, and infrastructure management. The course may help reinforce Python skills, which is essential for DevOps engineers. Also, the course's practical coding exercises and debugging sessions are great for building foundational skills.
Embedded Systems Engineer
Embedded systems engineers design, develop, and test software for embedded systems. This Intro to Python course, which involves building a Pac-Man game, may be useful for learning foundational Python skills. While embedded systems often use C or C++, Python is increasingly used for scripting and testing. The course may help engineers to reinforce their understanding of Python programming. The skills learned from this course may be helpful for embedded systems engineers.
Mobile App Developer
Mobile app developers create applications for mobile devices. This Intro to Python course, which involves building a Pac-Man game, may be useful for mobile app developers who want to expand their skills. While Python is not the primary language for mobile app development, it can be used for backend services or scripting. The course may help app developers reinforce the fundamentals of Python. For example, one may want to run a Python script on the back end, or do some testing of the mobile application using Python.
IT Support Specialist
IT support specialists provide technical assistance to users and troubleshoot computer issues. This Intro to Python course, focused on building a Pac-Man game, may be useful for learning basic coding concepts. IT support specialists can use Python scripting to automate tasks. The course may help them learn about how to write code, which can lead to automation. These automation scripts may help specialists to work more efficiently.
Technical Writer
Technical writers create documentation for software, hardware, and other technical products. This Intro to Python course focused on building a Pac-Man game helps technical writers to better see the perspective of the programmer. This is because they may not be able to code themselves. Also, the course may help them to better describe the product features. Knowing how programmers think may help writers.
IT Consultant
IT consultants advise organizations on how to use information technology to meet their goals. This Intro to Python course, which involves building a Pac-Man game, makes the consultant a better programmer. The course may help them to better understand the perspective of the programming team. By becoming more fluent in the field's vernacular, one may stand out from other consultants.
Technology Sales
In Technology Sales the staff must understand the value of what they sell. A deep understanding of the technology can help improve one's ability to sell it. While this Intro to Python course, in which the learner builds a Pac-Man game, only focuses on programming, it nevertheless helps one understand tech better. For this reason, it may be useful.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Intro to Python: Learn while developing a pac-man game.
Offers a fast-paced, thorough introduction to Python. It includes projects that allow you to apply what you've learned, which is perfect for solidifying your understanding of Python before and after the course. It useful reference tool for beginners and intermediate programmers. It provides additional depth to the existing course.
Provides a practical introduction to Python programming. It covers essential concepts and techniques for automating tasks, which can be helpful for understanding how to approach problem-solving in the Pac-Man game development. While not directly game-related, it builds a strong foundation in Python. It is commonly used as a textbook for introductory Python courses.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser