Repository navigation
Expand file tree
/
Copy pathdiceshell.py
More file actions
63 lines (45 loc) · 1.38 KB
/
Copy pathdiceshell.py
File metadata and controls
63 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Example to show how module cmd is use.
Error handling is partly missing by intent.
"""
import cmd
import dice
# _pylint: disable=locally-disabled,unused-argument,too-many-public-methods
# pylint: disable=locally-disabled,unused-argument
class Shell(cmd.Cmd):
"""
Example of class with command actions to roll a dice.
"""
intro = 'Welcome to the dice shell. Type help or ? to list commands.\n'
prompt = '(dice) '
def __init__(self):
super().__init__()
self.dice = dice.Dice()
def do_roll(self, arg):
"""
Roll one dice one time.
"""
print("Rolling a... {}".format(self.dice.roll()))
def do_rolls(self, arg):
"""
Roll one dice several times, supply argument how many times to roll.
"""
if not arg:
print("Missing argument on how many times to roll the dice.")
return
times = int(arg)
for _ in range(times):
print("Rolling a... {}".format(self.dice.roll()))
def do_total(self, arg):
"""
How many rolls have been made in total?
"""
print("You have rolled the dice {} times.".format(self.dice.getRollsMade()))
def do_exit(self, arg):
"""
Leave the game.
"""
print("Bye bye - see ya soon again")
return True