Text Based Game - Please Review!

Text Based Game - Please Review!

Postby Seanliu » Sun Mar 30, 2014 4:14 pm

Hi, I am using PyCharm, which is real sweet (ooh, Americano!) but everytime i try to run the code, the start menu
"Enter any key then SPACE to play" works, then "Press N to go to the village" doesn't. Why? When I enter n, or in fact, any key, it says "Name not Defined'. Im Confused.

ALSO, Please have a look at my code, and rate the game! It is in Pre-Alpha, and will be for months, but I'm a budding game developer! THX! :D Oh yea, Here is my code (IDK how to shorten the code so it is in a pretty lil' box.)

Code: Select all
# Letting me do random.randint!#
import random, time
#f
#This sets up my name, Magic Points (MP) and Health/Hit Points! (HP)
window_height = 200
window_width = 300

def setup():
    global playerName
    global ATK
    global HP
    global XP
   
XP = False
HP = random.randint(10, 35)
ATK = random.randint(10, 25)
#This lets me skip three spaces! Convenient!#
def threeSpaces ():
    print("")
    print("")
    print("")

#This is the opening sequence.#
def openSequence():
    print("|-----|        ________   ____     ")
    print("|_____|           |      |    |     ")
    print("|    \    ____    |      |____|     ")
    print("|     \  |    |   |      |    |   ")
    print("|      \ |____|   |     /      \  ")
    print('BY SEANLIU')
#This prints the house (its supposed to be a village Lol) in the future code.
def startvillage ():
    print("          ________________        ")
    print("         /   -         -   \      ")
    print("        /         -         \  ")
    print("       /________________-_-__\ ")
    print("       |                    |  ")
    print("       |    |---|           |  ")
    print("       |    |  o|           |  ")
    print("       |    |   |           |  ")
    print("       ______________________  ")

threeSpaces()
#Starting Sequence
print("\nPRESS ANY KEY, THEN ENTER TO START YOUR QUEST ")
raw_input(">>")
print("GAME STARTING")
threeSpaces()
openSequence()
wood=random.randint(10, 50)
#T his is the villager stats.#

print("\n You landed in a strange place, in middle of a meadow. To the north you see a valley, and you decide to explore the valley, as you see a village there.\n PRESS N TO GO THERE ")
goNorthValley = input('>>')

def Set1 ():
        if (goNorthValley == "N"):
            print("You walk over to the valley.")
        elif(goNorthValley == "n"):
            print("You walk cautiously over.")
        else:
            threeSpaces()
            print("Go over to the village first, then explore later.")
            Set1()



Set1()
threeSpaces()
startvillage()
def npcStats ():
     global npcName
     global npcResponce
#Villager Names and Greetings
responces = ["Greetings stranger! Haha, that's from the theatre.", "Want one of the best cookies around?", "Oh hi!", "Er... Hello! Never seen you before!"]
npcnamechoice = ["Roger", "Kyle", "Markus", "Sean", "Mason", "Corrie",]
random.shuffle(npcnamechoice)

print ("[VILLAGER}: Hello, I am", npcnamechoice[0] + ".", "would you like to talk to me? ")
print(" Press Y to talk to the villager, or E to ignore him.")
random.shuffle(responces)

yesNo1 = input()

if ( yesNo1 == "Y" ):
       print("[VILLAGER]:,"  + responces[0] )
elif ( yesNo1 == "y" ):
       print("[VILLAGER]: " + responces[0])
elif ( yesNo1 == "E" ):
       print("[VILLAGER]: Goodble.")
elif (yesNo1 == "e" ):
       print("[VILLAGER]: Very well. Goodbye.")
else:
    threeSpaces()
    print("INVALID ENTRY")


print("[VILLAGER]: Before you go, what should I call you?")
playeName = input("Enter your Username >")


def enemyKnight ():
   global knightHP
   global knightATK

knightHP = random.randint(3,5)
knightATK = random.randint(2, 4)


print("[VILLAGER]: Oh no! The DARK KING's KNIGHTS have come! They will take all our stufff as tax! We have nothing to give them! Save usssss!")

