[Tutor] Engarde program was: i++
scott
slewin at rogers.com
Tue Jun 5 23:37:56 CEST 2007
Danny Yoo wrote:
>> I will work at your suggestions and will get back to you if I have any
>> problems.
>
> Good! Keep the folks on Python-Tutor up to date with your progress.
Here is the code changes I made based on your suggestions:
I put all the values together into a class
#######################################
class Character_stats:
def __init__(self, player, title, name, password, family, sl_inf,
mistress_inf, mistress2_inf, appt_inf, appt2_inf, spec_inf, sl,
allowance, funds, mid, mistress_name, mistress_sl, club, house, horses,
regiment, rank, ma, appointment, strength, con, cur_endurance, rapier,
dagger, sabre, cutlass, two_hand):
self.player = player
self.title = title
self.name = name
self.password = password
self.family = family
self.sl_inf = sl_inf
self.mistress_inf = mistress_inf
self.mistress2_inf = mistress2_inf
self.appt_inf = appt_inf
self.appt2_inf = appt2_inf
self.spec_inf = spec_inf
self.sl = sl
self.allowance = allowance
self.funds = funds
self.mid = mid
self.mistress_name = mistress_name
self.mistress_sl = mistress_sl
self.club = club
self.house = house
self.horses = horses
self.regiment = regiment
self.rank = rank
self.ma = ma
self.appointment = appointment
self.strength = strength
self.con = con
self.cur_endurance = cur_endurance
self.rapier = rapier
self.dagger = dagger
self.sabre = sabre
self.cutlass = cutlass
self.two_hand = two_hand
#############################
There where some values I did not want saved to the character file. A
couple where values that are for all characters, so I put them into
their own class.
###############################
class Master_stats:
def __init__(self, year, month):
self.year = year
self.month = month
###############################
There are only two values now, but that will most likely increase as I
get further into the program.
Lastly, I put the temporary values that I did not want saved on the
sheet into their own class.
#################################
class Character_temp:
def __init__(self, max_endurance):
self.sp = 0
self.income = 0
self.max_endurance = max_endurance
self.bribe_inf = 0
##################################
As you mentioned, my character save file is only a few lines long now :)
##################################
def char_save(character):
'''This saves the character to the harddrive'''
path = "./characters/" + character.player
cfile = open(path, "w")
cPickle.dump(character, cfile)
return
##################################
With the months, I used both your suggestions. I used the list and then
put it into a function.
###################################
def month_name(monthNumeral):
"""Returns the month name as a string"""
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
return months[monthNumeral - 1]
###################################
and I was able to call then function nicely by using:
####################################
s = "\n" + month_name(master.month) + " " + str(master.year)
cfile.write(s)
--
Your friend,
Scott
Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 11667 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070605/d19d4459/attachment.py
More information about the Tutor
mailing list