Week 6: Python Making Game

Lesson

  • Rolling dice simulator
    • Game logic, user input, printing (output), while loops, random integers
Basic Dice Rolling Simulator
import random

min = 1
max = 6

roll_again = “yes”

while (roll_again == “yes”):
print(“Rolling, rolling, rolling…”)
print(“The values are…”)
print(str(random.randint(min, max)),
str(random.randint(min, max))) roll_again = input(“Roll again?”)
Rolling, rolling, rolling… The values are…
(‘3’, ‘1’)
Roll again? yes
Rolling, rolling, rolling… The values are…
(‘4’, ‘1’)
Roll again? no

Practice

  • Extend the dice rolling program to create a game of your choosing.
    • i.e. highest sum wins, guess odd or even, pick a number and try to roll it, bet on the outcome of the dice
    • i.e. zombie dice
      • You (the player) are a zombie. You want as many brains as you can get (up to some number)
      • Values: brain, shotgun, footsteps
      • Each turn, you roll three dice. A brain is worth one point; footsteps are neutral; shotguns are bad, because you lose when you receive three.
      • After rolling three dice, you either decide to call it quits with your current brain collection, or you continue to roll (running the risk of more shotguns, but possibly earning more brains)