CIS 111 - Ogre Attack

Objectives

  • Use selection in a program.
  • Use repetition in a program.
  • Translate a flowchart algorithm into a programming language.
  • Fight an ogre.

Overview

Implement the algorithm given by the flowchart presented below. The program simulates a simple battle to the death between the player and an ogre.

Flowchart

Click on the flowchart to see full size version.

Ogre Attack flowchart (revised)

Sample run of program

Current health: Ogre (10), You (6) You hit the ogre and did 2 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (8), You (6) You hit the ogre and did 2 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (6), You (6) Your attack missed the ogre. You have evaded the ogre's attack. Current health: Ogre (6), You (6) You hit the ogre and did 2 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (4), You (6) You hit the ogre and did 1 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (3), You (6) You hit the ogre and did 1 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (2), You (6) Your attack missed the ogre. You have evaded the ogre's attack. Current health: Ogre (2), You (6) Your attack missed the ogre. The ogre hit you and did 3 point(s) of damage Current health: Ogre (2), You (3) Your attack missed the ogre. You have evaded the ogre's attack. Current health: Ogre (2), You (3) You hit the ogre and did 1 point(s) of damage You have evaded the ogre's attack. Current health: Ogre (1), You (3) Your attack missed the ogre. The ogre hit you and did 2 point(s) of damage Current health: Ogre (1), You (1) Your attack missed the ogre. You have evaded the ogre's attack. Current health: Ogre (1), You (1) You hit the ogre and did 2 point(s) of damage You have slain the ogre and live to fight another day.

Notes

  • To get a random integer from low to high:
    • from random import randint
    • number = randint(low, high)
  • To delay for n seconds:
    • from time import sleep
    • sleep(n)

Rubric

  • 3 points for following style conventions (variable naming, documentation comments, etc.)
  • 3 points for having your messages match the format of the sample run messages
  • 34 points for having a correctly operating program that matches the flowchart