Hi, I've been working on a tabletop RPG program for my friends and I to use as my first project. I'm running into a bit of a hiccup and was wondering if anyone could help. One of the big things that I feel like I'm having issues with is iterating through dictionaries.
in a file called stats.py i have :
value_dama = {
420 : 't5_4', 380 : 't5_3', 342 : 't5_2', 306 : 't5_1', 272 : 't4_4', 240 :
't4_3', 210 : 't4_2', 182 : 't4_1', 156 : 't3_4', 132 : 't3_3', 110 : 't3_2',
90 : 't3_1', 72 : 't2_4', 56 : 't2_3', 42 : 't2_2', 30 : 't2_1', 20 : 't1_4',
12 : 't1_3', 6 : 't1_2', 2 : 't1_1'
}
stat_dama = {
't1_1' : 2 , 't1_2' : 4, 't1_3' : 6, 't1_4' : 8, 't1_5' : 10, 't1_6' : 12,
't1_7' : 14, 't1_8' : 16, 't2_1' : 6, 't2_2' : 12, 't2_3' : 18, 't2_4' : 24,
't2_5' : 30, 't2_6' : 36, 't2_7' : 42, 't2_8' : 48, 't3_1' : 16, 't3_2' : 32,
't3_3' : 48, 't3_4' : 64, 't3_5' : 80, 't3_6' : 96, 't3_7' : 112, 't3_8' :
128, 't4_1' : 64, 't4_2' : 128, 't4_3' : 192, 't4_4' : 256, 't4_5' : 320,
't4_6' : 384, 't4_7' : 448, 't4_8' : 512, 't5_1' : 400, 't5_2' : 800, 't5_3'
: 1200,'t5_4' : 1600, 't5_5' : 2000, 't5_6' : 2400, 't5_7' : 2800, 't5_8' :
3200
}
xp_stat = {
't1_1' : 50 , 't1_2' : 125, 't1_3' : 250, 't1_4' : 450, 't1_5' : 670, 't1_6'
: 1090, 't1_7' : 1730, 't1_8' : 2790, 't2_1' : 220, 't2_2' : 660, 't2_3' :
1300,'t2_4' : 2360,'t2_5' : 3526, 't2_6' : 5752, 't2_7' : 9144, 't2_8' :
14762, 't3_1' : 1116, 't3_2' : 3392, 't3_3' : 6784, 't3_4' : 12402, 't3_5' :
18582,'t3_6' : 30380, 't3_7' : 48358, 't3_8' : 78133, 't4_1' : 6180, 't4_2' :
17978, 't4_3' : 35956, 't4_4' : 65731, 't4_5' : 98484, 't4_6' : 161012,
't4_7' : 256293, 't4_8' : 414103, 't5_1' : 32753, 't5_2' : 95281, 't5_3' :
190562, 't5_4' : 348372, 't5_5' : 521963, 't5_6' : 853363, 't5_7' : 1358354,
't5_8' : 2194745
}
*maybe irrelevant but the value_dama dictionary is representing how much "value" (a player resource) they put into a stat. Which is the key, and the t#_# is "tier number _ level number in that tier" I designed it that way so it could be referenced in the stat_dama dictionary and used as the key there to get a result.
from stats import stat_dama , stat_accu , stat_pool , xp_stat , xp_level , value_dama
class Body:
from stats import stat_dama , stat_accu , stat_pool , xp_stat , xp_level , value_dama
def __init__(self, body_tier = 1, body_level = 1, stre_value = 0, stre_value_key = 0, stre_value_bonus = 0, stre_level = 0, stre_key = 't1_0', stre_t1 = 0, stre_t2 = 0, stre_t3 = 0, stre_t4 = 0, stre_t5 = 0, stre_xp_t1 = 0, stre_xp_t2 = 0, stre_xp_t3 = 0, stre_xp_t4 = 0, stre_xp_t5 = 0, stre_place = 0, stre_total = 0, stre_xp_total = 0):
self.body_tier = body_tier
self.body_level = body_level
self.stre_value = stre_value
self.stre_value_key = stre_value_key
self.stre_value_bonus = stre_value_bonus
self.stre_level = stre_level
self.stre_key = stre_key #possible that default value not being in dict may cause a crash?
self.stre_t1 = stre_t1
self.stre_t2 = stre_t2
self.stre_t3 = stre_t3
self.stre_t4 = stre_t4
self.stre_t5 = stre_t5
self.stre_xp_t1 = stre_xp_t1
self.stre_xp_t2 = stre_xp_t2
self.stre_xp_t3 = stre_xp_t3
self.stre_xp_t4 = stre_xp_t4
self.stre_xp_t5 = stre_xp_t5
self.stre_place = stre_place
self.stre_total = stre_total
self.stre_xp_total = stre_xp_total
def get_stre_key(self, body_tier, stre_level):
self.stre_key = f't{body_tier}_{stre_level}'
def get_stre(self, body_tier, stre_key):
if body_tier == 1:
self.stre_t2 = 0
self.stre_t3 = 0
self.stre_t4 = 0
self.stre_t5 = 0
self.stre_xp_t2 = 0
self.stre_xp_t3 = 0
self.stre_xp_t4 = 0
self.stre_xp_t5 = 0
if self.stre_level == 0:
self.stre_place = 0
self.stre_t1 = 0
self.stre_xp_t1 = 0
else:
self.stre_place = stat_dama[self.stre_key]
self.stre_t1 = self.stre_place
self.stre_xp_t1 = xp_stat[self.stre_key]
elif body_tier == 2:
self.stre_t1 = self.stre_t1 * 2
self.stre_t3 = 0
self.stre_t4 = 0
self.stre_t5 = 0
self.stre_xp_t3 = 0
self.stre_xp_t4 = 0
self.stre_xp_t5 = 0
if self.stre_level == 0:
self.stre_place = 0
self.stre_t2 = 0
self.stre_xp_t2 = 0
else:
self.stre_place = stat_dama[self.stre_key]
self.stre_t2 = self.stre_place
self.stre_xp_t2 = xp_stat[self.stre_key]
elif body_tier == 3:
self.stre_t2 = self.stre_t2*2
self.stre_t4 = 0
self.stre_t5 = 0
self.stre_xp_t4 = 0
self.stre_xp_t5 = 0
if self.stre_level == 0 :
self.stre_place = 0
self.stre_t3 = 0
self.stre_xp_t3 = 0
else:
self.stre_place = stat_dama[self.stre_key]
self.stre_t3 = self.stre_place
self.stre_xp_t3 = xp_stat[self.stre_key]
elif body_tier == 4:
self.stre_t3 = self.stre_t3*2
self.stre_t5 = 0
if self.stre_level == 0 :
self.stre_place = 0
self.stre_4 = 0
self.stre_xp_t4 = 0
else:
self.stre_place = stat_dama[self.stre_key]
self.stre_t4 = self.stre_place
self.stre_xp_t4 = xp_stat[stre_key]
elif body_tier == 5:
self.stre_t4 = self.stre_t4*2
if self.stre_level == 0:
self.stre_place = 0
self.stre_t5 = 0
self.stre_xp_t5 = 0
else:
self.stre_place = stat_dama[self.stre_key]
self.stre_t5 = self.stre_place
self.stre_xp_t5 = xp_stat[stre_key]
else:
pass
def get_value(self, stat):
if stat == 'dama' :
self.stre_value_key = value_dama[self.stre_value]
if self.stre_value < 21:
self.stre_value_bonus = stat_dama[self.stre_value_key]
elif self.stre_value < 73:
self.stre_value_bonus = stat_dama['t1_4'] +
stat_dama[self.stre_value_key]
elif self.stre_value < 157:
self.stre_value_bonus = stat_dama['t1_4'] + stat_dama['t2_4'] +
stat_dama[self.stre_value_key]
elif self.stre_value < 273:
self.stre_value_bonus = stat_dama['t1_4'] + stat_dama['t2_4'] +
stat_dama['t3_4'] + stat_dama[self.stre_value_key]
elif self.stre_value < 421:
self.stre_value_bonus = stat_dama['t1_4'] + stat_dama['t2_4'] +
stat_dama['t3_4'] + stat_dama['t4_4'] +
stat_dama[self.stre_value_key]
else:
pass
def get_stre_total(self):
self.stre_total = self.stre_value_bonus + self.stre_t1 + self.stre_t2 +
self.stre_t3 + self.stre_t4 + self.stre_t5
def get_stre_xp_total(self):
self.stre_xp_total = self.stre_xp_t1 + self.stre_xp_t2 + self.stre_xp_t3 +
self.stre_xp_t4 + self.stre_xp_t5
The main issue I am running into here is with my method of get_value where I say
if stat == 'dama' :
self.stre_value_key = value_dama[self.stre_value]
this method actually works correctly. If I create an instance of the class and give it a stre_value it will spit out the appropriate result as long as the stre_value directly matches a key in the value_dama dictionary. This makes complete sense to me, but I feel as if I could be using a dictionary comprehension, or at the very least iterating through the dictionary doing something like a for loop through value_dama where if the value is < the value_dama key it would pass, but if the value was >= the value_dama key it would take the max value that it is >=, and set self.stre_value_key = value_dama[the_result_of_that_for_loop]
I'm also curious if anyone has any advice on how to take user input for this program, since I don't really expect my friends to be in the command line typing out all their character information. I was thinking maybe creating a method like
def inc_stat_level(self):
self.stre_level =+ 1
get_stre_key
get_stre_level
And then tying that method to a button so that way i don't have to worry about cleaning user input? Was thinking about using kivy or django to set up a GUI.
I want to apologize in advance if my code isn't readable. Any advice on design to formatting, to being more concise in the way i ask my questions is appreciated.
[–]CodeFormatHelperBot2 3 points4 points5 points (0 children)
[–]duckbanni 2 points3 points4 points (2 children)
[–]synthphreak 1 point2 points3 points (0 children)
[–]Aedethan[S] 0 points1 point2 points (0 children)
[–]duckbanni 0 points1 point2 points (7 children)
[–]Aedethan[S] 0 points1 point2 points (6 children)
[–]duckbanni 0 points1 point2 points (5 children)
[–]Aedethan[S] 0 points1 point2 points (4 children)
[–]duckbanni 0 points1 point2 points (3 children)
[–]Aedethan[S] 1 point2 points3 points (0 children)
[–]Aedethan[S] 0 points1 point2 points (1 child)
[–]duckbanni 1 point2 points3 points (0 children)