From the course: Programming Foundations: Object-Oriented Design

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Static attributes and methods

Static attributes and methods - Python Tutorial

From the course: Programming Foundations: Object-Oriented Design

Start my 1-month free trial

Static attributes and methods

- When we instantiate a bunch of enemy spaceships for our game, we'll want each of those spaceship objects to keep track of its own remaining shield strength independent of the others. That way, if the player's asteroid smashes into one of the ships, it'll reduce its shield strength, while the other ships remain unaffected. We've accomplished that by storing the ship's shield strength as an instance variable, which means each instance of the spaceship class will have its own separate copy. - What do you think about adding a different difficulty setting to our game? We could scale the toughness of all the ships, making their shields easier or harder to destroy. - Sounds good to me. - But unlike shield strength, the spaceships' toughness value should not vary from ship to ship. If the player decides to increase or decrease the game's difficulty, then all of the ships should increase or decrease their toughness the same amount. - Well, if we create toughness as another instance variable,…

Contents