comparison utils/ruleset_tester.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 #!/usr/bin/env python
2 import Tkinter as TK
3 import math
4
5 class Ruleset (object):
6 def __init__ (self):
7 # move to somewhere else later (file ...)
8 self.ST_name = 'Strength'
9 self.ST_desc = 'The strenght of your character, affects hitpoints, carry weight and the weapons skill.'
10 self.AG_name = 'Agility'
11 self.AG_desc = 'The agility of your character influences armor class, action points and the weapons skill.'
12 self.IN_name = 'Intelligence'
13 self.IN_desc = 'Your intelligence is important for the technology skill and your ability to talk with other characters.'
14
15 self.weapon_name = 'Weapons'
16 self.weapon_desc = 'A high weapons skill will let you fire weapons more precisly.'
17 self.tech_name = 'Technology'
18 self.tech_desc = 'Boost this skill to become a real hacker.'
19 self.talk_name = 'Talk'
20 self.talk_desc = 'A high talk skill can save bullets.'
21
22 def set_main (self, ST, AG, IN):
23 self.ST = ST
24 self.AG = AG
25 self.IN = IN
26 # now calc boni
27 self.calc_boni()
28
29 def calc_boni (self):
30 self.STbonus = 0
31 self.AGbonus = 0
32 self.INbonus = 0
33
34 if self.ST > 4 :
35 self.STbonus = (self.ST - 4) * 1
36 if self.AG > 2 :
37 self.AGbonus = (self.AG - 2) * 1
38 if self.IN > 4 :
39 self.INbonus = (self.AG - 5) * 1
40
41 def skill_weapon (self, type, count):
42 # weapon = 2 x (ST + AG) + 10%
43 #if self.weapon == False:
44 self.weapon = 2 * (self.ST + self.AG) + self.ST + self.AG
45
46 if type == 1 :
47 # increase
48 if count != 0 :
49 self.weapon = self.weapon + count
50
51 if type == 0 :
52 # decrease
53 if (self.weapon - count) != 0 :
54 self.weapon = self.weapon - count
55 else:
56 self.weapon = 0
57
58 def skill_tech (self, type, count):
59 self.tech = 3 * self.IN + 2 * self.INbonus
60
61 if type == 1 :
62 # increase
63 if count != 0 :
64 self.tech = self.tech + count
65
66 if type == 0 :
67 # decrease
68 if (self.tech - count) != 0 :
69 self.tech = self.tech - count
70 else:
71 self.tech = 0
72
73 def skill_talk (self, type, count):
74 self.talk = 2 * self.IN + self.INbonus
75
76 if type == 1 :
77 # increase
78 if count != 0 :
79 self.talk = self.talk + count
80
81 if type == 0 :
82 # decrease
83 if (self.talk - count) != 0 :
84 self.talk = self.talk - count
85 else:
86 self.talk = 0
87
88 def calc_skills (self):
89 self.skill_weapon(0,0)
90 self.skill_tech(0,0)
91 self.skill_talk(0,0)
92
93
94 class GUI (object):
95
96 def __init__ (self):
97 self.root = TK.Tk()
98 self.root.title('FIFE Techdemo Ruleset-tester')
99 self.root.geometry("350x100")
100
101 # inject ruleset
102 self.RULES = Ruleset()
103 self.RULES.set_main(2,2,2)
104 self.RULES.calc_skills()
105
106 self.frm1 = TK.Frame(master=self.root)
107 self.frm1.grid(column = 1, row = 1)
108
109 self.create_widgets()
110 self.create_buttons()
111
112 def create_widgets (self):
113
114 mainstat = {
115 "a" : [self.RULES.ST_name, self.RULES.ST_desc, self.RULES.ST, self.RULES.STbonus],
116 "b" : [self.RULES.AG_name, self.RULES.AG_desc, self.RULES.AG, self.RULES.AGbonus],
117 "c" : [self.RULES.IN_name, self.RULES.IN_desc, self.RULES.IN, self.RULES.INbonus]
118 }
119
120 skills = {
121 "a" : [self.RULES.weapon_name, self.RULES.weapon_desc, self.RULES.weapon],
122 "b" : [self.RULES.tech_name, self.RULES.tech_desc, self.RULES.tech],
123 "c" : [self.RULES.talk_name, self.RULES.talk_desc, self.RULES.talk]
124 }
125
126 col = 1
127 row = 2
128
129 # container for generated entry-widgets
130 self.entries = []
131 self.entry_vars = []
132
133 # create widgets for mainstat
134 for key in mainstat:
135 label = TK.Label(self.frm1, text=mainstat[key][0], relief= TK.GROOVE, bd=0, width=10, anchor=TK.W)
136 label.grid(column = col, row = row)
137 col = col + 1
138
139 self.entry_vars.append(TK.StringVar(self.root))
140 entry_key = TK.Entry(self.frm1, width=2, textvariable=self.entry_vars[-1])
141 entry_key.grid(column = col, row = row, padx = 0)
142 entry_key.insert(0, mainstat[key][2])
143 col = col + 1
144
145 label = TK.Label(self.frm1, text=mainstat[key][3], relief= TK.RIDGE, bd=2, width=3)
146 label.grid(column = col, row = row)
147 row = row + 1
148
149 col = 1
150
151 self.entries.append(entry_key)
152
153 col = 5
154 row = 2
155
156 for key in skills:
157 label = TK.Label(self.frm1, text=skills[key][0], relief= TK.GROOVE, bd=0, width=10, anchor=TK.W)
158 label.grid(column = col, row = row, padx = 4)
159 col = col + 1
160
161 label = TK.Label(self.frm1, text=skills[key][2], relief= TK.RIDGE, bd=2, width=3)
162 label.grid(column = col, row = row)
163 row = row + 1
164
165 col = 5
166
167 def create_buttons (self):
168 col = 6
169 row = 6
170
171 button_calc = TK.Button(self.frm1, text='Calculate', command=self.calc)
172 button_calc.grid(column = col, row = row)
173
174 col = 7
175
176 button_quit = TK.Button(self.frm1, text='Quit', command=self.exit)
177 button_quit.grid(column = col, row = row)
178
179 pass
180
181 def calc (self):
182 # prepare entrys for calculation
183
184 tmp_vars = []
185 for i,var in enumerate(self.entry_vars) :
186 inumber = var.get()
187 tmp_vars.append(int(inumber))
188
189 # set new mainstats & skill values
190 # 0 = weapons
191 # 2 = talk
192 # 1 = technology
193 self.RULES.set_main(tmp_vars[0],tmp_vars[2],tmp_vars[1])
194 self.RULES.calc_skills()
195
196 # print new stats
197 self.create_widgets()
198
199 def exit(self):
200 self.root.quit()
201
202 def run (self):
203 self.root.mainloop()
204
205 # demo
206 if __name__ == '__main__':
207 gui = GUI()
208 gui.run()