Chapter 6. Classes and object-oriented programming

 

This chapter covers

  • An easier way to think about classes
  • How to use classes to design your programs

Until now, we’ve been skimming over one of the fundamental ways you can organize your program in Python: the class. Classes and object-oriented programming are normally seen as big, scary things that real programmers use to write their programs, and you might think you need a lot of theoretical knowledge in order to use them properly. Nothing could be further from the truth. In Python, it’s possible to ease into classes and object-oriented programming.

In this chapter, you’ll start with the code you wrote back in chapter 2 to generate caves for Hunt the Wumpus and then see how much easier it is to write it using classes. Then you’ll build up from there into a full-fledged adventure game along the lines of Adventure or Zork. While you do that, you’ll find out all about Python’s classes and how to make the most of them.

What exactly are classes?

 

Object-oriented design

 
 
 
 

Player input

 
 
 
 

Treasure!

 
 

Further into the caves

 
 

Here there be monsters!

 
 
 
 

Danger and excitement

 
 

Where to from here?

 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest