Look at the thing I did

  • Topic Archived
You're browsing the GameFAQs Message Boards as a guest. Sign Up for free (or Log In if you already have an account) to be able to post messages, change how messages are displayed, and view media in posts.
  1. Boards
  2. Game Design and Programming
  3. Look at the thing I did

User Info: Yongus

Yongus
1 year ago#1
Friend and I watched most of the thenewboston syntax videos for Python 3 and spent 2 hours attempting to piece together our first program / generic text adventure. First experience with coding.

Looking for feedback on silly code and poor conventions.


http://pastebin.com/5ajWwTWM



Kind of stuck on integrating character levels, xp, and level up thresholds.

The math for damage and health is probably stupid

Doubtful that our implementation of classes and creating objects (hero/enemies) is better than bad

Combat will be revised with prompts and options. It's currently (poorly?) automated just to have things work.

Hero and Enemy health will be formatted to print together in more of a typical horizontal information layout you'd find in a traditional RPG

User Info: SeraphLance

SeraphLance
1 year ago#2
Seems reasonable for a first-time-coding thing. Obviously, there's a ton of problems with it, but they're problems that you're pretty much expected to have at your level of experience.

Some simple things:
1. Your formulas are fine (and if they aren't, you'll tweak it through testing), but you'll want to wrap them into some kind of levelUp() or setLevel() method, because as-is it only applies at level 1.
2. All of Erdrick's variables should probably be wrapped in an __init__() like the creatures. It's not strictly necessary, but it helps with consistency.
3. "equipment" should be moved out of Erdrick. Likewise, you'll either want to store the key or some more sophisticated object in the weapon/armor variables. As you add more gear, you'll find that just knowing the attack or defense of what he has equipped doesn't exactly help you figure out what it is.
4. Methods. Lots of methods. Classes are more than just containers of data. You might do well to have it look something like this (just stubbed out to keep the challenge for you, and forgive the formatting):

equipment = {'Copper Sword': 3, 'Leather Tunic': 3} # currently equipped
class Erdrick:
def __init__(self):
self.exp = 0
self.level = 1
self.levelupthresholds = [10, 30, 60, 100]
self.health = self.calculateMaxHealth()
self.weapon = 'Copper Sword'
self.armor = 'Leather Tunic'
def calculateDamage(self):
return + 1 * (self.level - 1) + equipment[self.weapon]
def calculateMaxHealth(self):
return 20 + 10 * (self.level - 1) + equipment[self.armor] #should also be called on level up.
def giveXP(self, amnt):
pass # leaving this to you. This is where you figure out whether/how to level up, and if so, recalculate health.
def takeDamage(self, amnt):
pass # this is where you take damage. You could, for example, return True if the hero died from the hit, False otherwise.

5. Regarding the exp curve, I strongly recommend coming up with a mathematical formula and using that. For example, your level up scheme might look something like this:

def getTotalXPToLevelUp(level):
return 5 * level * (level + 1) # AKA sum of levels x 10.


Somewhat more advanced things:
1. __str__() and __repr__(). __repr__() in particular. This is the canonical way to "print" an object for the user, for either health or something like a stats screen (strongly preferring the latter here).
2. Lambdas are fun. For example, If you wanted extra party members or job classes with their own HP curves, you could do this:

class Character():
#other stuff
def changeJob(self, job):
self.job = job
def calculateMaxHealth(self):
return self.job.hp_formula(self.armor, self.level)

class Job():
def __init__(self, name, hp_formula):
self.name = name
self.hp_formula = hp_formula

#Hero
hero = Job("Hero", lambda armor, level: return 20 + 10 * (level - 1) + equipment[armor])

#Sage
sage = Job("Sage", lambda armor, level: return 10 + 8 * (level - 1) + equipment[armor])


(Don't worry if you don't understand that. It's "advanced" for a reason.)
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.

User Info: scar the 1

scar the 1
1 year ago#3
Wow, recommending lambdas to a newbie. That's cruel :)
Everything has an end, except for the sausage. It has two.

User Info: Cheezmeister

Cheezmeister
1 year ago#4
Not really. Recommending OOP to a newbie, now that's cruel!

Hey Yongus, thanks for sharing! Where can I play it?
I make games!
http://luchenlabs.com

User Info: scar the 1

scar the 1
1 year ago#5
Cheezmeister posted...
Not really. Recommending OOP to a newbie, now that's cruel!

Hey Yongus, thanks for sharing! Where can I play it?

Well that damage was already done, though ;)
Everything has an end, except for the sausage. It has two.

User Info: SeraphLance

SeraphLance
1 year ago#6
I'm fairly convinced that functional programming is only intuitive to true beginners when large dosages of psychoactive substances are involved. With lambdas, I'm giving him a digital joint. You want to kill him!

Actually, the code I wrote wasn't intended to be code I'd write if I were making a similar game. That's not necessarily helpful to a newbie. The lambdas are a special case, but I still probably wouldn't do it that way.
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.

User Info: Cheezmeister

Cheezmeister
1 year ago#7
Please. Digital LSD has no known lethal dose. Not that I'd recommend it to beginners either.

Now, OOP is more like digital codeine. It feels good at first, but then you discover the Habit Pattern is way cheaper, and before you know it you're sucking DHCP in some digitalleyway for one more ObservableAbstractHypodermicSmackFactory().

-Richard Stallman


To get back on topic, check this out https://community.c9.io/t/writing-a-python-app/1609
I make games!
http://luchenlabs.com

User Info: Yongus

Yongus
1 year ago#8
we trashed our code and decided to remake pokemon instead of dragon warrior because more hard and exciting

will update later :p
  1. Boards
  2. Game Design and Programming
  3. Look at the thing I did

Report Message

Terms of Use Violations:

Etiquette Issues:

Notes (optional; required for "Other"):
Add user to Ignore List after reporting

Topic Sticky

You are not allowed to request a sticky.

  • Topic Archived