Object-oriented Python Master OOP by building games and GUIs

Irv Kalb

Book - 2022

"This guide to mastering object-oriented programming with Python covers the basics of building classes and creating objects through clear examples using the pygame package. Also explores key concepts like encapsulation, polymorphism, and inheritance as well as best practices for coding with objects"--

Saved in:
1 being processed

2nd Floor Show me where

005.113/PYTHON/Kalb
0 / 1 copies available
Location Call Number   Status
2nd Floor 005.113/PYTHON/Kalb Due Jan 2, 2025
Subjects
Published
San Francisco : No Starch Press 2022.
Language
English
Main Author
Irv Kalb (author)
Physical Description
1 volume ; 24 cm
ISBN
9781718502062
  • Acknowledgments
  • Introduction
  • Who Is This Book For?
  • Python Version(s) and Installation
  • How Will I Explain OOP?
  • What's in the Book
  • Development Environments
  • Widgets and Example Games
  • Part I. Introducing Object-Oriented Programming
  • 1. Procedural Python Examples
  • Higher or Lower Card Game
  • Representing the Data
  • Implementation
  • Reusable Code
  • Bank Account Simulations
  • Analysis of Required Operations and Data
  • Implementation 1-Single Account Without Functions
  • Implementation 2-Single Account with Functions
  • Implementation 3-Two Accounts
  • Implementation 4-Multiple Accounts Using Lists
  • Implementation 5-List of Account Dictionaries
  • Common Problems with Procedural Implementation
  • Object-Oriented Solution -First Look at a Class
  • Summary
  • 2. Modeling Physical Objects with Object-Oriented Programming
  • Building Software Models of Physical Objects
  • State and Behavior: Light Switch Example
  • Introduction to Classes and Objects
  • Classes, Objects, and instantiation
  • Writing a Class in Python
  • Scope and Instance Variables
  • Differences Between Functions and Methods
  • Creating an Object from a Class
  • Calling Methods of an Object
  • Creating Multiple Instances from the Same Class
  • Python Data Types Are Implemented as Classes
  • Definition of an Object
  • Building a Slightly More Complicated Class
  • Representing a More Complicated Physical Object as a Class
  • Passing Arguments to a Method
  • Multiple Instances
  • Initialization Parameters
  • Classes in Use
  • OOP as a Solution
  • Summary
  • 3. Mental Models of Objects and the Meaning of "Self"
  • Revisiting the DimmerSwitch Class
  • High-Level Mental Model #1
  • A Deeper Mental Model #2
  • What Is the Meaning of "self"?
  • Summary
  • 4. Managing Multiple Objects
  • Bank Account Class
  • Importing Class Code
  • Creating Some Test Code
  • Creating Multiple Accounts
  • Multiple Account Objects in a List
  • Multiple Objects with Unique Identifiers
  • Building an Interactive Menu
  • Creating an Object Manager Object
  • Building the Object Manager Object
  • Main Code That Creates an Object Manager Object
  • Better Error Handling with Exceptions
  • Try and except
  • The raise Statement and Custom Exceptions
  • Using Exceptions in Our Bank Program
  • Account Class with Exceptions
  • Optimized Bank Class
  • Main Code That Handles Exceptions
  • Calling the Same Method on a List of Objects
  • Interface vs. Implementation
  • Summary
  • Part II. Graphical User Interfaces with Pygame
  • 5. Introduction to Pygame
  • Installing Pygame
  • Window Details
  • The Window Coordinate System
  • Pixel Colors
  • Event-Driven Programs
  • Using Pygame
  • Bringing Up a Blank Window
  • Drawing an Image
  • Detecting a Mouse Click
  • Handling the Keyboard
  • Creating a Location-Based Animation
  • Using Pygame rects
  • Playing Sounds
  • Playing Sound Effects
  • Playing Background Music
  • Drawing Shapes
  • Reference for Primitive Shapes
  • Summary
  • 6. Object-Oriented Pygame
  • Building the Screensaver Ball with OOP Pygame
  • Creating a Ball Class
  • Using the Ball Class
  • Creating Many Ball Objects
  • Creating Many, Many Ball Objects
  • Building a Reusable Object-Oriented Button
  • Building a Burton Class
  • Main Code Using a SimpleButton
  • Creating a Program with Multiple Buttons
  • Building a Reusable Object-Oriented Text Display
  • Steps to Display Text
  • Creating a SimpleText Class
  • Demo Ball with SimpleText and SimpleButton
  • Interface vs. Implementation
  • Callbacks
  • Creating a Callback
  • Using a Callback with SimpleButton
  • Summary
  • 7. Pygame Gui Widgets
  • Passing Arguments into a Function or Method
  • Positional and Keyword Parameters
  • Additional Notes on Keyword Parameters
  • Using None as a Default Value
  • Choosing Keywords and Default Values
  • Default Values in GUI Widgets
  • The pygwidgets Package
  • Setting Up
  • Overall Design Approach
  • Adding an Image
  • Adding Buttons, Checkboxes, and Radio Buttons
  • Text Output and Input
  • Other pygwidgets Classes
  • Pygwidgets Example Program
  • The Importance of a Consistent API
  • Summary
  • Part III. Encapsulation, Polymorphism, and Inheritance
  • 8. Encapsulation
  • Encapsulation with Functions
  • Encapsulation with Objects
  • Objects Own Their Data
  • Interpretations of Encapsulation
  • Direct Access and Why You Should Avoid It
  • Strict Interpretation with Getters and Setters
  • Safe Direct Access
  • Making Instance Variables More Private
  • Implicitly Private
  • More Explicitly Private
  • Decorators and @property
  • Encapsulation in pygwidgets Classes
  • A Story from the Real World
  • Abstraction
  • Summary
  • 9. Polymorphism
  • Sending Messages to Real-World Objects
  • A Classic Example of Polymorphism in Programming
  • Example Using Pygame Shapes
  • The Square Shape Class
  • The Circle and Triangle Shape Classes
  • The Main Program Creating Shapes
  • Extending a Pattern
  • Pygwidgets Exhibits Polymorphism
  • Polymorphism for Operators
  • Magic Methods
  • Comparison Operator Magic Methods
  • A Rectangle Class with Magic Methods
  • Main Program Using Magic Methods
  • Math Operator Magic Methods
  • Vector Example
  • Creating a String Representation of Values in an Object
  • A Fraction Class with Magic Methods
  • Summary
  • 10. Inheritance
  • Inheritance in Object-Oriented Programming
  • Implementing Inheritance
  • Employee and Manager Example
  • Base Class: Employee
  • Subclass: Manager
  • Test Code
  • The Client's View of a Subclass
  • Real-World Examples of Inheritance
  • InputNumber
  • DisplayMoney
  • Example Usage
  • Multiple Classes Inheriting from the Same Base Class
  • Abstract Classes and Methods
  • How pygwidgets Uses Inheritance
  • Class Hierarchy
  • The Difficulty of Programming with Inheritance
  • Summary
  • 11. Managing Memory Used by Objects
  • Object Lifetime
  • Reference Count
  • Garbage Collection
  • Class Variables
  • Class Variable Constants
  • Class Variables for Counting
  • Putting It All Together: Balloon Sample Program
  • Module of Constants
  • Main Program Code
  • Balloon Manager
  • Balloon Class and Objects
  • Managing Memory: Slots
  • Summary
  • Part IV. Using Oop in Game Development
  • 12. Card Games
  • The Cord Class
  • The Deck Class
  • The Higher or Lower Game
  • Main Program
  • Game Object
  • Testing with name_
  • Other Card Games
  • Blackjack Deck
  • Games with Unusual Card Decks
  • Summary
  • 13. Timers
  • Timer Demonstration Program
  • Three Approaches for implementing Timers
  • Counting Frames
  • Timer Event
  • Building a Timer by Calculating Elapsed Time
  • Installing pyghelpers
  • The Timer Class
  • Displaying Time
  • CountUpTimer
  • CountDownTimer
  • Summary
  • 14. Animation
  • Building Animation Classes
  • SimpleAnimation Class
  • SimpleSpriteSheetAnimation Class
  • Merging Two Classes
  • Animation Classes in pygwidgets
  • Animation Class
  • SpriteSheetAnimation Class
  • Common Base Class: PygAnimation
  • Example Animation Program
  • Summary
  • 15. Scenes
  • The State Machine Approach
  • A pygame Example with a State Machine
  • A Scene Manager for Managing Many Scenes
  • A Demo Program Using a Scene Manager
  • The Main Program
  • Building the Scenes
  • A Typical Scene
  • Rock, Paper, Scissors Using Scenes
  • Communication Between Scenes
  • Requesting Information from a Target Scene
  • Sending Information to a Target Scene
  • Sending Information to All Scenes
  • Testing Communications Among Scenes
  • Implementation of the Scene Manager
  • Run() Method
  • Main Methods
  • Communication Between Scenes
  • Summary
  • 16. Full Game: Dodger
  • Modal Dialogs
  • Yes/No and Alert Dialogs
  • Answer Dialogs
  • Building a Full Game: Dodger
  • Game Overview
  • Implementation
  • Extensions to the Game
  • Summary
  • 17. Design Patterns and Wrap-Up
  • Model View Controller
  • File Display Example
  • Statistical Display Example
  • Advantages of the MVC Pattern
  • Wrap-Up
  • Index