Skip to content

Handy Dandy Examples for Difficult Code

sleepinghungry edited this page Jan 17, 2017 · 1 revision

To have a character die while talking to it:

def final_words(game, thing):
  thing.health -= 1
  if thing.health == 2:
    game.output("The character doesn't look good.  It says, \"I don't feel very good.\"")
  elif thing.health == 1:
    game.output("The character closes its eyes and whispers, \"I should've been a game designer.\"")
  elif thing.health == 0:
    game.output("The character doesn't respond.")
  elif thing.health < 0:
    game.output("The character has died.")

actor_or_animal_variable.add_phrase("chat", final_words)

This code is easily edited to handle fighting by changing "chat" to "fight" or "kill"

BWX Game Engine pages

Python Pages

Step By Step Guides

Building Conditionals

Lectures

Explaining Conditionals

Assignments

I Am Thinking of a Number...

Clone this wiki locally