The Care and Feeding of Your Baby Dragon
You know how to create your own classes, even some of the subtle bits, but so far you’ve only seen a small, fluffy, toy example. Let me give you something a bit more interesting. Let’s say we want to make a simple virtual pet, a baby dragon.
Like most babies, it should be able to eat, sleep, and poop, which means you’ll need to be able to feed it, put it to bed, and take it on walks. Internally, your dragon will need to keep track of whether it’s hungry, tired, or needs to go out, but you won’t be able to see that when you interact with your dragon, the same way you can’t ask a human baby, “Are you hungry?” You’ll also add a few other fun ways you can interact with your baby dragon, and when your baby ...
Get Learn to Program, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.