IB CS1 3rd Quarter Exam

From WLCS
Revision as of 10:20, 22 March 2010 by Admin (talk | contribs) (New page: === Directions: === * This exam is open-book, open-notes, closed-person. * You are an avid Dungeons and Dragons player, but you have so many characters, you have a difficult time keeping ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Directions:

  • This exam is open-book, open-notes, closed-person.
  • You are an avid Dungeons and Dragons player, but you have so many characters, you have a difficult time keeping track of them all! You must implement the following class and program for your D&D Character Database

Character class:

Attributes:

  • player name (string)
  • character type (string examples fighter, thief, mage, cleric, paladin)
  • level (0-10 int)
  • health (0-100 int)
  • weapon (string)
  • attack strength (0-20 int)
  • defense strength (0-20 int)

Methods:

  • __init__() - should set all of the attributes
  • __str__() - returns a string with the player's name and type
    • Example: "Mr. Bui the level 10 paladin"
  • attack() - returns a random number from 1 up to the player's attack strength
  • defend() - returns a random number from 1 up to the player's defense strength

Randomizing:

  • import random at the top
  • random.randint(lower, upper)

Program

  1. Create an empty list named myCharacters
  2. Display a menu that lets the user (a)dd, (r)emove, (s)earch, a(t)tack, (d)efend
    • The (a)dd option should prompt the user for all the necessary attributes of a Character and then append one to the myCharacters list
    • The (r)emove option should prompt the user for a name and remove the character
    • The (s)earch option allows the user to search for the character and prints it out
    • The a(t)tack option prompts the user for a character name and then runs its attack() method/function
    • The (d)efend option prompts the user for a character name and then runs its defend() method/function