need help with the code lenght

This is the place for queries that don't fit in any of the other categories.

need help with the code lenght

Postby Serafiks » Mon Jul 28, 2014 7:56 am

Maybe I handle wrong spaces, or maybe what I made really generates a ton of stuff! Well anyway I was programming a game and it didn't even start (i only set let's say some values) and i am already at 5-600 code lines.. so i was wondering
can i store that codes in another .py text and then do something like import fileXXX.py so that it runs from the point where i input it, and then it closes the "main" py file keeps running normally? if so can u tell me how to pls?
Serafiks
 
Posts: 9
Joined: Fri Jul 18, 2014 5:42 am

Re: need help with the code lenght

Postby freddyhard » Mon Jul 28, 2014 12:20 pm

would you have a UML diagram or something similar showing the overall structure of the game?
freddyhard
 
Posts: 36
Joined: Wed Jul 16, 2014 9:32 pm

Re: need help with the code lenght

Postby micseydel » Mon Jul 28, 2014 8:37 pm

I think I have some idea of what you mean, but I'm not quite sure. If you would post your code that would probably illuminate things thoroughly.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1435
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: need help with the code lenght

Postby Serafiks » Tue Jul 29, 2014 6:03 pm

hmmm the code is really huge because in it there are also some drawings in ASCII which take a lot of spaces...
Code: Select all
import random
import time
#VARIABLES NEEDED BY THE GAME#
P1class = "N/A"
P2class = "N/A"
P3class = "N/A"
P4class = "N/A"
invparty = ["Potion","WoodenSword",]
dagger = "[5Damage][35€]"
sword = "[10Damage][70€]"
twoHandedSword = "[+20Damage][-15HP][135€]"
Halberd = "[25Damage][18HP][6AC][150€]"
leather = "[3AC][45€]"
hardleather = "[+4.5 AC][70€]"
ringmail = "[6AC][90€]"
plate = "[11AC][-7.5Damage][210€]"
potion = "[Restores25HP][35€]"
partitaIniziata = True
mercNPC = ["Dagger","Sword","twoHandedSword","Halberd","leather","hardleather","ringmail","plate","Potion"]
checkcounter = ["1","2","3","4"]
checkclassi = ["warrior","smith","tank","mage"]
#DEFINED FUNCTIONS FOR FASTHELP TUTORIAL AND ALPHATEST#
def rules():
    print()
    print("+------------------------------------------------------------------+")
    print("|Every player starts the adventure at level 1                      |")
    print("|You can play more heroes also if you are alone]                   |")   
    print("+------------------------------------------------------------------+")
    time.sleep(3)
    print("|A level 1 each character spawns with [100HP, 1Dmg, 1Armor]        |")
    print("|But when you choose a class it will give you some bonus.          |") 
    print("|[You can see details about classes & bonuses with ClassInfo()]    |")
    print("+------------------------------------------------------------------+")
    time.sleep(5)
    print("|Every player or creature will have the following statistics:      |")
    print("|Health points[HP] Damage[Dmg] Armor[AC] Luck[L] CritRating[CR]    |")
    print("+------------------------------------------------------------------+")
    time.sleep(4)
    print("|If the HP of a player goes to 0 he will be knocked unconciouss    |")
    print("|if instead it goes below -5 he will die permanently               |")
    print("+------------------------------------------------------------------+")
    time.sleep(3)
    print("|Each character will have a Max Health value, this value           |")
    print("|will go down/up each time a player gets damaged or healed.        |")
    print("|HP can be restored with potions, magic or by resting              |")           
    print("+------------------------------------------------------------------+")
    time.sleep(2)
    print("|HP, Damage and Armor will raise when a character levels up!       |")
    print("|Luck and Crit Rating instead can only be raised by items or spells|")
    print("+------------------------------------------------------------------+")
def fasthelp():
    print(" _____________________________________________")
    print(" ..............::COMMANDS#LIST::..............")
    print("+---------------------------------------------+")
    print("| P1() statusP1() PL1hp P2() statusP2() PL2hp |")
    print("|                                             |")
    print("| P3() statusP3() PL3hp P4() statusP4() PL4hp |")
    print("|                                             |")
    print("| shop()  rules()  PL*LVL  help()  partygold  |")
    print("|                                             |")
    print("| rules() tutorial() players invparty  exit() |")
    print("|_____________________________________________|")
    print(" ..............::COMMANDS#LIST::..............")   
    print("Digit commands EXACTLY as they are written in the code above!")
    print()
def ClassInfo():
    print("+--------------------------------------+")
    print("|[WARRIOR]   +5 HP x level             |")
    print("|            +1 AC x level             |")
    print("|            +1 Damage x level         |")
    print("+--------------------------------------+")
    time.sleep(1)
    print("|[TANK]      +8 HP x level             |")
    print("|            +1.5 AC x level           |")
    print("|            +0.5 Damage x level       |")
    print("+--------------------------------------+")
    time.sleep(1)
    print("|[SMITH]  +4 HP x level             |")
    print("|            +0.5 AC x level           |")
    print("|            +0.5 Damage x level       |")
    print("|            *Can repair/modify items  |")
    print("+--------------------------------------+")
    time.sleep(1)
    print("|[MAGE]      +3 HP x level             |")
    print("|            +1 AC x level             |")
    print("|            +0.5 Damage x level       |")
    print("|            -25 STARTING [HP]         |")
    print("|            *Can cast Spells          |")
    print("+--------------------------------------+")
    time.sleep(1)
    print()
    print("[Bonus apply to character when he choices the class]")
    print()
def tutorial():
    print("Welcome to the game tutorial! We will learn the game basic rules, for now let's just focus on the game pannels")   
    print()
    time.sleep(3)   
    fasthelp()
    print()
    print("# You can open this window anytime by typing fastrules() #")
    print()   
    time.sleep(8)   
    print()
    print("In the list above you can see some of the game commands, now we will analyze player commands in detail.")
    print()
    time.sleep(0.8)
    print("Each player can check their status in 2 ways; P() or statusP()")
    print("[AFTER P YOU MUST ADD NUMBER OF THE PLAYER YOU WANT TO CHECK!]")   
    print("For Player 3 for example, you should type --> P3() or statusP3()")
    print()
    time.sleep(3)
    print("Ok, let's assume that we want to check Player 1 details; in this case he will be a Warrior level 4.")
    time.sleep(2.5)
    print("-------------------------------------------")
    print("  -PLAYER 1-")
    print("Name-----> Arthur   #shows the player name")
    print("Class----> Warrior  #shows the player level")
    print("Level----> 4    #shows the player current level")
    print("Damage---> 27   #shows the player current damage")
    print("Armor----> 6    #shows the player current armor")
    print("Max HP---> 158  #shows the player MAX health")
    print("HP-------> 78   #shows the player current health")
    print("-------------------------------------------")
    time.sleep(4)
    print()
    print("# You can open this window anytime by typing P1() #")
    print()   
    time.sleep(3)
    print("We can also see the character statistic in another way for the previous example we used P1()")
    print("Now let's see the graphic display of Player 1 instead, it is similar but it shows less info.")
    print()
    time.sleep(6)
    print("-------------------------------------------")
    print("                  Arthur")
    print("                    ,       WARRIOR")
    print("   ,  {|}          {}")
    print("  / \, | ,        .--.")
    print(" |    =|= >      /.--.\ HEALTH POINTS")
    print("  \ /` | `       |====|     78")
    print("   `   |         |`::`| ")
    print("       |     .-;`\..../`;_.-^-._")
    print("      /\\/  /   |...::..|`   :   `|")
    print("      |:'\ |  / '''::''|   .:.   |")
    print("      \ /\;-,/ \   ::  |   ARMOR |")
    print("       |\ <` >  >._::_.|    6    |")
    print("       | `  `  /___^___|   ':'   |")
    print("       |       |_______\    :    /")
    print("       |       |        \   :   / ")
    print("       |       |___/\___|`-.:.-`")
    print("    DMG| 27     \_ || _/    `")
    print("       |        <_ >< _>")
    print("       |        |  ||  |")
    print("       |        |  ||  |")
    print("       |       _\.:||:./_")
    print("       |      /____/\____\\ ")
    print()
    time.sleep(2)
    print("# You can open this window anytime by typing statusP1() #")
    print()
    time.sleep(3)
    print("The difference between this pannel and the other one we saw before, is that in the first window")
    print("you can see ALL the detailed statistics of that player, while in this one you can only see some")
    print("Max health is not showed, Level is not showed")
    print()
    time.sleep(3)
    print("Let's now see the basic game RULES.")
    time.sleep(1.5)
    rules()
    time.sleep(3)
    print("# You can open this window anytime by typing rules() #")
    time.sleep(1.5)
    print()
    print("Now let's give a look at CLASS DETAILS.")
    time.sleep(4)
    ClassInfo()
    print("That is pretty everything for now!")
    print()
def alphatest():
    ClassInfo()   
    P1()
    statusP1()
    P2()
    statusP2()
    P3()
    statusP3()
    P4()
    statusP4()   
    shop()
#TUTORIAL OR GAME START#
startTut=input("Do you want to start the Tutorial? [Yes/No] ")
startTut=startTut.lower()
print()
if startTut == "yes":
    print()
    tutorial()
else:
    print("You skipped the tutorial, you can do it anytime just by typing tutorial()")
    print()
#GAME START AND CHECK#
print("   [GAME SETTINGS]  ")
print()
players=input("How many heroes do you want to use? [1-4]: ")
print()
while players not in checkcounter:   
    print("Incorrect value! [1 to 4 players admitted]")
    players = (input("Number of heroes: "))
    time.sleep(1)
ClassInfo()
#SET GOLD, PLAYING AND NOT PLAYING CHARACTERS + NAMES + CLASS#
if players == "1":
    PL1 = "is playing"
    PL2 = "Not playing."
    PL3 = "Not playing."
    PL4 = "Not playing."   
    PL1LVL = 1
    PL1tot = 100   
    PL1hp = 100
    PL1arm = 1
    PL1dmg = 1
    PL2LVL = 0
    PL3LVL = 0
    PL4LVL = 0
    partygold = 75
    nameP1=(input("Player 1 name: "))
    P1class=(input("Player 1 choose a class: "))
    P1class=P1class.lower()
    while P1class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P1class=(input("Player 1 choose a class: "))
        P1class=P1class.lower()
    time.sleep(1)   
elif players == "2":
    PL1 = "is playing"
    PL2 = "is playing"
    PL3 = "Not playing."
    PL4 = "Not playing."
    PL1LVL = 1
    PL1tot = 100   
    PL1hp = 100
    PL1arm = 1
    PL1dmg = 1
    PL2LVL = 1
    PL2tot = 100
    PL2hp = 100
    PL2arm = 1
    PL2dmg = 1
    PL3LVL = 0
    PL4LVL = 0
    partygold = 150   
    nameP1=(input("Player 1 name: "))
    P1class=(input("Player 1 choose a Class: "))   
    P1class=P1class.lower()
    while P1class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P1class=(input("Player 1 choose a class: "))
        P1class=P1class.lower()
    time.sleep(1)   
    nameP2=(input("Player 2 name: "))
    P2class=(input("Player 2 choose a Class: "))
    P2class=P2class.lower()
    while P2class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P2class=(input("Player 2 choose a class: "))
        P2class=P2class.lower()
    time.sleep(1)
elif players == "3":
    partygold = 225
    PL1 = "is playing."
    PL2 = "is playing."
    PL3 = "is playing."
    PL4 = "Not playing."
    PL1LVL = 1
    PL2LVL = 1
    PL3LVL = 1
    PL4LVL = 0       
    PL1tot = 100
    PL2tot = 100     
    PL3tot = 100
    PL1hp = 100
    PL2hp = 100   
    PL3hp = 100
    PL1arm = 1
    PL2arm = 1
    PL3arm = 1
    PL1dmg = 1     
    PL2dmg = 1
    PL3dmg = 1
    nameP1=(input("Player 1 name: "))
    P1class=(input("Player 1 choose a Class: "))
    P1class=P1class.lower()
    while P1class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P1class=(input("Player 1 choose a class: "))
        P1class=P1class.lower()
    time.sleep(1)
    nameP2=(input("Player 2 name: "))
    P2class=(input("Player 2 choose a Class: "))
    P2class=P2class.lower()
    while P2class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P2class=(input("Player 2 choose a class: "))
        P2class=P2class.lower()
    nameP3=(input("Player 3 name: "))
    P3class=(input("Player 3 choose a Class: "))
    P3class=P3class.lower()
    while P3class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P3class=(input("Player 3 choose a class: "))
        P3class=P3class.lower()
