HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonModerate

RPG User File (Stats Holder)

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
holderfileuserstatsrpg

Problem

This is my Player file. It is mainly for saving purposes. Is it easy to understand and read? Anything I should add or change for improvements?

```
#Programmer: DeliriousSyntax
#Player.py
#Date: November 22, 2015

import math

class User:
def __init__(self, user, class_type):
self.user = user
self.level = 1
self.xp = 1
self.Class = class_type
self.dex_attr = 0
self.tech_attr = 0
self.strength_attr = 0
self.health_attr = 0
self.energy_attr = 0
self.boss_kills = 0
self.ordinary_kills = 0
self.towns_visited = 0
self.money_earned = 0
self.money = 0
self.black_jack_wins = 0
self.beers = 0
self.houses = 0
self.rent = 0
self.shops = 0

@property
def drinking_class(self):
if self.beers 25:
return "Light Drinker"
elif self.beers > 250:
return "Alcoholic"

@property
def health(self):
return 110 + (self.health_attr * 4)

@property
def energy(self):
return 50 + (self.energy_attr * 4)

@property
def strength(self):
return 15 + self.strength_attr

@property
def tech(self):
return 15 + self.tech_attr

@property
def dex(self):
return 15 + self.dex_attr

@property
def lvl_xp(self):
return int(math.sqrt(float(self.level) 999) self.level)

def update_level(self):
while self.xp >= self.lvl_xp:
self.level+=1
print("Level Up! \nLevel {} reached! {}xp to next level.".format(lvl, lvl_xp))

def stats(self):
return('\n\n==============Player Stats===============\n' +
'|-{:8}/{:<8}-|\n'.format(' XP', self.xp, self.lvl_xp)+
'|-{:<17}-|-{:^17}-|\n'.format(' Boss Kills', self.boss_kills)+
'|-{:<17}-|-{:^17}-|\n'.format(' Normal Kills', self.ordinary_kills)+
'|-{:<17}-|-{:^17}-|\n'.format(' Towns Visi

Solution

You seem to have a lot of counts of things. towns_visited is a good example. This implies to me that in your game, you would have a variety of towns to be visited. Perhaps, having an empty set for which towns you have visited, and instead of towns_visited, just use a count of that set. Every time you visit a town, add it to the set. The same would apply to houses. Every time you buy a house, add the specific house object to a list and that would take care of houses and what you do with them. I'm assuming you know the difference between a list and a set.

Context

StackExchange Code Review Q#111835, answer score: 11

Revisions (0)

No revisions yet.