threeSpaces()
print("[VILLAGER]: STRANGER! WILL YOU HELP US?")
fightorFlight1 = input("Choose whether to Fight or Flight. If you wish to fight, press A, floowed by ENTER. Else, press H, followed by ENTER.")
#This is the primitive fight system, but has no loop.
if ( fightorFlight1 == "A" ):
   print("You swing your sword at the unfortunate soul, and causes" , ATK, "damage.")
   knightHP= knightHP - ATK
   print("The knight has", knightHP, "HP left.")
   print("The knight swings a sword at you, causing" ,knightATK,"Damage.")
   HP = HP - knightATK
   print("Ouch! You have", HP,'HP left! Be careful!')
elif( knightHP >= 0):
    print("[VILLAGER]: KEEP GOIN!")
    print("The knight swings his dark sword at you and causes",knightATK,"Damage!")
    HP = HP-knightATK
    print("You have", HP, "HP left, but you swing the sword at its neck, and decacipates the knight. It is dead immediately.")
    if (knightHP <= 0):
        print("You killed the knight!")
elif(fightorFlight1 == "h"):
    print("You decide to leave the village to its fate.")
elif(fightorFlight == "H"):
    print("You leave the village to its fate.")

else:
    print("You walk away, sighing happily as the knight is taken down by one of the villagers.")

threeSpaces()

print("Oh? what is this? You found an old piece of paper! It has some faded writing on it!")
readorNot = input("If you want to read the sheet, press R. If you throw it away, press T.")

rucksack=["Bread","Iron Sword","Various Clothing"]

if( readorNot == 'r'):
    print(" It says:")
    threeSpaces()
    print("...Karr...Mountains....North.....Blade...")
    print("Hmm.You put this in the rucksack the grateful villager gave you. It has", rucksack, "in it." )
    rucksack.append("map")
elif( readorNot == 'R'):
    print(" It says:")
    threeSpaces()
    print("...Karr...Mountains....North.....Blade...")
    print("Hmm.You put this in the rucksack the grateful villager gave you. It has", rucksack, "in it." )
    rucksack.append("map")
elif (readorNot == "t"):
    print("Hmm. You decide to put it in your new rucksack anyway.")
    rucksack.append("map")
elif (readorNot == "T"):
    print("Hmm. You decide to put it in your new rucksack anyway.")
    rucksack.append("map")

print("You leave the village, to explore. You see a woods to the east, and a winding field to the further north.")
wood = random.randint(10, 50)
firstgoChoice = input("/n You then decide to get wood to build a nice house in the meadow, and stay the night in one of the villager's house. PRESS W")
print(" Phew! After a solid day's work, you collected", wood, "wood!")
print("You dig a hole, bury the wood in the pit, and stay the night in the cabin.")
startvillage()
print("You are in a deep slumber...")

for (i) in range (10):
    time.sleep(1)
    print('Sleeping...')






print("For ten days you work tirelessly with the locals, building your house and a barrier around the village, which is called Karr, after the mountain.")
def playerHouse():
    print("                _   _   _        ")
    print("               | |_| |_| |       ")
    print("               |         |       ")
    print("               |    |    |       ")
    print("     /---------|         |-----\ ")
    print("    /    _      _________|      \ ")
    print("   /    | |                     |")
    print("  |      -                      |")
    print("  |                     ||      | ")
    print("  |   ___                       |")
    print("  |  |   |                      |")
    print("  |  |   |                      |")
    print("  ]  |  o|                      |")
    print("  |__|___|______________________|")

print("Now you have somewhere to stay. you place a chest in your house, along with a lot of things that is essencial for household uses, and a blacksmith, a gem forge, and a potions master if they ever arrive.")
threeSpaces()
print("[BUILDER]: AIN'T THIS A FINE THANG, SIR? I'M SURE YOU'LL AGREE, SIR! IN FACT, I'LL GIVE MY EXPOR TO YOU!")
rucksack.append("Expor")
print("The Expor lets you have an XP bar! Woohoo! Every 3 XP = 1 Level! Unfortunately, you'll need to activate it in future adventures.")
print("[BUILDER]: POP TOLD ME THAT IT NEEDS TO BE ACTIVATED AT THE FOUNTAIN OF KE'LL! OH YEA, HERES A MAP!")
rucksack.append("Town Map")
print("being bored after all the action, you decide to explore. One thing crosses your mind.  \n  After the attack, you need some defences. And where do you find weapons? The Smith of course! ")