elif players == "4":
    PL1 = "is playing."
    PL2 = "is playing."
    PL3 = "is playing."
    PL4 = "is playing."
    PL1LVL = 1
    PL1tot = 100   
    PL1hp = 100
    PL1arm = 1
    PL1dmg = 1
    PL2LVL = 1
    PL2tot = 100
    PL2hp = 100
    PL2arm = 1
    PL2dmg = 1
    PL3LVL = 1
    PL3tot = 100
    PL3hp = 100
    PL3arm = 1
    PL3dmg = 1
    PL4LVL = 1
    PL4tot = 100
    PL4hp = 100
    PL4arm = 1
    PL4dmg = 1
    partygold = 300   
    nameP1=(input("Player 1 name: "))
    P1class=(input("Player 1 choose a Class: "))
    P1class=P1class.lower()
    while P1class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P1class=(input("Player 1 choose a class: "))
        P1class=P1class.lower()
    time.sleep(1)
    nameP2=(input("Player 2 name: "))
    P2class=(input("Player 2 choose a Class: "))
    P2class=P2class.lower()
    while P2class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P2class=(input("Player 2 choose a class: "))
        P2class=P2class.lower()
    nameP3=(input("Player 3 name: "))
    P3class=(input("Player 3 choose a Class: "))
    P3class=P3class.lower()
    while P3class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P3class=(input("Player 3 choose a class: "))
        P3class=P3class.lower()
    nameP4=(input("Player 4 name: "))
    P4class=(input("Player 4 choose a Class: "))
    P4class=P4class.lower()
    while P4class not in checkclassi:
        print("Invalid CLASS! [Warrior, Mage, Tank, Smith]")
        P4class=(input("Player 4 choose a class: "))
        P4class=P3class.lower()
# ///  ADD CLASS BONUS TO STARTING VALUES ///
if P1class == "tank":
    PL1tot=PL1tot+8
    PL1hp=PL1hp+8
    PL1arm=PL1arm+1.5
    PL1dmg=PL1dmg+0.5
if P1class == "warrior":
    PL1tot=PL1tot+5
    PL1hp=PL1hp+5
    PL1arm=PL1arm+1
    PL1dmg=PL1dmg+1
if P1class == "smith":
    PL1tot=PL1tot+4
    PL1hp=PL1hp+4
    PL1arm=PL1arm+1
    PL1dmg=PL1dmg+0.5
if P2class == "tank":
    PL2tot=PL2tot+8
    PL2hp=PL2hp+8
    PL2arm=PL2arm+1.5
    PL2dmg=PL2dmg+0.5
if P2class == "warrior":
    PL2tot=PL2tot+5
    PL2hp=PL2hp+5
    PL2arm=PL2arm+1
    PL2dmg=PL2dmg+1
if P2class == "smith":
    PL2tot=PL2tot+4
    PL2hp=PL2hp+4
    PL2arm=PL2arm+1
    PL2dmg=PL2dmg+0.5
if P3class == "tank":
    PL3tot=PL3tot+8
    PL3hp=PL3hp+8
    PL3arm=PL3arm+1.5
    PL3dmg=PL3dmg+0.5
if P3class == "warrior":
    PL3tot=PL3tot+5
    PL3hp=PL3hp+5
    PL3arm=PL3arm+1
    PL3dmg=PL3dmg+1
if P3class == "smith":
    PL3tot=PL3tot+4
    PL3hp=PL3hp+4
    PL3arm=PL3arm+1
    PL3dmg=PL3dmg+0.5
if P4class == "tank":
    PL4tot=PL4tot+8
    PL4hp=PL4hp+8
    PL4arm=PL4arm+1.5
    PL4dmg=PL4dmg+0.5
if P4class == "warrior":
    PL4tot=PL4tot+5
    PL4hp=PL4hp+5
    PL4arm=PL4arm+1
    PL4dmg=PL4dmg+1
