Stringing Together Breakout

Jed Rembold

October 10, 2022

Announcements

  • Midterm on Wednesday!
    • Bring your materials! (Notes, printed text, slides, old problem sets, etc)
    • Remember that you still only have an hour to get through the exam. Bringing a ton of materials is no substitute for having studied and coming prepared.
    • Practice Exam 1 and solutions posted
    • Practice Exam 2 and solutions coming by the end of today
    • I’m trying really hard to have up through PS4 feedback to you
  • Office hours today from 5 until 6:30pm
  • Polling: rembold-class.ddns.net

Review!

Suppose you have the string x = "consternation" and you’d like to just extract and print the word "nation". Which expression below will not give you the string "nation"?

  1. x[7:len(x)]
  2. x[7:]
  3. x[-6:len(x)]
  4. x[-6:-1]

Transforming Methods

Method Description
string.lower() Returns a copy of string with all letters converted to lowercase
string.upper() Returns a copy of string with all letters converted to uppercase
string.capitalize() Returns a copy of string with the first character capitalized and the rest lowercase
string.strip() Returns a copy of string with whitespace and non-printing characters removed from both ends
string.replace(old, new) Returns a copy of string with all instances of old replaced by new

Classifying Character Methods

Method Description
char.isalpha() Returns True if char is a letter
char.isdigit() Returns True if char is a digit
char.isalnum() Returns True if char is letter or a digit
char.islower() Returns True if char is a lowercase letter
char.isupper() Returns True if char is an uppercase letter
char.isspace() Returns True if char is a whitespace character (space, tab, or newline)
char.isidentifier() Returns True if char is a legal Python identifier

Igpay Atinlay

  • Suppose we wanted to write a script that converted English to Pig Latin
  • Rules of Pig Latin:
    • If the word begins with a consonant, move everything up to the first vowel to the end and append on “ay” at the end
      fleeteetflay
    • If the word starts with a vowel, just append “way” to the end
      orangeorangeway
    • If the word has no vowels, do nothing
  • Our decomposition:
    • Find first vowel
    • Convert a single word

Indingfay Owelsvay

def find_first_vowel_index(word):
    """
    Find the first vowel in a word and return its index,
    or return None if no vowels found.
    """
    for i in range(len(word)):
        index = "aeiou".find(word[i].lower())
        if index != -1:
            return i
    return None

Onvertcay Oneway Ordway

def word_2_pig_latin(word):
    """
    Convert a single word with no special characters from
    English to Pig Latin.
    """
    vowel = find_first_vowel_index(word)
    if vowel is None:
        return word
    elif vowel == 0:
        return word + "way"
    else:
        return word[vowel:] + word[:vowel] + "ay"

Project 2: Breakout!

  • Project 2 is recreating the classic arcade game Breakout!
  • Guide will be posted today, not due until Oct 21
  • Take a break for a few days after the midterm, but then consider getting a start this weekend

Breakout Basics

  • Breakout is a game in which the player attempts to break all the colored bricks by causing a bouncing ball to collide with them
  • The player controls a paddle at the bottom of the screen which the ball will bounce off
    • The paddle can only move left and right
  • If the ball makes it past the paddle to the bottom of the screen, the player loses a life
    • Lose 3 lives and it is game over!

Breakout Milestones

  • Breakout is broken up over 5 milestones
  • You have already seen or written pieces of similar code to many of the milestones!
    • Milestone 1: PS4 brick pyramid
    • Milestone 2: PS4 eyeball tracking
    • Milestone 3: Section bouncy ball problem

Milestone 1

Milestone 2

Milestone 3

Milestone 4

Milestone 5

// reveal.js plugins