337
|
1 from cmd import Cmd
|
351
|
2 # using hook
|
337
|
3
|
|
4 class Pirate(Cmd):
|
|
5 gold = 3
|
|
6 def do_loot(self, arg):
|
351
|
7 'Seize booty from a passing ship.'
|
337
|
8 self.gold += 1
|
|
9 def do_drink(self, arg):
|
|
10 'Drown your sorrrows in rrrum.'
|
|
11 self.gold -= 1
|
351
|
12 def precmd(self, line):
|
|
13 self.initial_gold = self.gold
|
|
14 return line
|
|
15 def postcmd(self, stop, line):
|
|
16 if self.gold != self.initial_gold:
|
374
|
17 print('Now we gots {0} doubloons'
|
|
18 .format(self.gold))
|
337
|
19
|
|
20 pirate = Pirate()
|
374
|
21 pirate.cmdloop()
|