if P4class == "smith":
    PL4tot=PL4tot+4
    PL4hp=PL4hp+4
    PL4arm=PL4arm+1
    PL4dmg=PL4dmg+0.5
print()
print("Set game difficulty [1-2-3-4]")
diff = input("1[EASY] 2[MEDIUM] 3[HARD] 4[MULTI]: ")
print()
time.sleep(0.5)
while diff not in checkcounter:
    time.sleep(0.3)
    print()
    print("Invalid choice!![1-2-3-4]")
    time.sleep(0.5)
    diff = input("Select game difficulty ---> ")
    print()
    time.sleep(1)
#EXISTING DATA AT THIS POINT / nameP[1-4] diff[1-4] players[1-4] PL[1-4] PL*tot PL*LVL PL*hp PL*arm PL*dmg]#
def shop():   
    print("                            .-.")
    print("      [T R A D E]          {{@}}")
    print("           <>               8@8")
    print("         .::::.             888")
    print("     @\/W\/\/W\///@         8@8")
    print("      \/^\/\/^\///    _     )8(")
    print("       \_O_<>_O_/     (@)__/8@8\__(@)")
    print("  ____________________ `~\"-=}:{=-\"~`")
    print(" |<><><>  |  |  <><><>|     |.|")
    print(" |<>      |  |      <>|     |Z|")
    print(" |<>      |  |      <>|     |'|")
    print(" |<>   .--------.   <>|     |.|")
    print(" |     |   ()   |     |     |B|")
    print(" |_____| (O\/O) |_____|     |'|")
    print(" |     \   /\   /     |     |.|")
    print(" |------\  \/  /------|     |U|")
    print(" |       '.__.'       |     |'|")
    print(" |        |  |        |     |.|")
    print(" :        |  |        :     |U|")
    print("  \<>     |  |     <>/      |'|")
    print("   \<>    |  |    <>/       |.|")
    print("    \<>   |  |   <>/        |K|")
    print("     `\<> |  | <>/'         |'|")
    print("       `-.|  |.-`           \ /")
    print("          '--'               ^")
    time.sleep(1.5)
    print("ITEMS LIST")
    print(mercNPC)
    print("END OF ITEMS LIST")
    time.sleep(1)
    print("[To know the cost and the statistic of each item, type the item name!]")
    print("[Without blank spaces and in lower case!] [Ex.\"sword\" Ex.\"twohandedsword\"]")
    print()
    print("To buy the item, type the item name followed by a + [Ex. \"sword+\"]")
    time.sleep(1.5)
    print("if your party has enough gold the item will be moved to your inventory")   
def statusP1():
    print("-------------------------------------------")
    print("                 ",nameP1.upper())
    print("                    ,       ",P1class.upper())
    print("   ,  {|}          {}")
    print("  / \, | ,        .--.")
    print(" |    =|= >      /.--.\ HEALTH POINTS")
    print("  \ /` | `       |====|   ",PL1hp)
    print("   `   |         |`::`| ")
    print("       |     .-;`\..../`;_.-^-._")
    print("      /\\/  /   |...::..|`   :   `|")
    print("      |:'\ |  / '''::''|   .:.   |")
    print("      \ /\;-,/ \   ::  |   ARMOR |")
    print("       |\ <` >  >._::_.|  ",PL1arm*2/2 ,"  |")
    print("       | `  `  /___^___|   ':'   |")
    print("       |       |_______\    :    /")
    print("       |       |        \   :   / ")
    print("       |       |___/\___|`-.:.-`")
    print("    DMG|",PL1dmg*2/2,"   \_ || _/    `")
    print("       |        <_ >< _>")
    print("       |        |  ||  |")
    print("       |        |  ||  |")
    print("       |       _\.:||:./_")
    print("       |      /____/\____\\ ")
    print("-------------------------------------------")
