comparison orpg/dieroller/shadowrun.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents 4385a7d0efd1
children bf799efe7a8a
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
45 from die import * 45 from die import *
46 46
47 __version__ = "1.0" 47 __version__ = "1.0"
48 48
49 class shadowrun(std): 49 class shadowrun(std):
50
50 def __init__(self,source=[],target=2): 51 def __init__(self,source=[],target=2):
51 std.__init__(self,source) 52 std.__init__(self,source)
52 53
54
53 def vs(self,target): 55 def vs(self,target):
54 return srVs(self, target) 56 return srVs(self, target)
55 57
58
56 def open(self): 59 def open(self):
57 return srOpen(self) 60 return srOpen(self)
58 61
59 class srVs(std): 62 class srVs(std):
63
60 def __init__(self,source=[], target=2): 64 def __init__(self,source=[], target=2):
61 std.__init__(self, source) 65 std.__init__(self, source)
62 # In Shadowrun, not target number may be below 2. All defaults are set to two and any 66 # In Shadowrun, not target number may be below 2. All defaults are set to two and any
63 # thing lower is scaled up. 67 # thing lower is scaled up.
64 if target < 2: 68 if target < 2:
67 self.target = target 71 self.target = target
68 # Shadowrun was built to use the d6 but in the interests of experimentation I have 72 # Shadowrun was built to use the d6 but in the interests of experimentation I have
69 # made the dieroller generic enough to use any die type 73 # made the dieroller generic enough to use any die type
70 self.openended(self[0].sides) 74 self.openended(self[0].sides)
71 75
76
72 def openended(self,num): 77 def openended(self,num):
73 if num <= 1: 78 if num <= 1:
74 self 79 self
75 done = 1 80 done = 1
76 for i in range(len(self.data)): 81 for i in range(len(self.data)):
80 if done: 85 if done:
81 return self 86 return self
82 else: 87 else:
83 return self.openended(num) 88 return self.openended(num)
84 89
90
85 def __sum__(self): 91 def __sum__(self):
86 s = 0 92 s = 0
87 for r in self.data: 93 for r in self.data:
88 if r >= self.target: 94 if r >= self.target:
89 s += 1 95 s += 1
90 return s 96 return s
91 97
98
92 def __str__(self): 99 def __str__(self):
93 if len(self.data) > 0: 100 if len(self.data) > 0:
94 myStr = "[" + str(self.data[0]) 101 myStr = "[" + str(self.data[0])
95 for a in self.data[1:]: 102 for a in self.data[1:]:
96 myStr += "," 103 myStr += ","
100 myStr = "[] = (0)" 107 myStr = "[] = (0)"
101 108
102 return myStr 109 return myStr
103 110
104 class srOpen(std): 111 class srOpen(std):
112
105 def __init__(self,source=[]): 113 def __init__(self,source=[]):
106 std.__init__(self,source) 114 std.__init__(self,source)
107 self.openended(self[0].sides) 115 self.openended(self[0].sides)
108 116
117
109 def openended(self,num): 118 def openended(self,num):
110 if num <= 1: 119 if num <= 1:
111 self 120 self
112 done = 1 121 done = 1
113 for i in range(len(self.data)): 122 for i in range(len(self.data)):
117 if done: 126 if done:
118 return self 127 return self
119 else: 128 else:
120 return self.openended(num) 129 return self.openended(num)
121 130
131
122 def __sum__(self): 132 def __sum__(self):
123 s = 0 133 s = 0
124 for r in self.data: 134 for r in self.data:
125 if r > s: 135 if r > s:
126 s = r 136 s = r
127 return s 137 return s
128 138
139
129 def __str__(self): 140 def __str__(self):
130 if len(self.data) > 0: 141 if len(self.data) > 0:
131 myStr = "[" + str(self.data[0]) 142 myStr = "[" + str(self.data[0])
132 for a in self.data[1:]: 143 for a in self.data[1:]:
133 myStr += "," 144 myStr += ","