walktime = random.randint(5, 20)

for (i) in range (walktime):
    time.sleep(1)
    print('You are walking to the smith...')

print('After you get there, you see a fresh sword on the anvil, along with a wooden staff, which has a red orb on the top.')
print('Now, do you pick up the sword, or the staff, as the smith (called Myles) revealed to you it was. If you choose wand, then press W. Otherwise, if you prefer the sword, press S.')
weaponChoice = input("Weapon of Choice? >>").lower

if (weaponChoice == 'w'):
    weaponChoice = 'Magyc Staff'
elif (weaponChoice == 's'):
    weaponChoice = 'Runic Sword'






print('[MYLES]: GOOD CHOICE! BUT YOU BETTER TAKE THE OTHER ONE AS WELL.')
print('you take the other weapon. You now have both weapons. Now for some cool clothes.')
print('If you wish to have a magical robe, which boosts magic and XP points, press R followed by ENTER.')
print('If you want a nice, strong armour which greatly boosts HP, and slows you down (does not affect gameplay), press K, followed, as usual, by ENTER.')
clothesKindChoice = input('Shopping for what? Strength or Stealth? >>').lower

def ShoppingForClothes ():
    if (clothesKindChoice == 'r'):
        print('You got a nice flowing silk robe, with complex runes that move about as if they were alive.')
    elif(clothesKindChoice == 'k'):
        print('Boom! After a few nights sleep, you finally get the armour. You hang it up by the wall, and you stare gleefully at it.')
    else:
        ShoppingForClothes()
ShoppingForClothes()
print('Whoo! Now, after a massive order of Kyahaiyas (pyjamas) and Kondobanyas (Normal clothes like coats and shirts) and parting with a lot of cash, your clothing is finally fixed.')
print('Before bed, you look at your nice new clothes. You put on your Kyahiayas, and the velvety clothes puts you to sleeeeep.')

print('Its a wonderful new day... What are you going to do? If you want to explore the forest to the east, press F. If you want to take a meal rest, press Y.')
exChoice1 = input(">>").lower()
def exChoiceLoop1():
    if (exChoice1 == 'f'):
        print("You take your stuff, and walk over to the forest. Your tummy rumbles, so you take food from your bag,")
    elif (exChoice1 == 'y'):
        print('You settle down at an inn, a crowdy place. You order some hot lamb soup. It norishes you, leaving a very happy costumer.')
        HP = HP + 2
        print('You have', HP,'HP after that soup!' )
        print('You head off towards the forest.')

    else:
        print("[RuneMaster]:Play the game properly. Sigh.")
        exChoiceLoop1()
exChoiceLoop1()

print('You see a sign. It says:')
print("BEWARE MONS...R.. TSA'GA FORES...")
print('You wanna go into the forest? Y/N').lower()
forest1 = int(input('>>'))
def enterForestLoop():
    if (forest1 == 'y'):
        print('You went in cautiously, but you are blocked by thick trunks.')
    elif (forest1 == 'n'):
        print('You decide to get psyched up, and go another time.')
    else:
        enterForestLoop()
enterForestLoop()




threeSpaces()
threeSpaces()

Very Long I know. I am not a PRO yet. I am only 10.

--Seanliu
Last edited by stranac on Sun Mar 30, 2014 4:57 pm, edited 1 time in total.
Reason: Added code tags. Locked.
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby stranac » Sun Mar 30, 2014 5:04 pm

Please read this to learn how to post code.

That line should be:
Code: Select all
goNorthValley = raw_input('>>')

input() will try to interpret anything you enter as python code. raw_input() gets a string from user.

Also, there is quite a bit of suspiciously indented code.
Specifically, a lot of your functions seem to do nothing, but declare a few variables as globals.
Make sure you indent everything properly, indentation is important in python.

Nice to see someone of your age getting into programming.
Last edited by stranac on Sun Mar 30, 2014 9:40 pm, edited 1 time in total.
Reason: Felt like we were hijacking the thread, split the rest to General Discussions
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Text Based Game - Please Review!

