RuneStorm
http://www.runestorm.com/forums/

Any Python coders out there?
http://www.runestorm.com/forums/viewtopic.php?f=6&t=66167
Page 1 of 1

Author:  Captain Xavious [ Tue Sep 16, 2008 8:01 am ]
Post subject:  Any Python coders out there?

I've got a class teaching Python at college, and its pretty fun, but it is a bit hard to follow along with my instructor when she tells us how various functions and expressions and stuff work, so I decided to start making a game in class. Its planned to be a simple 2D hack 'n slash RPG using a modified, heavily cut down version of D&D 4th's core gameplay, and so far all I got done is a basic character creation. While it does pretty much what I want it to do, I'd like to add in a few little things that just make it a bit cooler, like a custom description of your character based off your attributes. For some reason though, it keeps defaulting to set strings that should not be going off...

Here's my code (excuse some of the mess, I'm trying several things at once to try and get this dang description thing working):
Code:
# RPG game
# by Casey Johnson

import random

BaseStrBonus = 0
BaseDexBonus = 0
BaseIntBonus = 0

CharName = raw_input("What is your character's name? ")
Stat1 = random.randrange(10) + 7   
Stat2 = random.randrange(10) + 7
Stat3 = random.randrange(10) + 7
print "\nYou rolled a",Stat1,", a",Stat2,", and a",Stat3,"."

print "===\n1. Warrior\n2. Archer\n3. Wizard\n4. Rogue\n==="
CharClass = int(raw_input("Class? (Enter number of your class) "))
while (CharClass < 1 or CharClass > 4):
    CharClass = int(raw_input("Sorry, but that is not one of the options.\nPlease pick again: "))

if CharClass == 1:
    BaseStrBonus = 3
    BaseDexBonus = 2
    BaseIntBonus = 1
    BaseHealthBonus = 12
    BaseManaBonus = 2
    PlayerClass = "Fighter"
    print "You are", CharName, "the Warrior.\nYou can dish out the damage in melee and still take a beating."

if CharClass == 2:
    BaseStrBonus = 2
    BaseDexBonus = 3
    BaseIntBonus = 1
    BaseHealthBonus = 10
    BaseManaBonus = 2
    PlayerClass = "Archer"
    print "You are", CharName, "the Archer.\nYou prefer to fight from afar, resorting to melee only as a fallback."

if CharClass == 3:
    BaseStrBonus = 1
    BaseDexBonus = 2
    BaseIntBonus = 3
    BaseHealthBonus = 6
    BaseManaBonus = 12
    PlayerClass = "Wizard"
    print "You are", CharName, "the Wizard.\nYou are a master of the arcane arts, destroying enemies with your magic."   

if CharClass == 4:
    BaseStrBonus = 1
    BaseDexBonus = 3
    BaseIntBonus = 2
    BaseHealthBonus = 8
    BaseManaBonus = 6
    PlayerClass = "Rogue"
    print "You are", CharName, "the Rogue.\nYou prefer stealth over brute force and know how to take advantage of magic."   

CharStrength = Stat1 + BaseStrBonus
CharDexterity = Stat2 + BaseDexBonus
CharIntelligence = Stat3 + BaseIntBonus

CharStrModifier = (CharStrength - 10) / 2
CharDexModifier = (CharDexterity - 10) / 2
CharIntModifier = (CharIntelligence - 10) / 2

CharStrRating = ""

if (CharStrength <= "11"):
    CharStrengthRating = "Low"
elif (CharStrModifier >= "16"):
    CharStrRating = "High"
else:
    CharStrRating = "Med"
   

CharHealth = CharStrength + BaseHealthBonus
CharInitiative = CharDexModifier
CharMana = CharIntModifier + BaseManaBonus

StrDesc = ""
DexDesc = ""
IntDesc = ""

StrDescLow = "Though relatively weak,"
StrDescMed = "Despite having an average build,"
StrDescHigh = "While exceptionally strong,"

DexDescLow = "you have rather poor reflexes,"
DexDescMed = "your dexterity is nothing special,"
DexDescHigh = "you are unbelievably  nimble,"

IntDescLow = "and you're far from being the brightest hero around."
IntDescMed = "and you're relatively smart."
IntDescHigh = "and you are considered a genius among peers."

if CharStrRating == "High":
    StrDesc = StrDescHigh
else:
    if CharStrRating == "Low":
        StrDesc = StrDescLow
    else:
        StrDesc = StrDescMed
   
if (CharDexModifier >= "3"):
    DexDesc = DexDescHigh
if (CharDexModifier < "3" and CharDexModifier > "0"):
    DexDesc = DexDescMed
if (CharDexModifier < "1"):
    DexDesc = DexDescLow

if CharIntModifier >= "3":
    IntDesc = IntDescHigh
if CharIntModifier <= "2" and CharIntModifier >= "1":
    IntDesc = IntDescMed   
if CharIntModifier < "1":
    IntDesc = IntDescLow

print "Name: ", CharName
print "Class: ", PlayerClass
print "Description: ",StrDesc,DexDesc,IntDesc
print "Health: ",CharHealth
print "Initiative  Bonus: ",CharInitiative
print "Mana: ",CharMana
print "Strength: ",CharStrength," (",CharStrModifier,")"
print "Dexterity: ",CharDexterity," (",CharDexModifier,")"
print "Intelligence: ",CharIntelligence," (",CharIntModifier,")"


raw_input("Hit enter to exit.")


Anyone got any suggestions?

Author:  P_Colossus [ Tue Sep 16, 2008 9:47 am ]
Post subject:  Any Python coders out there?

No, but now i want to learn that to, lol. !lol

Author:  Bjossi [ Tue Sep 16, 2008 9:57 am ]
Post subject:  Any Python coders out there?

Xav, comment out all code that is not necessary to power up the descriptions. If the source of the issue is not obvious, commenting out irrelevant code is the best thing to do and then keep on commenting out stuff until it finally prints out descriptions correctly. Then you got an idea of where the problem lies.

Author:  Captain Xavious [ Tue Sep 16, 2008 10:09 am ]
Post subject:  Any Python coders out there?

That sounds like a good idea. But I don't know how or if I can comment out large chunks with python. Need to figure that out. Gonna be pretty ugly until then. :p
EDIT: Found the Comment Out button! :D

And P_Colossus, I did this in one day, and my programming knowledge is pretty much zero. Not exactly hard to do. ;)

Just take other code, figure out how various things work, and why they work, then go from there.

Author:  Bjossi [ Tue Sep 16, 2008 10:19 am ]
Post subject:  Any Python coders out there?

That is one way of learning programming; checking out how stuff works, find out why it works like that, and then use it to make your own stuff.

But of course it can get very hard once the code gets big and messy. That is where school comes to the rescue in its shiny armor. :P

Author:  Captain Xavious [ Tue Sep 16, 2008 10:35 am ]
Post subject:  Any Python coders out there?

Alright, cut down the code to just the minimums on a separate file, and I'm still not getting it.

Code:
import random

BaseStrBonus = 0

Stat1 = random.randrange(10) + 7   
print "\nYou rolled a",Stat1

CharStrength = Stat1 + BaseStrBonus

CharStrModifier = (CharStrength - 10) / 2

CharStrRating = ""

if (CharStrModifier <= "0"):
    CharStrengthRating = "Low"
else:
    if (CharStrModifier >= "3"):
        CharStrRating = "High"
    else:
        CharStrRating = "Med"

StrDesc = ""

StrDescLow = "Though relatively weak,"
StrDescMed = "Despite having an average build,"
StrDescHigh = "While exceptionally strong,"

if CharStrRating == "High":
    StrDesc = StrDescHigh
else:
    if CharStrRating == "Low":
        StrDesc = StrDescLow
    else:
        StrDesc = StrDescMed

print "Description: ",StrDesc
print "Strength: ",CharStrength," (",CharStrModifier,")"

raw_input("Hit enter to exit.")


Everything seems to add up right in the code, but it keeps defaulting to the MedStrDesc.

Will keep working at this, but I gotta admit, its getting extremely frustrating.

Author:  Tyster [ Tue Sep 16, 2008 10:51 am ]
Post subject:  Any Python coders out there?

O've got one thing to say. Breaking up your code into functions is a very good idea. This will help keep your main function clean, small, and easily readable. If you have not yet learned about functions/methods, then you can definately practice using them with your game code after your class gets around to them. This also makes it more likely for people to actually read through your code and help you, since nobody wants to read through 1,000 lines of code to try to help someone find an error.

A couple specific applications that could really clean up your main function:

[quote author= selectClass();
printCharacterStats();
# Now is that a clean main function or what?
}

int selectClass(void)
{
# This takes care of the whole process of
# setting up a class for a payer, including
# prompting the player for input and
# setting characteristics
}

void printCharacterStats(void)
{
print "Name: ", CharName
print "Class: ", PlayerClass
print "Description: ",StrDesc,DexDesc,IntDesc
print "Health: ",CharHealth
print "Initiative Bonus: ",CharInitiative
print "Mana: ",CharMana
print "Strength: ",CharStrength," (",CharStrModifier,")"
print "Dexterity: ",CharDexterity," (",CharDexModifier,")"
print "Intelligence: ",CharIntelligence," (",CharIntModifier,")"
}
[/quote]

I've never used Python, but this sure does look very similar to C. Also, when your class gets to objects or structures, then you can really take off. I'm not sure if Python is object-oriented, though. if not, then structures should be good enough for this application.

Author:  Captain Xavious [ Tue Sep 16, 2008 1:41 pm ]
Post subject:  Any Python coders out there?

Python can be object-oriented, but it doesn't have to, I guess. Not sure how that works.

But anyways, yeah, I didn't get to objects or structures in class yet, unfortunately.

I'll definitely break it up like that, looks much nicer! Thanks!

Author:  Sargeant Smash [ Wed Sep 17, 2008 10:52 am ]
Post subject:  Any Python coders out there?

You missed class today Xavious where were you? I actualy learned some stuff today! Python is simple and very interesting, and i kinda like it! Maybe now I'll be able to help you on some stuffs.

Author:  Bjossi [ Wed Sep 17, 2008 11:00 am ]
Post subject:  Any Python coders out there?

I may be learning C#, but all of us will be coding geniuses before long. :P

Author:  Tyster [ Wed Sep 17, 2008 3:26 pm ]
Post subject:  Any Python coders out there?

C#?

Edit: I really should learn to use Google before asking questions

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/