Object-Oriented Python: Master OOP by Building Games and GUIs

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Power up your Python with object-oriented programming and learn how to write powerful, efficient, and re-usable code. Object-Oriented Python is an intuitive and thorough guide to mastering object-oriented programming from the ground up. You’ll cover the basics of building classes and creating objects, and put theory into practice using the pygame package with clear examples that help visualize the object-oriented style. You’ll explore the key concepts of object-oriented programming — encapsulation, polymorphism, and inheritance — and learn not just how to code with objects, but the absolute best practices for doing so. Finally, you’ll bring it all together by building a complex video game, complete with full animations and sounds. The book covers two fully functional Python code packages that will speed up development of graphical user interface (GUI) programs in Python.

Author(s): Irv Kalb
Edition: 1
Publisher: No Starch Press
Year: 2022

Language: English
Commentary: Vector PDF
Pages: 416
City: San Francisco, CA
Tags: GUI; Python; Memory Management; Animation; Object-Oriented Programming; PyGame; Game Development; 3D Scenes; Polymorphism; Encapsulation; Inheritance; Elementary

Acknowledgments
Introduction
Part I: Introducing Object-oriented Programming
Chapter 1: Procedural Python Examples
Higher or Lower Card Game
Bank Account Simulations
Common Problems with Procedural Implementation
Object-Oriented Solution—First Look at a Class
Summary
Chapter 2: Modeling Physical Objects with Object-Oriented Programming
Building Software Models of Physical Objects
Introduction to Classes and Objects
Classes, Objects, and Instantiation
Building a Slightly More Complicated Class
Representing a More Complicated Physical Object as a Class
Classes in Use
OOP as a Solution
Summary
Chapter 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
Chapter 4: Managing Multiple Objects
Bank Account Class
Importing Class Code
Creating Some Test Code
Creating an Object Manager Object
Better Error Handling with Exceptions
Using Exceptions in Our Bank Program
Calling the Same Method on a List of Objects
Interface vs. Implementation
Summary
Part II: Graphical User interfaces with Pygame
Chapter 5: Introduction to Pygame
Installing Pygame
Window Details
Event-Driven Programs
Using Pygame
Playing Sounds
Drawing Shapes
Summary
Chapter 6: Object-Oriented Pygame
Building the Screensaver Ball with OOP Pygame
Building a Reusable Object-Oriented Button
Building a Reusable Object-Oriented Text Display
Demo Ball with SimpleText and SimpleButton
Interface vs. Implementation
Callbacks
Summary
Chapter 7: Pygame GUI Widgets
Passing Arguments into a Function or Method
The pygwidgets Package
The Importance of a Consistent API
Summary
Part III: Encapsulation, Polymorphism, and Inheritance
Chapter 8: Encapsulation
Encapsulation with Functions
Encapsulation with Objects
Interpretations of Encapsulation
Making Instance Variables More Private
Decorators and @property
Encapsulation in pygwidgets Classes
A Story from the Real World
Abstraction
Summary
Chapter 9: Polymorphism
Sending Messages to Real-World Objects
A Classic Example of Polymorphism in Programming
Example Using Pygame Shapes
pygwidgets Exhibits Polymorphism
Polymorphism for Operators
Creating a String Representation of Values in an Object
A Fraction Class with Magic Methods
Summary
Chapter 10: Inheritance
Inheritance in Object-Oriented Programming
Implementing Inheritance
Employee and Manager Example
The Client’s View of a Subclass
Real-World Examples of Inheritance
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
Chapter 11: Managing Memory Used by Objects
Object Lifetime
Class Variables
Putting It All Together: Balloon Sample Program
Managing Memory: Slots
Summary
Part IV: Using OOP in Game Development
Chapter 12: Card Games
The Card Class
The Deck Class
The Higher or Lower Game
Testing with __name__
Other Card Games
Summary
Chapter 13: Timers
Timer Demonstration Program
Three Approaches for Implementing Timers
Installing pyghelpers
The Timer Class
Displaying Time
Summary
Chapter 14: Animation
Building Animation Classes
Animation Classes in pygwidgets
Summary
Chapter 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
Rock, Paper, Scissors Using Scenes
Communication Between Scenes
Implementation of the Scene Manager
Summary
Chapter 16: Full Game: Dodger
Modal Dialogs
Building a Full Game: Dodger
Summary
Chapter 17: Design Patterns and Wrap-Up
Model View Controller
Wrap-Up
Index