Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """A random string generator, for 'You hit th bat!' type messages.
- Usage: generate_message(enemeyName, weaponName) - returns a string"""
- import random
- class StringGenerator:
- """A class for generating strings procedurally,
- from many random combinations."""
- messages = [
- "you {attack} with your {weapon}",
- "{preparation} {weapon}, then {attack} with it",
- "{preparation} {weapon}, then {attack}"
- ]
- preparations = [
- "you {adverb} take aim with your",
- "you {adverb} grab for your",
- "you grip your trusty",
- "you steady your"
- ]
- intros = [
- "with little time to prepare",
- "in a blaze of fury",
- "in a blind panic",
- "confident in your abilities",
- "fully aware of the danger",
- "without hesitation",
- "with no mercy",
- "with no remorse",
- "feeling threatened",
- "like a cornered rat",
- "unconcerned by the situation",
- "like a hero",
- "without breaking a sweat"
- ]
- asides = [
- "HUGE SUCCESS",
- "Hooray!",
- "Incredible!",
- "Spectaular!",
- "Ten out of ten!",
- "A textbook move!",
- "You make it look easy!",
- "Amazing!",
- "What a hero!",
- "Ouch!", "Oof!", "I bet that hurt."
- ]
- attacks = [
- "{hit} the {enemy} {adverb} {bodypart}",
- "{adverb} {hit} the {enemy} {bodypart}",
- "{hit} the {enemy} {bodypart} {adverb}",
- "{adverb} {hit} the {enemy}, right {bodypart}",
- "{adverb} leap at the {enemy}, and {hit} it {bodypart}",
- "leap at the {enemy}, and {hit} it {adverb} {bodypart}"
- ]
- bodyparts_singular = [
- "face", "neck", "nose", "mouth", "forehead", "chin", "teeth", "tongue",
- "chest", "belly", "unmentionables", "spine", "back",
- "stomach", "spleen", "heart", "intestines", "bladder"
- ]
- bodyparts_directional = [
- "arm", "elbow", "wrist", "hand", "finger", "thumb",
- "leg", "thigh", "knee", "ankle", "shin", "foot", "toe",
- "eye", "nostril", "ear",
- "nipple", "shoulder", "buttock",
- "lung", "kidney"
- ]
- hit = [
- "stab", "poke", "skewer",
- "slice", "cut",
- "whack", "thwack", "smash", "smack", "wallop", "hit"
- ]
- adverbs = [
- "quickly", "swiftly", "suddenly",
- "angrily", "vengefully", "desperately",
- "joyously", "triumphantly", "courageously",
- "elegantly", "precisely", "calmly", "carefully", "casually",
- "steadily", "slowly", "gradually"
- ]
- def generate_message(self, theEnemy, theWeapon):
- """Generate an attack message string, and return it."""
- message = self.random_message().format( enemy=theEnemy, weapon=theWeapon,
- attack=self.random_attack(theEnemy), preparation=self.random_preparation() ) + "!"
- # Randomly prefix with an intro
- if random.randint(0,1) == 0:
- message = self.random_intro() + ", " + message
- message = message.capitalize()
- # Randomly add an aside
- if random.randint(0,1) == 0:
- message = message + " " + self.random_aside()
- return message
- def random_message(self):
- """Return a random base message"""
- return random.choice(self.messages)
- def random_attack(self, theEnemy):
- """Returns a random attack clause"""
- return random.choice(self.attacks).format(enemy=theEnemy,
- hit=self.random_hit(), bodypart=self.random_bodypart(),
- adverb=self.random_adverb())
- def random_intro(self):
- """Return a random intro"""
- if random.randint(0,2) == 0:
- return self.random_adverb()
- else:
- return random.choice(self.intros)
- def random_aside(self):
- """Return a random aside"""
- return random.choice(self.asides)
- def random_preparation(self):
- """Return a random preparation"""
- return random.choice(self.preparations).format(adverb=self.random_adverb())
- def random_hit(self):
- """Returns a random 'hit' verb"""
- return random.choice(self.hit)
- def random_bodypart(self):
- """Returns a random body part name"""
- option = random.randint(0,2)
- if option == 0:
- return "in the " + random.choice(self.bodyparts_singular)
- elif option == 1:
- return "in the " + random.choice(["left", "right"]) + \
- " " + random.choice(self.bodyparts_directional)
- else:
- return "between the " + random.choice(self.bodyparts_directional) + "s"
- def random_adverb(self):
- """Return a random adverb"""
- return random.choice(self.adverbs)
- # run the main function only if this module is executed as the main script
- # (if you import this as a module then nothing is executed)
- if __name__=="__main__":
- # call the main function
- s = StringGenerator()
- print "Demonstration: 10 random strings about attacking an orc with a spoon."
- for i in range(10):
- print s.generate_message("orc", "spoon")
Advertisement
Add Comment
Please, Sign In to add comment