Skip to content

Latest commit

 

History

History

07-Creating-Mini-Game-with-GitHub-Copilot

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Creating a Mini Game with GitHub Copilot

In this module, we’ll explore how to use GitHub Copilot to build a classic rock, paper, scissors minigame. This hands-on project is designed to sharpen your programming skills and enhance your ability to develop console applications in Python. Best of all, we’ll use GitHub Codespaces, so there’s no need to worry about setting up a development environment. With GitHub Copilot as your AI pair programmer, you can focus on creating your application while effortlessly collaborating with your intelligent coding assistant. Lets begin.

  • Who this is for: Developers, DevOps Engineers, Software development managers, Testers.
  • What you'll learn: Harnessing GitHub Copilot to create code and add comments to your work.
  • What you'll build: Python files that will have code generated by Copilot AI for code and comment suggestions.
  • Prerequisites: To use GitHub Copilot you must have an active GitHub Copilot subscription. Sign up for 30 days free Copilot.
  • Timing: This course can be completed in under an hour.

By the end of this module, you'll acquire the skills to be able to:

  • Experience GitHub Codespaces as a development environment.
  • Develop input and output routines in a Python console application.
  • Use GitHub Copilot as an assistant.

Prerequisite reading:

Requirements

💪🏽 Exercise

Right click the "Start Course" button to open your Codespace in a new tab

start-course

You have already learned a bit about GitHub Codespaces and GitHub Copilot and how they work. In this challenge exercise, your goal is to develop a minigame in Python using GitHub Copilot.

Testing your GitHub Codespace

  1. Access your Codespaces and create a new file called app.py in Visual Studio Code.

    Note: You may need to install the Python Extension in Visual Studio Code if it isn't currently installed.

  2. Type the following comment:

    # write 'hello world' to the console
  3. GitHub Copilot should complete the code for you and provide the following result:

    # write 'hello world' to the console
    print('hello world')
  4. Run the application with the python app.py command in the terminal and check if the result is similar to the following console message:

    hello world

Creating the game logic

Now that you've verified that Codespaces working with GitHub Copilot, your next step is to develop the logic of the Python minigame with the help of GitHub Copilot based on the following specifications:

The winner of the game is determined by three simple rules:

  • Rock beats scissors.
  • Scissors beat paper.
  • Paper beats rock.

Game interaction considerations

The computer will be your opponent and can randomly choose one of the elements (rock, paper, or scissors). Your game interaction will be through the console (Terminal).

  • The player can choose one of the three options rock, paper, or scissors and should be warned if they enter an invalid option.
  • At each round, the player must enter one of the options in the list and be informed if they won, lost, or tied with the opponent.
  • By the end of each round, the player can choose whether to play again.
  • Display the player's score at the end of the game.
  • The minigame must handle user inputs, putting them in lowercase and informing the user if the option is invalid.

In your GitHub Codespaces, follow the given instructions to set up prompts that GitHub Copilot can understand and use to help you build the minigame. Keep in mind that GitHub Copilot relies on comments to grasp the context and give you helpful suggestions while you're working on your project.

Verify your work

  1. Run the minigame on the console with the python app.py command.
  2. At the prompt, type one of the game options: rock, paper, or scissors.
  3. The minigame should inform the player whether the player won, lost, or tied with the opponent.
  4. Choose to continue playing.
  5. At the prompt, type screen.
  6. The minigame should inform the player if the option entered by the player is invalid.
  7. Repeat steps 2 and 4 to play a few rounds and choose not to continue playing.
  8. Check if the minigame is terminated and if it displays your score, informing you of the number of wins and rounds.

Congratulations on completing this challenge exercise! You've created a Python console minigame using GitHub Copilot.