def statusP2():
    print("-------------------------------------------")
    print("                 ",nameP2.upper())
    print("                    ,       ",P2class.upper())
    print("   ,  {|}          {}")
    print("  / \, | ,        .--.")
    print(" |    =|= >      /.--.\ HEALTH POINTS")
    print("  \ /` | `       |====|   ",PL2hp)
    print("   `   |         |`::`| ")
    print("       |     .-;`\..../`;_.-^-._")
    print("      /\\/  /   |...::..|`   :   `|")
    print("      |:'\ |  / '''::''|   .:.   |")
    print("      \ /\;-,/ \   ::  |   ARMOR |")
    print("       |\ <` >  >._::_.|  ",PL2arm*2/2 ,"  |")
    print("       | `  `  /___^___|   ':'   |")
    print("       |       |_______\    :    /")
    print("       |       |        \   :   / ")
    print("       |       |___/\___|`-.:.-`")
    print("    DMG|",PL2dmg*2/2,"   \_ || _/    `")
    print("       |        <_ >< _>")
    print("       |        |  ||  |")
    print("       |        |  ||  |")
    print("       |       _\.:||:./_")
    print("       |      /____/\____\\ ")
    print("-------------------------------------------")
def statusP3():
    print("-------------------------------------------")
    print("                 ",nameP3.upper())
    print("                    ,       ",P3class.upper())
    print("   ,  {|}          {}")
    print("  / \, | ,        .--.")
    print(" |    =|= >      /.--.\ HEALTH POINTS")
    print("  \ /` | `       |====|   ",PL3hp)
    print("   `   |         |`::`| ")
    print("       |     .-;`\..../`;_.-^-._")
    print("      /\\/  /   |...::..|`   :   `|")
    print("      |:'\ |  / '''::''|   .:.   |")
    print("      \ /\;-,/ \   ::  |   ARMOR |")
    print("       |\ <` >  >._::_.|  ",PL3arm*2/2,"  |")
    print("       | `  `  /___^___|   ':'   |")
    print("       |       |_______\    :    /")
    print("       |       |        \   :   / ")
    print("       |       |___/\___|`-.:.-`")
    print("    DMG|",PL3dmg*2/2,"   \_ || _/    `")
    print("       |        <_ >< _>")
    print("       |        |  ||  |")
    print("       |        |  ||  |")
    print("       |       _\.:||:./_")
    print("       |      /____/\____\\ ")
    print("-------------------------------------------")
def statusP4():
    print("-------------------------------------------")
    print("                 ",nameP4.upper())
    print("                    ,       ",P4class.upper())
    print("   ,  {|}          {}")
    print("  / \, | ,        .--.")
    print(" |    =|= >      /.--.\ HEALTH POINTS")
    print("  \ /` | `       |====|   ",PL4hp)
    print("   `   |         |`::`| ")
    print("       |     .-;`\..../`;_.-^-._")
    print("      /\\/  /   |...::..|`   :   `|")
    print("      |:'\ |  / '''::''|   .:.   |")
    print("      \ /\;-,/ \   ::  |   ARMOR |")
    print("       |\ <` >  >._::_.|  ",PL4arm*2/2,"  |")
    print("       | `  `  /___^___|   ':'   |")
    print("       |       |_______\    :    /")
    print("       |       |        \   :   / ")
    print("       |       |___/\___|`-.:.-`")
    print("    DMG|",PL4dmg*2/2,"   \_ || _/    `")
    print("       |        <_ >< _>")
    print("       |        |  ||  |")
    print("       |        |  ||  |")
    print("       |       _\.:||:./_")
    print("       |      /____/\____\\ ")
    print("-------------------------------------------")
def P1():       
        print("+-----#PLAYER 1#----+")
        print("|                   |")
        print("| Name----->",nameP1)
        print("| Class---->",P1class.upper())
        print("| Level---->",PL1LVL,"     |")
        print("| Damage--->",PL1dmg*2/2,"   |")
        print("| Armor---->",PL1arm*2/2,"   |")
        print("| Max HP--->",PL1tot,"   |")
        print("| HP------->",PL1hp,"   |")
        print("|                   |")
        print("+-------------------+")
def P2():
        print("+-----#PLAYER 2#----+")
        print("|                   |")
        print("| Name----->",nameP2)
        print("| Class---->",P2class.upper())
        print("| Level---->",PL2LVL,"     |")
        print("| Damage--->",PL2dmg*2/2,"   |")
        print("| Armor---->",PL2arm*2/2,"   |")
        print("| Max HP--->",PL2tot,"   |")
        print("| HP------->",PL2hp,"   |")
        print("|                   |")
        print("+-------------------+")
def P3():
        print("+-----#PLAYER 3#----+")
        print("|                   |")
        print("| Name----->",nameP3)
        print("| Class---->",P3class.upper())
        print("| Level---->",PL3LVL,"     |")
        print("| Damage--->",PL3dmg*2/2,"   |")
        print("| Armor---->",PL3arm*2/2,"   |")
        print("| Max HP--->",PL3tot,"   |")
        print("| HP------->",PL3hp,"   |")
        print("|                   |")
        print("+-------------------+")
def P4():
        print("+-----#PLAYER 4#----+")
        print("|                   |")
        print("| Name----->",nameP4)
        print("| Class---->",P4class.upper())
        print("| Level---->",PL4LVL,"     |")
        print("| Damage--->",PL4dmg*2/2,"   |")
        print("| Armor---->",PL4arm*2/2,"   |")
        print("| Max HP--->",PL4tot,"   |")
        print("| HP------->",PL4hp,"   |")
        print("|                   |")
        print("+-------------------+")
def help():
    print("tutorial(): Starts the tutorial.")
    print()
    print("rules(): Shows the detailed rules of the game.")
    print()
    print("ClassInfo(): Shows the details bonus of classes per level.")
    print()
    print("statusP(): Shows the status of the selected player.[P1,P2,P3,P4]")
    print("     Ex. --> statusP3() ---> will give the status of Player 3")
    print()
    print("P(): Shows the global status of the selected player.[P1,P2,P3,P4]")
    print("     Ex. --> P4() ---> will give the status of Player 4")
    print()
    print("shop(): Opens the shop/trade window if possible at the selected moment.")
    print()
    print("invparty: List of the items in the party's inventory.")
    print()
    print("partygold: Shows the gold owned by the party.")
    print()
    print("players: Shows the number of alive players.")
    print()
class TurnAttHeal(object):
    def __init__(self, starter):
        self.counter = starter
       
    def getHeal(self, amt):
        self.counter = self.counter + amt
        print("Current HP",self.counter + amt)
   
    def getDMG(self,amt):
        self.counter = self.counter - amt
        print(self.counter,"HP left")

    def HPleft(self):
              return self.counter           
###GAME REAL START###
time.sleep(0.5)
print("Ok so ")
Like a good start would be if its possible to store the defined functions in another PY file, most of the space are used by defined functions.. but I am afraid that defined functions must be in the same file...
Serafiks
 
Posts: 9
Joined: Fri Jul 18, 2014 5:42 am

Re: need help with the code lenght

Postby micseydel » Tue Jul 29, 2014 6:53 pm

Let us know in this thread if you want more help than is available here.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1435
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: need help with the code lenght

Postby Kebap » Thu Jul 31, 2014 9:53 am

Hello Serafiks,
Serafiks wrote:I was programming a game and it didn't even start (i only set let's say some values) and i am already at 5-600 code lines..


Looking through your code quickly, many of these lines come from you printing many lines, one by one. There could definitely be some improvements there, but in the end, you indeed need to save the text somewhere you want to print later.

Another reason are lots of lines similar to the following, which could be shrunken easily by using lists or dictionaries, or even classes if you feel it necessary.

Code: Select all
        PL1LVL = 1
        PL1tot = 100
        PL1hp = 100
        PL1arm = 1
        PL1dmg = 1


Code: Select all
    if P1class == "tank":
        PL1tot=PL1tot+8
        PL1hp=PL1hp+8
        PL1arm=PL1arm+1.5
        PL1dmg=PL1dmg+0.5


One more thing, and this is what really makes your code hard to read, you mix function definitions and code logic. Try to first define all functions, nothing in between the definitions. Only after all have been defined, list your other code logic. Some people put this into another function called main(), then only have a single line in the end, which will start main() function. That way, you can just ignore the lengthy function definitions atop, and work on wherever you please.

Depending on your editor, you can even collapse some definitions, so they won't even take up much space on your screen. Hope it helps!
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 397
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], stranac and 5 guests