Mercurial > python-cmd2
comparison docs/pycon2010/pirate6.py @ 351:8a5bc9f5c28e
cmd2 docs
author | catherine@Drou |
---|---|
date | Tue, 16 Feb 2010 23:07:04 -0500 |
parents | 6fe1e75e3a67 |
children | 7cd04727f7f7 |
comparison
equal
deleted
inserted
replaced
350:1c91655d05f8 | 351:8a5bc9f5c28e |
---|---|
1 from cmd2 import Cmd | 1 from cmd import Cmd |
2 # prompts and defaults | 2 # prompts and defaults |
3 | 3 |
4 class Pirate(Cmd): | 4 class Pirate(Cmd): |
5 gold = 3 | 5 gold = 3 |
6 prompt = 'arrr> ' | 6 prompt = 'arrr> ' |
7 def default(self, line): | 7 def default(self, line): |
8 print('What mean ye by "{0}"?'.format(line)) | 8 print('What mean ye by "{0}"?'.format(line)) |
9 def do_loot(self, arg): | 9 def do_loot(self, arg): |
10 'Drown your sorrrows in rrrum.' | 10 'Seize booty from a passing ship.' |
11 self.gold += 1 | 11 self.gold += 1 |
12 def do_drink(self, arg): | 12 def do_drink(self, arg): |
13 '''Drown your sorrrows in rrrum. | 13 '''Drown your sorrrows in rrrum. |
14 | 14 |
15 drink [n] - drink [n] barrel[s] o' rum.''' | 15 drink [n] - drink [n] barrel[s] o' rum.''' |
17 self.gold -= int(arg) | 17 self.gold -= int(arg) |
18 except: | 18 except: |
19 if arg: | 19 if arg: |
20 print('''What's "{0}"? I'll take rrrum.'''.format(arg)) | 20 print('''What's "{0}"? I'll take rrrum.'''.format(arg)) |
21 self.gold -= 1 | 21 self.gold -= 1 |
22 def postcmd(self, stop, line): | 22 def precmd(self, line): |
23 print('Now we gots {0} doubloons'.format(self.gold)) | 23 self.initial_gold = self.gold |
24 return line | |
25 def postcmd(self, stop, line): | |
26 if self.gold != self.initial_gold: | |
27 print('Now we gots {0} doubloons'.format(self.gold)) | |
24 if self.gold < 0: | 28 if self.gold < 0: |
25 print("Off to debtorrr's prrrison. Game overrr.") | 29 print("Off to debtorrr's prison. Game overrr.") |
26 return True | 30 return True |
27 return stop | 31 return stop |
28 def do_quit(self, arg): | 32 def do_quit(self, arg): |
29 print("Quiterrr!") | 33 print("Quiterrr!") |
30 return True | 34 return True |