PY-1.4-BP6-MQ50

Our Goal: Get Your Game Ready for the Web

In this lesson, you will get your game ready to be played on the internet. This means you will set up your project so that special tools can turn your Pygame game into a web game. You will make sure your game files are in the right places and that everything is set up for your game to work in a web browser.

Check Your Project Setup

Before you get your game ready for the web, let's check your project setup. We will run some tests to see if your game files are in the right places.

Run this command in your terminal:

pytest module-1.4/blueprint-BP6/quest-50

What you should see:

āŒ Some tests will fail. This is okay for now! It means your project is not yet ready for web export, and the tests are waiting for you to set it up.

Set Up Your Project for the Web

Now, you will set up your project so that your game can be turned into a web game. This means making sure your files are in the right places and have the right starting code.

  1. Make your main game file: Create a file named main.py in your project's main folder. Inside it, add the basic Pygame setup code (like import pygame and pygame.init()).

  2. Make a 'web' folder: Create a new folder named web in your project's main folder.

  3. Make your web page file: Inside the web folder, create a file named index.html. This will be the main page for your web game.

  4. Add basic HTML: Inside index.html, add the basic parts of an HTML page (like <html>, <head>, and <body>). Also, add a <script> tag that will help load your game later. It should look something like this:

    <!DOCTYPE html>
    <html>
    <head>
        <title>My Pygame Web Game</title>
    </head>
    <body>
        <script src="game.js"></script>
    </body>
    </html>
    

Remember to save all your files after you make changes.

Check Your Work Again

You've set up your project for the web! Now, let's run the tests to make sure everything is correct.

Run this command in your terminal:

pytest module-1.4/blueprint-BP6/quest-50

What you should see:

āœ… All tests should pass! This means your project is now ready to be turned into a web game.

Documentation

Documentation not available for PY-1.4-BP6.