Postby Kebap » Mon Mar 31, 2014 2:39 pm

stranac wrote:Nice to see someone of your age getting into programming.

Agreed, reminds me of myself. Only I did not have online forums at the time to ask for help. So great to see you, Seanliu! :mrgreen:

Here are some random thoughts:

Code: Select all
#This lets me skip three spaces! Convenient!#
def threeSpaces ():
    print("")
    print("")
    print("")

consider print("\n" * 3)
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: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Text Based Game - Please Review!

Postby Seanliu » Sat Apr 05, 2014 8:25 pm

stranac wrote:Please read this to learn how to post code.

That line should be:
Code: Select all
goNorthValley = raw_input('>>')

input() will try to interpret anything you enter as python code. raw_input() gets a string from user.

Also, there is quite a bit of suspiciously indented code.
Specifically, a lot of your functions seem to do nothing, but declare a few variables as globals.
Make sure you indent everything properly, indentation is important in python.

Nice to see someone of your age getting into programming.



Eeh... When I try raw_input, my IDE (PyCharm) gives an error. I am using Python 3.3.5
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby stranac » Sat Apr 05, 2014 10:38 pm

Seanliu wrote:Eeh... When I try raw_input, my IDE (PyCharm) gives an error. I am using Python 3.3.5

In that case what you had should have worked, unless something else was going on.
That's why it's always important to show the full error traceback.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Text Based Game - Please Review!

Postby Seanliu » Sun Apr 06, 2014 3:06 pm

Oh well. Never mind about the raw_input. There is virtually no diffrence, plus, input is easier to type. Any suggestions to my game, or how my game can be shortened?
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby Mekire » Sun Apr 06, 2014 3:57 pm

You next goal should be to get rid of any and all global variables.
If you are not ready to look into classes then try passing around a dictionary of game state information from function to function.
The only things in your global scope should pretty much be functions, classes, and GLOBAL_CONSTANTS.

Also some basic structural issues.
This is the structure of essentially any game you have ever played:

Code: Select all
while playing:
    process_user_input()
    update_game_state()
    display_updated_interface_to_user()

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Text Based Game - Please Review!

Postby Seanliu » Sun Apr 06, 2014 9:49 pm

Eeh... I dont know how to do classes (it is all very high-end to me!), and that would mean trudging and deleting a lot of old code, so I need some pointers on how to use these global_constant and class thingies.

THX for the help!
Last edited by Mekire on Sun Apr 06, 2014 11:47 pm, edited 1 time in total.
Reason: Quote removed.
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby Kebap » Mon Apr 07, 2014 3:57 pm

try with this structure maybe first:

1) define all your functions
2) define a function main() which starts and handles all the other functions (and maybe their returned values)
3) start main()

your current code is more like this:

* some code
* a function definition
* more code
* another function
* a function
* some code
* more code, maybe calling a function
* another function definition
* ...

try and do not have any code outside the functions, unless you have a very good reason for that case
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: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Text Based Game - Please Review!

Postby Seanliu » Mon Apr 07, 2014 4:36 pm

OK. But main() might be hard soooo Im not sure how. do I pack all my def()s first, and then do main() then pack all my other code in, and call the stuff from the above def()s? So would it look something like this?

Code: Select all
def whatever():
    print("Whatever")
def main():
    print('This is gunna print the words - Whatever.")
    whatever()
   


Like that?
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby Kebap » Mon Apr 07, 2014 6:10 pm

Yep, seems fine to me. And yep, might be hard. ;)
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: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Text Based Game - Please Review!

Postby Seanliu » Fri Apr 18, 2014 10:45 pm

OK! I have done it funally! But there are (a lot) of potentially buggy code that I have to sort out

:(

I will get started, and post the code as soon as i can!
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Based Game - Please Review!

Postby Seanliu » Fri Apr 18, 2014 10:50 pm

OK. But i have a load of unecessacary if loops

Code: Select all
def spam():
    if spam == 'n':
        print('spam is n!')
    else:
        spam()


but how to make it IN the main() without the defs and ifs?
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm


Return to Game Development

Who is online

Users browsing this forum: Bing [Bot] and 4 guests