User Menu Log Out

Welcome to MattHall.info

An Introduction to Interactive Programming with Python

This class was taught by Rice University and taken online through Coursera.org. This course was worked on from March 24th 2014 to May 26th 2014.

Getting Started - (CodeSkulptor)

For this class we were given access to CodeSkulptor to build, test, and run our programs. To run the program press the play button (the triangle in the upper left).

For simple programs the output is displayed in the cosole window on the right.

CodeSkulptor screenshot

For more advanced programs a new window with a canvas will appear.

CodeSkupltor does not always work with Internet Explorer. Chrome or Firefox are the reccomended browsers.

Week 1 - "Rock-Paper-Scissors-Lizard-Spock" game

Mini-project description - Rock-paper-scissors-lizard-Spock

Rock-paper-scissors is a hand game that is played by two people. The players count to three in unison and simultaneously "throw" one of three hand signals that correspond to rock, paper or scissors. The winner is determined by the rules:

  • Rock smashes scissors
  • Scissors cuts paper
  • Paper covers rock
Rock-paper-scissors is a surprisingly popular game that many people play seriously. Due to the fact that a tie happens around 1/3 of the time, several variants of Rock-Paper-Scissors exist that include more choices to make ties less likely.

Rock-paper-scissors-lizard-Spock (RPSLS) is a variant of Rock-paper-scissors that allows five choices. Each choice wins against two other choices, loses against two other choices and ties against itself. Much of RPSLS's popularity is that it has been featured in 3 episodes of the TV series "The Big Bang Theory". The Wikipedia entry for RPSLS gives the complete description of the details of the game.

In our first mini-project, we will build a Python function rpsls(name) that takes as input the string name, which is one of "rock", "paper", "scissors", "lizard", or "Spock". The function then simulates playing a round of Rock-paper-scissors-lizard-Spock by generating its own random choice from these alternatives and then determining the winner.

My RPSLS Game

Week 2 - "Guess The Number" game

One of the simplest two-player games is "Guess the number". The first player thinks of a secret number in some known range while the second player attempts to guess the number. After each guess, the first player answers either "Higher", "Lower" or "Correct!" depending on whether the secret number is higher, lower or equal to the guess. In this project, you will build a simple interactive program in Python where the computer will take the role of the first player while you play as the second player.

You will interact with your program using an input field and several buttons. For this project, we will ignore the canvas and print the computer's responses in the console. Building an initial version of your project that prints information in the console is a development strategy that you should use in later projects as well. Focusing on getting the logic of the program correct before trying to make it display the information in some "nice" way on the canvas usually saves lots of time since debugging logic errors in graphical output can be tricky.

My Guess The Number Game

Week 3 - "Stopwatch: The Game"

Our mini-project for this week will focus on combining text drawing in the canvas with timers to build a simple digital stopwatch that keeps track of the time in tenths of a second. The stopwatch should contain "Start", "Stop" and "Reset" buttons.

This game is a test of reflexes; two numerical counters that keep track of the number of times that you have stopped the watch and how many times you manage to stop the watch on a whole second (1.0, 2.0, 3.0, etc.).

My Stopwatch Game

Week 4 - Pong

In this project, we will build a version of Pong, one of the first arcade video games (1972). While Pong is not particularly exciting compared to today's video games, Pong is relatively simple to build and provides a nice opportunity to work on the skills that you will need to build a game like Asteroids.

For this version of Pong the left side is controled with the "W" and "S" keys and the right side is controled with the Up and Down arrows. Successful reflections from a player paddle will cause the ball to speed up. The point is awarded when the ball touches the gutter (not the edge of the canvas).

My Pong Game

Week 5 - Memory

This weeks project is Memory. A list of 8 pairs of cards will be placed face down on the canvas. The cards have numbers 0-7. Clicking a card will turn it over. Clicking a second card will turn it over. On the third click if the cards match they will stay visable. If the do not match they will be turned back over. The goal is to complete the row in the smallest amount of turns possible.

My Memory Game

Week 6 - Blackjack

Blackjack is a simple, popular card game that is played in many casinos. Cards in Blackjack have the following values: an ace may be valued as either 1 or 11 (player's choice), face cards (kings, queens and jacks) are valued at 10 and the value of the remaining cards corresponds to their number. During a round of Blackjack, the players plays against a dealer with the goal of building a hand (a collection of cards) whose cards have a total value that is higher than the value of the dealer's hand, but not over 21. (A round of Blackjack is also sometimes referred to as a hand.)

The game logic for our simplified version of Blackjack is as follows. The player and the dealer are each dealt two cards initially with one of the dealer's cards being dealt faced down (his hole card). The player may then ask for the dealer to repeatedly "hit" his hand by dealing him another card. If, at any point, the value of the player's hand exceeds 21, the player is "busted" and loses immediately. At any point prior to busting, the player may "stand" and the dealer will then hit his hand until the value of his hand is 17 or more. (For the dealer, aces count as 11 unless it causes the dealer's hand to bust). If the dealer busts, the player wins. Otherwise, the player and dealer then compare the values of their hands and the hand with the higher value wins. The dealer wins ties in our version.

My Blackjack Game

Week 7 - Spaceship from "RiceRocks" game

In our last two mini-projects, we will build a 2D space game RiceRocks that is inspired by the classic arcade game Asteroids (1979). Asteroids is a relatively simple game by today's standards, but was still immensely popular during its time. In the game, the player controls a spaceship via four buttons: two buttons that rotate the spaceship clockwise or counterclockwise (independent of its current velocity), a thrust button that accelerates the ship in its forward direction and a fire button that shoots missiles. Large asteroids spawn randomly on the screen with random velocities. The player's goal is to destroy these asteroids before they strike the player's ship. In the arcade version, a large rock hit by a missile split into several fast moving small asteroids that themselves must be destroyed. Occasionally, a flying saucer also crosses the screen and attempts to destroy the player's spaceship. Searching for "asteroids arcade" yields links to multiple versions of Asteroids that are available on the web (including an updated version by Atari, the original creator of Asteroids).

For this mini-project, you will implement a working spaceship plus add a single asteroid and a single missile.

We strongly recommend using Chrome for this mini-project.

My Rice Rocks ("Asteroids") Phase 1

Week 8 - Full "RiceRocks" game

For our last mini-project, we will complete the implementation of RiceRocks, an updated version of Asteroids, that we began last week.

At the end of this project, your game will have multiple rocks and multiple missiles. You will lose a life if your ship collides with a rock and you will score points if your missile collides with a rock. You will keep track of the score and lives remaining and end the game at the proper time. You may optionally add animated explosions when there is a collision.

We strongly recommend using Chrome for this mini-project.

My Rice Rocks ("Asteroids") Phase 2