Pages

Friday, August 21, 2020

Day 5: Basic Objects, Flow Control, and Randomization

Following the Game Theme

She really seemed to enjoy today's lesson.  The running joke is, a good session with dad is 2 hours.  A bad session with dad can't be over soon enough.  Out of 5 lessons, we had two really good sessions, but none of them were what I would classify as bad.  I'm learning what keeps my daughter's attention.  I shouldn't be so surprised to find out she:
  • demands to be the one typing the actual code
  • wants examples to do something, not just output a String
  • and finally, the more obnoxious the better.
Today's lesson consisted of picking up where we left off yesterday, converting the primitives from our main method in our Hero class to instance variables with getters and setters.  She picked up on the notion of the class representing an archetype as opposed to a physical instance MUCH faster than I did (and I was 18 the first time I tried grasping object-oriented programming).

She decided to implement a Hero that could (and would) only attack other instances of the Hero class, and being a hero, would talk smack well in advance of an attack.  After each attack, each instance of the Hero class would then ask the other person to stop (being a Hero and all).  Finally, being heroes, they would refuse to stop fighting once engaged, demanding that each see the fight through to the finish in an honorable fashion (i.e. to the death).

Sound Effects to the Rescue

While attacking (and subsequently being attacked), she decided each Hero would verbalize their might (or their displeasure at being whacked).  At this point, I introduced our first set of external project assets.  I had her open up Audacity and record a handful of threats and a good number of hurt exclamations.  Last year I bought her the most amazing microphone (a Blue Yeti), and it really made today's lesson that much better because of the quality of her recordings.

Using basic if/else-if logic, I had her modify the Hero class to use text threats and complaints by default, with simple overrides for providing sounds when available.  She then added in her sounds and we were off to the races, pitching scenarios and ideas for the apparent game we are going to write now that she realizes this is how games are made.

Randomization FTW

Finally, we created a loop of our two Hero instances hitting each other for the same amount (which proved to be predictably boring).  We quickly moved on to the notion of random max hits with a chance for misses, with a fight ending after at least one of the heroes death (or both if we are really lucky).  She also quickly grasped the need for adjusting the seed for randomization so we didn't see player one repeatedly beat the fire out of player two.  The lesson was a resounding success, and she is overflowing with ideas which I am trying to convince her to write down while she is excited.  Epiphanies are fleeting and should be honored quickly to avoid being forgotten.

No comments: