Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- from tools import addSpacing
- class ScreenPrinter:
- screenWidth = 100
- printSpace = screenWidth-2
- def printFullCharacterSheet(self,CharacterData):
- '''prints a full character sheet'''
- #coreCharacteristics = self.getCoreCharacteristics(CharacterData)
- self.getReportHeading(CharacterData)
- def getCoreCharacteristics(self,CharacterData):
- '''takes the assembled characterData and extracts the character core characterists.'''
- CoreCharacteristics = {"WS":CharacterData['WS'],"BS":CharacterData['BS'],\
- 'Strength':CharacterData['Strength'],'Toughness':CharacterData['Toughness'],\
- 'Agility':CharacterData['Agility'],'Intelligence':CharacterData['Intelligence'],\
- 'Perception':CharacterData['Perception'],'WP':CharacterData['WP'],'Fell':CharacterData['Fell']
- }
- return CoreCharacteristics
- def getReportHeading(self,CharacterData,title="Torroes Prime's Text Adventure System"):
- report = [self.getBarHead(),
- self.getPageTitle(title),
- self.getTwoColumn(44),
- self.getCharacterNameAndClassLine(CharacterData["name"],CharacterData["class"]),
- self.getTwoColumn(49),
- self.getTotalXpEarned(999999999),
- self.getThreeColumn(49,19),
- self.getCoreCharacteristicsChartHeaderAndWoundsLine(CharacterData["cWounds"],CharacterData["tWounds"]),
- self.getCoreCharacteristisAndCurrentFatique(self.getCoreCharacteristicsLine(CharacterData),CharacterData["fatique"]),
- self.getTwoColumn(55),
- self.getPresentDamageAndCarriedWeightChartHeaders()]
- for item in report:
- print(item)
- def getBarHead(self):
- '''prints a report head line '+----+' number of '-' determined by screenWidth '''
- space = ScreenPrinter.printSpace
- output = "+"+("-"*space)+"+"
- return output
- def getPageTitle(self, title="Torroes Prime's Text Adventure System"):
- '''prints report title'''
- space = ScreenPrinter.printSpace - len(title)
- return "|"+addSpacing(title,ScreenPrinter.printSpace,2)+"|"
- def getTwoColumn(self,firstColumnWidth = 25):
- '''prints a 2 column header. if a firstColumnWidth is not supplied, default width is 25 spaces'''
- rightColumnSpace = ScreenPrinter.printSpace-firstColumnWidth-1
- return "+"+("-"*firstColumnWidth)+"+"+("-"*rightColumnSpace)+"+"
- def getThreeColumn(self,firstColumnWidth = 25,secondColumnWidth=25):
- '''prints a 3 column header. if a firstColumnWidth/secondColumnWidth is not supplied, default width is 25 spaces'''
- output = "+"+("-"*firstColumnWidth)+"+"+("-"*secondColumnWidth)+"+"+\
- ("-"*(ScreenPrinter.printSpace - firstColumnWidth-secondColumnWidth-2))+"+"
- return output
- def getCharacterName(self,name="Test Name"):
- return "| Character Name: "+addSpacing(name,26)+" |"
- def getCharacterClass(self,charClass = "Test Class"):
- return " Class: "+addSpacing(charClass,44)+" |"
- def getCharacterNameAndClassLine(self,name,charClass):
- return self.getCharacterName(name)+self.getCharacterClass(charClass)
- def getCoreCharacteristicsAndTotalXpLine(self):
- '''supplies the '| Core Characteristics | Total XP Earned: ' section'''
- return "| Core Characteristics | Total XP Earned: "
- def getTotalXpEarned(self,xpEarned):
- if isinstance(xpEarned,int) is True:
- xp = "{:,}".format(int(xpEarned))
- output = self.getCoreCharacteristicsAndTotalXpLine() + addSpacing(xp,29,)+" |"
- return output
- def getCoreCharacteristicsTableHeader(self):
- ''' supplies core characteristics chart header'''
- return "| WS | BS | Str | Tgh | Ag | Int | Per | WP | Chr "
- def getTotalWoundsHeader(self):
- '''supplies '| Total Wounds: \''''
- return "| Total Wounds: "
- def getCurrentWoundsHeader(self):
- '''supplies '| Current Wounds: \''''
- return "| Current Wounds: "
- def getWounds(self,current,total):
- '''constructs total wounds and Current wounds section of character sheet'''
- totalWounds = self.getTotalWoundsHeader()+addSpacing(total,3)+" "
- currentWound = self.getCurrentWoundsHeader()+addSpacing(current,9)+" "
- output = totalWounds+currentWound+" |"
- return output
- def getTotalWounds(self,totalWounds):
- '''constructs the totalWounds section of character sheet'''
- output = self.getTotalWoundsHeader()+addSpacing(totalWounds,3)+" |"
- return output
- def getCurrentWounds(self,CurrentWounds):
- '''constructs the current Wounds section of character sheet'''
- output = self.getCurrentWoundsHeader()+addSpacing(CurrentWounds,9)
- return output
- def getCoreCharacteristicsChartHeaderAndWoundsLine(self,current,total):
- ''' constructs the characteristics chart header and wounds sections as a single line'''
- output = self.getCoreCharacteristicsTableHeader()+\
- self.getWounds(current,total)
- return output
- def getPresentDamageChartHeader(self):
- '''supplies 'Present damage' header for character sheet'''
- return "| "+addSpacing("Present Damage:",53,2)+" "
- def getCurrentCarriesWeightHeader(self):
- ''' suppleis the "Current Carried Weight" chart header for character sheet'''
- return "| "+addSpacing("Current Carried Weight",40,2)+" |"
- def getPresentDamageAndCarriedWeightChartHeaders(self):
- '''supplies the present damage header and current carried weight header as a single line'''
- return self.getPresentDamageChartHeader()+self.getCurrentCarriesWeightHeader()
- def getCoreCharacteristicsLine(self,chars):
- ''' supplies the core characteristics for output'''
- ws = "| "+addSpacing(chars[character.ListOfCharacteristics[0]],3,2)
- bs = "| "+addSpacing(chars[character.ListOfCharacteristics[1]],3,2)
- strength = "| "+addSpacing(chars[character.ListOfCharacteristics[2]],4,2)
- tgh = "| "+addSpacing(chars[character.ListOfCharacteristics[3]],4,2)
- ag = "| "+addSpacing(chars[character.ListOfCharacteristics[4]],3,2)
- intel = "| "+addSpacing(chars[character.ListOfCharacteristics[5]],4,2)
- per = "| "+addSpacing(chars[character.ListOfCharacteristics[6]],4,2)
- wp = "|"+addSpacing(chars[character.ListOfCharacteristics[7]],3,2)
- fel ="| "+addSpacing(chars[character.ListOfCharacteristics[8]],4,2)
- return ws+bs+strength+tgh+ag+intel+per+wp+fel+" |"
- def getCurrentFatigue(self,fatigue):
- ''' supplies the current fatigue for the character sheet'''
- return " Current Fatigue: "+addSpacing(fatigue,17)+" |"
- def getCoreCharacteristisAndCurrentFatique(self,chars,fatigue):
- '''constructs core characteristis and current fatigue as a single line'''
- return self.getCoreCharacteristicsLine(chars)+self.getCurrentFatigue(999)
- def getPresentDamageHeader(self):
- '''provides the table header for damage'''
- return "| Head | Torso | L. Arm | R. Arm | L. Leg | R. Leg |"
- class character:
- ListOfCharacteristics = ["WS","BS","Strength","Toughness","Agility","Intelligence","Perception","WP","Fell"]
- ListOfCharacteristicNames = ["Weapon Skill","Ballistic SKill","Strength","Toughness","Agility","Intelligence","Perception","Will PowerP","Fellowship"]
- def __init__(self,**kwargs):
- self.fName = kwargs.get("fName","TESTfName")
- self.lName = kwargs.get("lName","")
- self.name = ""
- self.characteristics ={
- character.ListOfCharacteristics[0]:kwargs.get(character.ListOfCharacteristics[0],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[1]:kwargs.get(character.ListOfCharacteristics[1],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[2]:kwargs.get(character.ListOfCharacteristics[2],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[3]:kwargs.get(character.ListOfCharacteristics[3],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[4]:kwargs.get(character.ListOfCharacteristics[4],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[5]:kwargs.get(character.ListOfCharacteristics[5],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[6]:kwargs.get(character.ListOfCharacteristics[6],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[7]:kwargs.get(character.ListOfCharacteristics[7],character.generateCharacteristic(0)),
- character.ListOfCharacteristics[8]:kwargs.get(character.ListOfCharacteristics[8],character.generateCharacteristic(0)),
- }
- self.charClass = "TEST CLASS"
- self.totalWounds = kwargs.get("tWounds",10)
- self.currentWounds = kwargs.get("cWounds",0)
- self.fatique = 0
- self.expierencePoints = 0
- self.experienceToSpend = 0
- self.skills = []
- self.traits = []
- self.talents = []
- self.bonus = []
- self.affinity = {}
- self.bodyParts = {
- "head":"notDamaged",
- "torso":"notDamaged",
- "left arm":"notDamaged",
- "right arm":"notDamaged",
- "left leg":"notDamaged",
- "right leg":"notDamaged"
- }
- self.armor = {
- "head":"notArmored",
- "head":"notArmored",
- "torso":"notArmored",
- "left arm":"notArmored",
- "right arm":"notArmored",
- "left leg":"notArmored",
- "right leg":"notArmored"
- }
- self.armaments = {
- "head":"unArmed",
- "right fore-arm":"unArmed",
- "rigth hand":"unArmed",
- "left fore-arm":"unArmed",
- "left hand":"unArmed",
- "rifle":"unArmed",
- "hold out slot 1":"unArmed",
- }
- def getCharacterData(self):
- '''compiles character data for use in output functions'''
- charData = {"name":self.getFullName(),"class":self.charClass}
- for item in character.ListOfCharacteristics:
- charData.update({item:self.getCharacteristicByName(item)})
- charData.update({"cWounds":self.getCurrentWounds()})
- charData.update({"tWounds":self.getTotalWounds()})
- charData.update({"xp":self.expierencePoints})
- charData.update({"fatique":self.fatique})
- return charData
- def getTotalWounds(self):
- '''returns character's total wounds'''
- return self.totalWounds
- def getCurrentWounds(self):
- '''returns character's current wounds'''
- return self.currentWounds
- def getTotalXP(self):
- '''returns character's expierence.'''
- return self.expierencePoints
- def generateCharacteristic(bonus=0):
- '''generates 1 core characteristic, an int between 0 and 20 and applies any supplied bonus'''
- return random.randint(2,20)+bonus
- def setFullName(self):
- '''sets character's full name by combining first name and lat name'''
- self.name = self.fName+" "+self.lName
- def getFirstName(self):
- '''returns character first name'''
- name = self.name.split()
- return name[0]
- def getFullName(self):
- '''returns a combination of characters first name and last name'''
- return self.fName+" "+self.lName
- def getCharacteristicByName(self,name):
- '''returns characteristic value by supplied name'''
- try:
- return self.characteristics[name]
- except KeyError:
- print(f"no characteristic '{name}' found.")
- def setCharacteristicByName(self,name,valueToMod):
- '''modifies a selected characteristic by a supplied value. raises KeyError is characteristic name is not found.'''
- try:
- self.characteristics[name] += valueToMod
- print(f"{self.getFullName()}'s {name} has been modded by {valueToMod}.")
- except KeyError:
- print(f"no characteristic '{name}' found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement