2012-09-25 20 views
0

我想我的手在爲我寫的筆和紙遊戲製作一個字符發生器(python 2.7)。直到我達到代碼的最後,我一直在努力完成這件事。現在它已經壞了,我無法找到一種方法讓它在最後打印出一個字符表。請記住,我是一個新手,並在這裏使用一堆東西,我只是在試驗。如果任何人都可以幫助我完成工作,並使用代碼中生成的所有信息打印字符表,我將非常感激!我認爲出錯的是,如果代碼在ID生成器中跳過,我需要一種方法讓代碼忽略它。無論如何,這裏是代碼。如何才能使此摘要起作用?

########################################################## 
# Cyberpanky N.O.W Python Character Generator by Ray Weiss 
# 
# Created 9/24/2012 
# 
# Much thanks to Connor Daliposon 
# Mho made a very readable D&D Character Generator 
# That a Python newbie like me could understand                                                         
########################################################## 

# Imports 
import random 
from pprint import pprint 


# Hey there 
print """ 
Hello world & welcome to the CYBERPANKY N.O.W. character generator. 
Programmed by Ray Weiss. 
To quit at anytime, press CNTRL-C. 
""" 

print "Lets figure out your stats first. Press enter to continue." 
raw_input() 

# Stat Roller 
# Rolls 3D6 and adds the sum together and prints 

def roll_stats(): 
    a = random.randint(1, 6) 
    b = random.randint(1, 6) 
    c = random.randint(1, 6) 
    d = random.randint(1, 6) 
    list = [a, b, c, d] 
    list.sort() 
    add = sum(list[1:4]) 
    return add 

# Modifiers 

def pow_mod(): 
    a = "|+1 to hit on mele attack rolls| " 
    b = "|+1 damage on mele attack rolls|" 

    if pow >= 15 and pow < 17: 
     return a 
    if pow >= 17: 
     return a + b 
    else: 
     return " ~no modifiers~" 

def iq_mod(): 
    a = "|-500$ to invest in cyberspace| " 
    b = "|Reroll Street Doc abilities|" 

    if iq >= 15 and iq < 17: 
     return a 
    if iq >= 17: 
     return a + b 
    else: 
     return " ~no modifiers~" 

def agi_mod(): 
    a = "|+1 to hit with ranged weapons| " 
    b = "|-1 to hit with ranged weapons|" 

    if agi >= 12: 
     return a 
    if agi <= 9: 
     return b 
    else: 
     return " ~no modifiers~" 

def con_mod(): 
    a = "|+1 hit point per hit dice|" 
    b = "|-1 hit point per hit dice|" 

    if con >= 15: 
     return a 
    elif con <= 6: 
     return b 
    else: 
     return " ~no modifiers~" 

def cyn_mod(): 
    a = "|Add 10% to earned experience|" 
    b = "|Add 5% to earned experience|" 
    c = "|Subtract 10% from earned experience|" 
    d = "|Subtract 20% from earned experience|" 

    if cyn >= 15: 
     return a 
    elif cyn > 12 and cyn < 15: 
     return b 
    elif cyn > 6 and cyn < 9: 
     return c 
    elif cyn <= 6: 
     return d 
    else: 
     return " ~no modifiers~" 

def cha_mod(): 
    a = "|+1 to reaction rolls|" 
    b = "|-1 to reaction rolls|" 

    if cha >= 15: 
     return a 
    if cha <= 8: 
     return b 
    else: 
     return " ~no modifiers~" 

# Prints stats + modifiers. 
pow = roll_stats() 
print "Power:", pow, pow_mod() 
iq = roll_stats() 
print "Intelligence:", iq, iq_mod() 
agi = roll_stats() 
print "Agility:", agi, agi_mod() 
con = roll_stats() 
print "Constitution:", con, con_mod() 
cyn = roll_stats() 
print "Cynicism:", cyn, cyn_mod() 
cha = roll_stats() 
print "Charisma:", cha, cha_mod() 

print "\nIf you dont like your stats, tough shit. This is Cyberpanky N.O.W." 
print "\nPress enter to continue." 
raw_input() 

# Choose Class 

print """In Cyberpanky N.O.W. there are only 3 character classes. 

1. Samurai: Badass mercenaries. Can make multiple attacks. 
------------------------------------------------------------------------------ 
2. Street Docs: Hackers/Doctors. Can heal & hack. 
------------------------------------------------------------------------------ 
3. Shaman: Magical prophets that follow spirit animals and cast miracles 
------------------------------------------------------------------------------ 
""" 
type = int(raw_input("Please type a 1, 2, or 3 > ")) 

if type == 1: 
    character_class = "Samurai" 
    class_power = """* Attack multiple times for a -2 to hit penalty. 
* Uses a D10 for Physical hit box. 
* Has a + 1 to hit bonus that levels up to level 5. 
""" 
    name = raw_input("Alright {}, tell me your name >".format(character_class)) 

elif type == 2: 
    character_class = "Street Doc" 
    class_power = """* Roll IQ to mess with electronics 
* Can heal party members after combat for 1D4 Hit Points 
* Can perform cyberwear installation or surgery with proper tools. 
""" 
    name = raw_input("Alright {}, tell me your name >".format(character_class)) 

elif type == 3: 
    character_class = "Shaman" 
    class_power = """* Can cast Miracles. 
* Can call for a saving grace if they are on their last Cool Hit Box 
* Can do favors for their god for more miracles, or pay a tithe. 
""" 
    name = raw_input("Alright {}, tell me your name >".format(character_class)) 

# Alignment 

print"""\nAlright {}, pick an alignment, it's not that important; 

1. Narcissist: Cocky bastard, you think you are the best. 
------------------------------------------------------------------------------ 
2. Neutral: Pretty self explanatory dipshit. 
------------------------------------------------------------------------------ 
3. Nihilist: You care about nothing Lebowski, You'll cut off their Johnson. 
""".format(name) 

x = int(raw_input("Please type a 1, 2, or 3 > ")) 

if x == 1: 
    alignment = "Narcissist" 

elif x == 2: 
    alignment = "Neutral" 

elif x == 3: 
    alignment = "Nihilist" 

print "\nOk you chose {} for an alignment, press enter to continue.".format(
                   alignment) 
raw_input() 

# Functions for ID generation 

def gen_id(): 
    global gender_id 
    one = "1. Straight male" 
    two = "2. Gay male" 
    three = "3. Transgender male pre-op" 
    four = "4. Transgender male post-op" 
    five = "5. Bisexual male" 
    six = "6. Straight female" 
    seven = "7. Gay female" 
    eight = "8. Transgender female pre-op" 
    nine = "9. Transgender female post-op" 
    ten = "10. Bisexual female" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "\nPlease hit enter to roll 1D10" 
    raw_input() 
    gender_id = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(gender_id) 
    raw_input() 

# Ethnic Profile 
def eth_pr(): 
    global ethnic_pr 
    one = "1. Native American" 
    two = "2. West European" 
    three = "3. East European" 
    four = "4. North Asian" 
    five = "5. South Asian" 
    six = "6. Pacific" 
    seven = "7. North African" 
    eight = "8. South African" 
    nine = "9. Slavic/Caucuses" 
    ten = "10. Hispanic" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "\nPlease hit enter to roll 1D10" 
    raw_input() 
    ethnic_pr = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(ethnic_pr) 
    raw_input() 

# Family Class Distinction 
def fam_cls(): 
    global fcd 
    one = "1. Homeless" 
    two = "2. Impoverished" 
    three = "3. Lower Class" 
    four = "4. Lower Middle Class" 
    five = "5. Middle Class" 
    six = "6. Comfortable" 
    seven = "7. Upper Middle Class" 
    eight = "8. Upper Class" 
    nine = "9. Job Creators" 
    ten = "10. Warren Buffett" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    fcd = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(fcd) 
    raw_input() 

# Whats Good With Your Folks 
def wha_goo(): 
    global wg, one_x, two_x 
    one_x = "1. Things Are Good With Your Folks; Go to Current Family Affairs" 
    two_x = "2. Your folks are fucked; go to Your Folks Got Fucked" 
    list = [one_x, two_x] 
    pprint(list) 
    print "Please hit enter to roll 1D2" 
    raw_input() 
    wg = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(wg) 
    raw_input() 

# Your Folks Got Fucked 
def yo_fo(): 
    global fogo_fuck 
    one = "1. Your parents were mugged and murdered, just like Batman" 
    two = "2. Your parents were both convicted of murder" 
    three = "3. Parents decapitated by a truck" 
    four = "4. Parents addicted to coke, put you in an orphanage" 
    five = "5. Parents were corporate spies and assinated in front of you" 
    six = "6. Parents abandonded you at a young age and joined a cult" 
    seven = "7. Your parents died from STDs contracted from aldultery" 
    eight = "8. Parents owed mob a bunch of money, sleeping with fishies" 
    nine = "9. Nuclear explosion incinerated parents, their shadow remains" 
    ten = "10. Parents shot themselves immediately after you were born." 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    fogo_fuck = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(fogo_fuck) 
    raw_input() 

# Current Family Affairs 
def cu_fa(): 
    global cur_fam, one_y, two_y 
    one_y = "1. Things are ok with family, go to Nature Or Nurture" 
    two_y = "2. Your family is fucked, go to Your Family Is Fucked" 
    list = [one_y, two_y] 
    pprint(list) 
    print "Please hit enter to roll 1D2" 
    raw_input() 
    cur_fam = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(cur_fam) 
    raw_input() 

# Your Family Got Fucked 
def fa_fu(): 
    global fam_fuk 
    one = "1. Market tanked with president Paul, dead broke family." 
    two = "2. Home invaders raped and murded the women in your family" 
    three = "3. Racial Supremisicist drove your family from their home" 
    four = "4. Whole family was abducted by aliens, never seen again" 
    five = "5. Radiation leak hospitalized your whole family." 
    six = "6. Family was accidentally napalmed by the UN, all dead." 
    seven = "7. Family came down with malaria" 
    eight = "8. Family has some obvious dealings with Illuminati" 
    nine = "9. Family eaten alive by cannibals" 
    ten = "10. Make it up dipshit" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    raw_input() 
    fam_fuk = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(fam_fuk) 
    raw_input() 

# Nature Or Nurture 
def na_nu(): 
    global nat_nur 
    one = "1. Your childhood was very boring & average" 
    two = "2. Your childhood was spent moving from city to city" 
    three = "3. Your childhood was depraved; hungry and lonely" 
    four = "4. Your childhood was rewarding, social & fun." 
    five = "5. You were a sick child, spent a lot of time in bed" 
    six = "6. You were sent to a preppy boarding school as a kid" 
    seven = "7. You got addicted to drugs; it screwed you up." 
    eight = "8. You killed another kid, spent time in a hospital" 
    nine = "9. You were a child genius, but had few friends" 
    ten = "10. Make it up dipshit" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    nat_nur = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(nat_nur) 
    raw_input() 

# General Disposition 
def ge_di(): 
    global gen_dis 
    one = "1. Friendly" 
    two = "2. Unfriendly" 
    three = "3. Shy" 
    four = "4. Outgoing" 
    five = "5. Unpretentious" 
    six = "6. Pretentious" 
    seven = "7. Hyperactive" 
    eight = "8. Depressed" 
    nine = "9. Wonderful Human Being" 
    ten = "10. Scumbag" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    gen_dis = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(gen_dis) 
    raw_input() 

# Whats the most important thing in the world 
def wh_wo(): 
    global wha_wor 
    one = "1. Money" 
    two = "2. Kicking ass" 
    three = "3. Getting fucked up" 
    four = "4. Family & friends" 
    five = "5. Business" 
    six = "6. The internet" 
    seven = "7. Faith" 
    eight = "8. Style" 
    nine = "9. Anarchy" 
    ten = "10. Selfishness" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    wha_wor = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(wha_wor) 
    raw_input() 

# Who is to blame for the worlds problems? 
def wh_pr(): 
    global who_pro 
    one = "1. Corporations" 
    two = "2. Leftists" 
    three = "3. Fate" 
    four = "4. Religion" 
    five = "5. The Illuminatus" 
    six = "6. The News Media" 
    seven = "7. The UN" 
    eight = "8. Your Neighbors" 
    nine = "9. Aliens" 
    ten = "10. President Ron Paul" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    who_pro = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(who_pro) 
    raw_input() 

# How do you solve the worlds problems 
def ho_pr(): 
    global how_pro 
    one = "1. Kill them all" 
    two = "2. But them out" 
    three = "3. Intimidation" 
    four = "4. Diplomacy" 
    five = "5. Free trade" 
    six = "6. Seduction" 
    seven = "7. New-Age spirituality" 
    eight = "8. Religious fanaticism" 
    nine = "9. Federal power" 
    ten = "10. Who gives a shit" 
    list = [one, two, three, four, five, six, seven, eight, nine, ten] 
    pprint(list) 
    print "Please hit enter to roll 1D10" 
    raw_input() 
    how_pro = random.choice(list) 
    print "You rolled {}, press enter to continue.".format(how_pro) 
    raw_input() 


# ID Generation 

print ("Alright {}, now we need to figure out your personality & life story." 
                   .format(name)) 
print "\n\t\t1. Ethnics, Genes, & Looks" 
print "\nTo figure out your age, we add 15 to 1D10.\n" 
age = random.randint(1, 10) + 15 
print "Press enter to continue dipshit." 
raw_input() 
print "Age:", age 
print "\t\tGender Identity\n" 
gen_id() 
print "\t\tEthnic Profile\n" 
eth_pr() 
print "\t\t2. Ballz Of Our Fathers" 
print "\n" 
print "\t\tFamily Class Distinction" 
fam_cls() 
print "\t\tWhat's Good With Your Folks" 
wha_goo() 
if wg == one_x: 
    fogo_fuck = "none" 
    print "\t\tCurrent Family Affairs" 
    cu_fa() 
    print "\t\tNature Or Nurture?" 
    na_nu() 
    if cur_fam == one_y: 
     fam_fuk = "none" 
     print "\t\tNature Or Nurture?" 
     na_nu() 
    if cur_fam == two_y: 
     print "\t\t Your Family Is Fucked" 
     fa_fu() 
if wg == two_x: 
    print "\t\tYour Folks Got Fucked" 
    yo_fo() 
    print "\t\tCurrent Family Affairs" 
    cu_fa() 
    print "\t\tNature Or Nurture?" 
    na_nu() 
    if cur_fam == one_y: 
     print "\t\tNature Or Nurture?" 
     na_nu() 
    if cur_fam == two_y: 
     print "\t\t Your Family Is Fucked" 
     fa_fu() 
print "\t\t3. What Makes you tick" 
print "\n" 
print "\t\tGeneral Disposition" 
ge_di() 
print "\t\tWhat's The Most Important Thing In The World?" 
wh_wo() 
print "\t\tWho Is To Blame For The World's Problems?" 
wh_pr() 
print "\t\tHow Do You Solve Your/The Worlds Problem" 
ho_pr() 

#Starting Money 
gold = roll_stats() * 100 

print "Ok so lets sum that up, please hit enter to continue" 
raw_input() 

print""" 
------------------------------------------------------------------------------ 
""" 

# Character Sheet Function. 
def char_shee(): 
    print "Name:", name 
    print "Class:", character_class 
    print "Class Powers:", class_power 
    print "Alignment:", alignment 
    print "Power:", pow, pow_mod() 
    print "Intelligence:", iq, iq_mod() 
    print "Agility:", agi, agi_mod() 
    print "Constitution:", con, con_mod() 
    print "Cynicism:", cyn, cyn_mod() 
    print "Charisma:", cha, cha_mod() 
    print "All Characters Start With 3 Hit Dice" 
    print""" 
\t\t{0}' History 
\t\t------------------ 
\t\tAge:{1} 
\t\t{2} 
\t\t{3} 
\t\t{4} 
\t\t{5} 
\t\t{6} 
\t\t{7} 
\t\t{8} 
\t\t{9} 
\t\t{10} 
\t\t{11} 
\t\t{12} 
\t\t{13} 
\t\t{14} 
""".format(name, age, gender_id, ethnic_pr, fcd, wg, fogo_fuck, cur_fam,fam_fuk, nat_nur, gen_dis, wha_wor, who_pro, how_pro) 

char_shee() 

讓我知道如果我公佈這在錯誤的地方,或者如果我需要從腰包裏掏出更多的信息,但我認爲香港專業教育學院終於公佈這在正確的地方這個時候:)

回答

1

你得到一個IndexError因爲你不擁有電子在上線517 .format()語句nough位置參數,您應該有15個,但你只得到了14

如果您刪除行516:

\t\t{14} 

一切都將正常工作。

+0

我想我回答了我自己的問題,當它沒有選擇時,添加了幾行說fam_fuk =「none」的行,現在看起來像它的工作!非常感謝! – lerugray

0

使用班

class player(object): 
     def __init__(self): 
      self.pow = roll_stats() 
      self.iq = roll_stats() 
      self.agi = roll_stats() 
      self.con = roll_stats() 
      self.cyn = roll_stats() 
      self.cha = roll_stats() 
      self.special = '' 
     def __str__(self): 
      return """" 
     Power:%s 
     Intelligence:%s 
     Agillity:%s 
     Constitution:%s 
     Cynasism:%s 
     Charisma:%s 
     %s 
"""%(self.pow,self.iq,self.agi,self.com,self.syn,self.cha,self.special) 

,只是做

p = player() 
print p 
+0

我有一種感覺,我可以使用類使事情變得更加相似,但我還沒有起牀到書中IM班,又是那麼的學習我沒有嘗試過使用它們,生病玩弄這雖然, 謝謝! – lerugray

0

這不是你的問題,但讓我添加roll_stats的更改版本。

return roll_stats(): 
    def d6(): 
     return random.randint(1, 6) 

    return sum(sorted((d6(), d6(), d6(), d6()))[1:4]) 
+0

太棒了!我很感激! – lerugray

相關問題