My Personal Game

Got something to share about your favorite games? Strategies? Game codes? Discuss gaming topics here!

My Personal Game

Post by centip3de on Sun Dec 26, 2010 12:41 am
([msg=51151]see My Personal Game[/msg])

So I wrote a very basic RPG, I plan to update it but I kinda just wanna release it (It's no fun to write 724 lines of code if nobody enjoys it). Now it's extremely hard to read because essentially everything is a definition (So I can call them whenever needed) and it's written in Python. So anyway it's 4 in the morning here (and I've been coding for 8 hours straight hence the terrible grammer/ spelling/ general flow of this entire thing) Anyways here it is:
Code: Select all
import random, time, sys, os

global player_health
global gold
global monster_health
global player_damage
global player_armor
global player_items
player_items = ""
player_armor = ""
player_damage = ""
player_health = 100
monster_health = 100
gold = 0



def cls():
    print('\n')

def monster_attack():
    global player_health
    global player_armor
    print "The Ogre is attacking..."
    time.sleep(3)
    if player_armor == "Plate Armor":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 89))
            k = terms[0]
        print "Ogre attacks you for " + str(k) + " damage."
        player_health = player_health - k
        PlayerAlive()
    if player_armor == "Chain Armor":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 92))
            l = terms[0]
        print "Ogre attacks you for " + str(l) + " damage."
        player_health = player_health - l
        PlayerAlive()
    if player_armor == "Wood Armor":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 96))
            m = terms[0]
        print "Ogre attacks you for " + str(m) + " damage."
        player_health = player_health - m
        PlayerAlive()
    if player_armor  == "Sweater Armor":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 98))
            n = terms[0]
        print "Ogre attacks you for " + str(n) + " damage."
        player_health = player_health - n
        PlayerAlive()
    if player_armor == "":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 99))
            o = terms[0]
        print "Ogre attacks you for " + str(o) + " damage."
        player_health = player_health - o
        PlayerAlive()
           
    terms = []
    for i in range(2):
        terms.append(random.randint(1, 99))
        j = terms[0]
    print "Ogre attacks you for " + str(j) + " damage."
    player_health = player_health-j
    print "You have " + str(player_health) + " health left"
    PlayerAlive()
   

def player_attack():
    global monster_health
    global player_damage
    print "You are attacking..."
    time.sleep(3)
    if player_damage == "Sword":
        terms = []
        for i in range(2):
            terms.append(random.randint(12, 111))
            k = terms[0]
        print "You attack for " + str(k) + " damage."
        monster_health = monster_health - k
        MonsterAlive()
        MidFight()
                   
    if player_damage == "Battle Axe":
        terms = []
        for i in range(2):
            terms.append(random.randint(5, 104))
            l = terms[0]
        print "You attack for " + str(l) + " damage."
        monster_health = monster_health - l
        MonsterAlive()
        MidFight()
    if player_damage == "Club":
        terms = []
        for i in range(2):
            terms.append(random.randint(3, 102))
            m = terms[0]
        print "You attack for " + str(m) + " damage."
        monster_health = monster_health - m
        MonsterAlive()
    if player_damage == "Stick":
        terms = []
        for i in range(2):
            terms.append(random.randint(2, 100))
            n = terms[0]
        print "You attack for " + str(n) + " damage."
        monster_health = monster_health - n
        MonsterAlive()
       
    if player_damage == "":
        terms = []
        for i in range(2):
            terms.append(random.randint(1, 99))
            j = terms[0]
        print "You attack for " + str(j) + " damage."
        monster_health = monster_health -j
        MonsterAlive()
       
   

def Beggenning():
    print "Welcome to your simple rpg!"
    time.sleep(5)
    cls()
    pn = raw_input("Let's start with the basics, what's your name? ")
    cls()
    print "Welcome " + pn + " we hope you enjoy your adventures here!"
    time.sleep(3)
    cls()
    Main()
   
def Main():
    global player_health
    global monster_health
    player_health = 100
    monster_health = 100
    cls()
    print "What would you like to do?"
    print "1: Fight"
    print "2: Look for burried treasure"
    print "3: Store"
    print "4: Inventory"
    print "5: Help"
    print "6: Quit"
    main_choice = raw_input("")
    if main_choice == "1":
        FightChoice()
    if main_choice == "attack":
        FightChoice()
    if main_choice == "Attack":
        FightChoice()
    if main_choice == "2":
        TreasureFind()
    if main_choice == "Look for burried treasure":
        TreasureFind()
    if main_choice == "look for burried treasure":
        TreasureFind()
    if main_choice == "3":
        StoreMain()
    if main_choice == "Store":
        StoreMain()
    if main_choice == "store":
        StoreMain()
    if main_choice ==  "4":
        print "You currently have " + str(player_armor) + " equipped"
        print "You also have a " + str(player_damage) + " equipped"
        print "You have " + str(player_items) + " equipped"
        print "And you have " + str(gold) + " gold"
        Main()
    if main_choice == "Inventory":
        print "You currently have " + str(player_armor) + " equipped"
        print "You also have a " + str(player_damage) + " equipped"
        print "You have " + str(player_items) + " equipped"
        print "And you have " + str(gold) + " gold"
        Main()
    if main_choice == "inventory":
        print "You currently have " + str(player_armor) + " equipped"
        print "You also have a " + str(player_damage) + " equipped"
        print "You have " + str(player_items) + " equipped"
        print "And you have " + str(gold) + " gold"
        Main()
    if main_choice == "Help":
        Help()
    if main_choice == "5":
        Help()
    if main_choice == "help":
        Help()
    if main_choice == "6":
        sys.exit
    if main_choice == "quit":
        sys.exit
    if main_choice == "Quit":
        sys.exit

def StoreMain():
    print "Welcome to the store!"
    print "Here you can get things like potions, weapons, or armor!"
    print "What would you like to do?"
    print "1: Browse Selection"
    print "2: Leave"
    store_choice = raw_input("")
    if store_choice == "1":
        StoreBrowse()
    if store_choice == "Browse Selection":
        StoreBrowse()
    if store_choice == "browse selection":
        StoreBrowse()

    if store_choice == "2":
        Main()
    if store_choice == "Leave":
        Main()
    if store_choice == "leave":
        Main()
def StoreBrowse():
        print "Here is the our store! Feel free to browse our selection!"
        print "1: Weapons"
        print "2: Armor"
        print "3: Potions"
        print "4: Leave"
        browse_choice = raw_input("")
        if browse_choice == "1":
            StoreWeapons()
        if browse_choice == "weapons":
            StoreWeapons()
        if browse_choice == "Weapons":
            StoreWeapons()

        if browse_choice == "2":
            ArmorBrowse()
        if browse_choice == "Armor":
            ArmorBrowse()
        if browse_choice == "armor":
            ArmorBrowse()

        if browse_choice == "3":
            PotionBrowse()
        if browse_choice == "Potions":
            PotionBrowse()
        if browse_choice == "potions":
            PotionBrowse()

        if browse_choice == "4":
            StoreMain()
        if browse_choice == "Leave":
            StoreMain()
        if browse_choice == "leave":
            StoreMain()

def PotionBrowse():
    print "1: Super Potion (Heals for 100) 200 gold"
    print "2: Potion (Heals for 75) 150 gold"
    print "3: Small Potion (Heals for 50) 100 gold"
    print "4: Minor Potion (Heals for 25) 50 gold"
    print "5: Leave"
    potion_choice = raw_input("")
    if potion_choice == "1":
        SuperPotion()
    if potion_choice == "Super Potion":
        SuperPotion()
    if potion_choice == "super potion":
        SuperPotion()

    if potion_choice == "2":
        Potion()
    if potion_choice == "Potion":
        Potion()
    if potion_choice == "potion":
        Potion()

    if potion_choice == "3":
        SmallPotion()
    if potion_choice == "Small Potion":
        SmallPotion()
    if potion_choice == "small potion":
        SmallPotion()

    if potion_choice ==  "4":
        MinorPotion()
    if potion_choice == "Minor Potion":
        MinorPotion()
    if potion_choice == "mionr potion":
        MinorPotion()

    if potion_choice == "5":
        StoreBrowse()
    if potion_choice == "leave":
        StoreBrowse()
    if potion_choice == "Leave":
        StoreBrowse()

def SuperPotion():
    global player_items
    global gold
    global player_health
    gold = gold - 200
    if gold > 0:
        print "Congratz on the new Super Potion!"
        print "You have " + str(gold) + " gold left"
        player_items = "Super Potion"
        time.sleep(2)
        PotionBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        PotionBrowse()
       
def Potion():
    global gold
    global player_health
    global player_items
    gold = gold - 150
    if gold > 0:
        print "Congratz on the new Potion!"
        print "You have " + str(gold) + " gold left"
        player_items = "Potion"
        time.sleep(2)
        PotionBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        PotionBrowse()
       
def SmallPotion():
    global player_items
    global gold
    global player_health
    gold = gold - 100
    if gold > 0:
        print "Congratz on the new Small Potion!"
        print "You have " + str(gold) +  " gold left"
        player_items = "Small Potion"
        time.sleep(2)
        PotionBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        PotionBrowse()
       
def MinorPotion():
    global gold
    global player_health
    global player_items
    gold = gold - 50
    if gold > 0:
        print "Congratz on the new Minor Potion!"
        print "You have " + str(gold) + " gold left"
        player_items = "Minor Potion"
        time.sleep(2)
        PotonBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        PotionBrowse()

def UseItems():
    global player_health
    global player_items
    if player_items == "Super Potion":
        player_health = player_health + 100
        player_items = ""
        print "You now have " + str(player_health) + " health."
        MidFight()
           
    if player_items == "Potion":
        player_health = player_health + 75
        player_items = ""
        print "You now have " + str(player_health) + " health."
        MidFight()
    if player_items == "Small Potion":
        player_health = player_health + 50
        player_items = ""
        print "You now have " + str(player_health) + " health."
        MidFight()
    if player_items == "Minor Potion":
        player_health = player_health
        player_items = ""
        print "You now have " + str(player_health) + " health."
        MidFight()

def UseItemsSelection():
    global player_health
    global player_items
    print "You currently have " + player_items + "."
    print "1: Use"
    print "2: Leave"
    use_items = raw_input("")
    if use_items == "1":
        UseItems()
    if use_items == "Use":
        UseItems()
    if use_items == "use":
        UseItems()

    if use_items == "2":
        MidFight()
    if use_items == "Leave":
        Midfight()
    if use_items == "leave":
        MidFight
   
           
   
       


def ArmorBrowse():
    print "1: Plate Armor (+10 armor) 450 gold"
    print "2: Chain Armor (+7 armor) 300 gold"
    print "3: Wood Armor (+3 armor) 150 gold"
    print "4: An extra sweater (+1 armor) 50 gold"
    print "5: Leave"
    armor_choice = raw_input("")
    if armor_choice == "1":
        ArmorPlate()
    if armor_choice == "Plate Armor":
        ArmorPlate()
    if armor_choice == "plate armor":
        ArmorPlate()

    if armor_choice == "2":
        ArmorChain()
    if armor_choice == "Chain Armor":
        ArmorChain()
    if armor_choice == "chain armor":
        ArmorChain()

    if armor_choice == "3":
        ArmorWood()
    if armor_choice == "Wood Armor":
        ArmorWood()
    if armor_choice == "wood armor":
        ArmorWood()

    if armor_choice == "4":
        ArmorSweater()
    if armor_choice == "An Extra Sweater":
        ArmorSweater()
    if armor_choice == "an extra sweater":
        ArmorSweater()

    if armor_choice == "5":
        StoreBrowse()
    if armor_choice == "Leave":
        StoreBrowse()
    if armor_choice == "leave":
        StoreBrowse()

def ArmorPlate():
    global gold
    global player_armor
    gold = gold - 450
    if gold > 0:
        print "Congratz on the new Plate Armor!"
        player_armor = "Plate Armor"
        print "You have " + str(gold) + " gold left."
        time.sleep(2)
        ArmorBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        ArmorBrowse()
       
def ArmorChain():
    global gold
    global player_armor
    gold = gold - 300
    if gold > 0:
        print "Congratz on the new Chain Armor!"
        player_armor = "Chain Armor"
        print "You have " + str(gold) + " gold left."
        time.sleep(2)
        ArmorBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        ArmorBrowse()
       
def ArmorWood():
    global gold
    global player_armor
    gold = gold - 150
    if gold > 0:
        print "Contratz on the new Wood Armor!"
        player_armor = "Wood Armor"
        print "You have " + str(gold) + " gold left."
        time.sleep(2)
        ArmorBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        ArmorBrowse()

def ArmorSweater():
    global gold
    global player_armor
    gold = gold - 50
    if gold > 0:
        print "Congratz on the new Sweater!"
        player_armor = "Sweater armor"
        print "You have " + str(gold) + " gold left."
        time.sleep(2)
        ArmorBrowse()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        ArmorBrowse
   
   

def WeaponSword():
    global gold
    global player_damage
    gold = gold - 550
    if gold > 0:
        print "Congratz on your new Sword!"
        player_damage = "Sword"
        print "You have " + str(gold) + " gold left!"
        time.sleep(2)
        StoreWeapons()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        StoreWeapons()
       
def WeaponBattleaxe():
    global gold
    global player_damage
    gold = gold - 300
    if gold > 0:
        print "Congratz on the new Battle Axe!"
        player_damage = "Battle Axe"
        print "You have " + str(gold) + " gold left!"
        time.sleep(2)
        StoreWeapons()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        StoreWeapons()
       
def WeaponClub():
    global gold
    global player_damage
    gold = gold - 150
    if gold > 0:
        print "Congratz on the new Club!"
        player_damage = "Club"
        print "You have " + str(gold) + " gold left!"
        time.sleep(2)
        StoreWeapons()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        StoreWeapons()

def WeaponStick():
    global gold
    global player_damage
    gold = gold - 50
    if gold > 0:
        print "Congratz on the new Stick!"
        player_damage = "Stick"
        print "You have " + str(gold) + " gold left!"
        time.sleep(2)
        StoreWeapons()
    else:
        print "You don't have enough money!"
        time.sleep(3)
        StoreWeapons()
   

def StoreWeapons():
    global gold
    print "1: Sword (+12 damage) 550 gold"
    print "2: Battle Axe (+5 damage) 300 gold"
    print "3: Club (+3 damage) 150 gold"
    print "4: Stick (+1 damage) 50 gold"
    print "5: Leave"
    weapon_choice = raw_input("")
    if weapon_choice == "1":
        WeaponSword()
    if weapon_choice == "sword":
        WeaponSword()
    if weapon_choice == "Sword":
        WeaponSword()
       
    if weapon_choice == "2":
        WeaponBattleaxe()
    if weapon_choice == "Battle Axe":
        WeaponBattleaxe()
    if weapon_choice == "battle axe":
        WeaponBattleaxe()       
       
    if weapon_choice == "3":
        WeaponClub()
    if weapon_choice == "club":
        WeaponClub()
    if weapon_choice == "Club":
        WeaponClub()
       
    if weapon_choice == "4":
       WeaponStick()
    if weapon_choice == "stick":
        WeaponStick()
    if weapon_choice == "Stick":
        WeaponStick()

    if weapon_choice == "5":
        StoreBrowse()
    if weapon_choice == "leave":
        StoreBrowse()
    if weapon_choice == "Leave":
        StoreBrowse()

   
def Help():
    print "Welcome to your simple RPG! It's really kinda sad if YOU of all people have to go to the help section... I mean, this"
    print "thing is your own creationg.... and besides it's uber self explanitory anyway.. Just for that, this is not happening"
    print "You arn't getting crap."
    time.sleep(10)
    Main()

def PlayerAlive():
    global player_health
    if player_health <=0:
       print "Sorry, You've died. GAME OVER"
       time.sleep(4)
       Beggenning()
    else:
       print "You have " + str(player_health) + " health left"
       MidFight()
       
   
       
def MonsterAlive():
    global monster_health
    global gold
    if monster_health <=0:
        print"Congratz! You've killed an Ogre!! You get 10 gold for your valient efforts!"
        gold = gold + 10
        time.sleep(2)
        Main()
    else:
        print "Ogre had " + str(monster_health) + " health left!"
        monster_attack()
       

def Fight():
    global player_health
    global monster_health
    if player_health >0:
        player_attack()
        monster_attack()
        MidFight()
def MidFight():
    global player_health
    global monster_health
    cls()
    print "What would you like to do?"
    print "1: Attack"
    print "2: Use Items"
    print "3: Run"
    fight_choice = raw_input("")
    if fight_choice == "1":
        Fight()
    if fight_choice == "attack":
        Fight()
    if fight_choice == "Attack":
        Fight()

    if fight_choice == "2":
        UseItemsSelection()
    if fight_choice == "use items":
        UseItemsSelection()
    if fight_choice == "Use Items":
        USeItemsSelection()

    if fight_choice == "3":
        Run()
    if fight_choice == "run":
        Run()
    if fight_choice == "Run":
        Run()
   
   
def Run():
    terms = []
    for i in range(2):
        terms.append(random.randint(1, 99))
        j = terms[0]
        if j >= 50:
            print "You've run successfully!"
            Main()
        else:
            print "Running failed!"
            FightChoice()
   
def FightChoice():
    global player_health
    global monster_health
    print "You've found an Ogre!"
    print "What would you like to do?"
    print "1: Attack"
    print "2: Use Items"
    print "3: Run"
    fight_choice = raw_input("")
    if fight_choice == "1":
        Fight()
    if fight_choice == "attack":
        Fight()
    if fight_choice == "Attack":
        Fight()

    if fight_choice == "2":
        UseItemsSelection()
    if fight_choice == "use items":
        UseItemsSelection()
    if fight_choice == "Use Items":
        UseItemsSelection

    if fight_choice == "3":
        Run()
    if fight_choice == "run":
        Run()
    if fight_choice == "Run":
        Run()
       
       


def TreasureFind():
     global gold
     terms =  []
     for i in range(2):
         terms.append(random.randint(1, 99))
     j = terms[0]
     if j >= 50:
         terms = []
         for i in range(2):
             terms.append(random.randint(1, 99))
         k = terms[0]
         print "You have found the treasure!"
         print "You have earned " + str(k) + " gold!"
         gold = gold + k
         Main()
     else:
         print "Sorry no treasure this time..."
         Main()

Beggenning()
     



Atm it include fighting, treasure finding, shopping. I give you all permission to do whatever you want with this, as long as you tell me how I can inprove it in any form (Or just post your on version of it :D) Please note that this is EXTREMELY HARD TO READ LIKE YOU'LL NEVER READ ANYTHING MORE DIFFICULT >.< So I suggest running it first, and then giving it a shot. Anywho have fun :)
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1430
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: My Personal Game

Post by Assassian360 on Sun Dec 26, 2010 7:44 am
([msg=51155]see Re: My Personal Game[/msg])

Glanced through your code and it looks ok, but might I suggest you try to make a few potential changes.
Before I start, I should mention that I haven't really done much Python programming at all. So I'm not sure how easy certain things are to do in Python specifically.


1) For your menu options, you repeat basically the same code 3 times. Instead of breaking it apart into 3 separate bits you may as well write it on one line like:

if main_choice == 1 or main_choice == "something" or main_choice == "Something":
Something()

2) You may want to consider working on a more template approach to combat, and items. You could perhaps consider putting items and their data into arrays and then using that information to have the buying etc. The same approach could be used for monsters too. At the moment your code only handles specifically a single monster, and to add more monsters you'll need massive code duplication.

Making your code use more of its information from essentially databases may make your code a lot messier. So you may also want to consider commenting parts you think could be hard to follow when rereading.

There are other things I could say. But good work for taking the time to write some code. Hope you have fun improving it further.
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: My Personal Game

Post by insomaniacal on Sun Dec 26, 2010 8:20 am
([msg=51156]see Re: My Personal Game[/msg])

It reminded me of those primarily text based online RPG games without any of the corny graphics. However, there's a problem in your program flow. Somewhere, anyway.

Code: Select all
You've run successfully!


What would you like to do?
1: Fight
2: Look for burried treasure
3: Store
4: Inventory
5: Help
6: Quit
6
Running failed!
You've found an Ogre!
What would you like to do?
1: Attack
2: Use Items
3: Run

As you can see, I've run away from the ogre successfully in the first line, then try to quit the game. However, this has the same effect as just pressing attack again. I looked at the code really quickly, and couldn't find what exactly went wrong. My guess is that some variable retained it's value when it's not supposed to. Try making sure you clear your variables as soon as they are no longer needed.

Also, instead of defining items via tons of if statements, you should look into dictionaries. You can have one dictionary with all the weapons, and for their definition, you can have a string of numbers like 44,10,5. 44 can represent attack value, 10, the speed of the weapon, and 5, the value of the weapon. It'll make your code cleaner, and easier to read. Not to mention, you could store all the information in a separate file, and read from it into your dictionary.

You also shouldn't try to predict what people will type, for the menu options for example. Instead of having something like:
Code: Select all
if a == 1:
  fight()
if a == "fight":
  fight()
if a == "Fight":
fight()


Just redirect them to the start of the menu if they dont input a correct value. Theres several ways to do this, but this is some psuedo-code to get the idea across.
Code: Select all
def menu():
if a = 1:
stuff()
...
...
...
if a = 6:
stuff6()

else:
print "You idiot, you can't manage to restrain your l33t 7yp!n6 5k!llz?"
menu()


(It's generally not a good idea to be an asshole in error-messages, but hey, it's a game, it's for fun, have some fun coding it :D )

Also, the general way of writing python scripts with tons of functions is to use classes and multiple files, such as described here:
Writing multiple files of source code for fun and profit.

We've all written messy code, so don't worry about not being 100% organized, but if your project grows larger and larger, it'll become easier if you can say all your battle related functions are in one script, all your store functions in another, program flow,etc. With one script, it can become a bit of a pain.

Anyway, good luck, and have fun coding!
It's not who votes that counts, it's who counts the votes
insomaniacal.blog.com
User avatar
insomaniacal
Addict
Addict
 
Posts: 1210
Joined: Sun May 24, 2009 10:21 am
Blog: View Blog (0)


Re: My Personal Game

Post by mojo1948 on Sun Dec 26, 2010 9:02 am
([msg=51158]see Re: My Personal Game[/msg])

Putting you menu in a while loop will help your program flow and take care of improper input.
Code: Select all
print "1. Attack\n","2. Run\n","3. Quit"
print "Any other key for bad choice"
while True:
   user = raw_input("Make Your Choice: ")
   if user == "1":
      print "Attack"
   elif user == "2":
      print "Run"      
   elif user == "3":
      print "Quit"
      break
   else:
      print "Bad Choice\n","Ogre Attacks!"


Coding games like this can be a fun way to learn, just keep at it and enjoy.
Never stop learning.
User avatar
mojo1948
Experienced User
Experienced User
 
Posts: 60
Joined: Sun Jul 18, 2010 5:45 am
Blog: View Blog (0)


Re: My Personal Game

Post by centip3de on Sun Dec 26, 2010 12:48 pm
([msg=51169]see Re: My Personal Game[/msg])

Thanks all! Really good tips! =D I'll make sure to add those in!! My next project is levels :P Anywho, this game was more of a way to get me better at coding in python then actually producing an actual game (Which it seems to be turning into xD) . Oh and I would store them in different files, but I'm not the best at reading files and implementing their contents into a code.... But I think that link might fix that problem... Anywho getting off topic here, thanks all! And Merry Christmas :)
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1430
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: My Personal Game

Post by insomaniacal on Sun Dec 26, 2010 2:38 pm
([msg=51173]see Re: My Personal Game[/msg])

Reading an unencrypted file is pretty easy in python.

Code: Select all
a=open("./yourfile")
a = a.read()


You can then manipulate the variable "a" however you want. Since you'd be the one creating it, you write it in such a way so that it will be easy to load the data into your game. You could do a similar thing with having people save their progress.
It's not who votes that counts, it's who counts the votes
insomaniacal.blog.com
User avatar
insomaniacal
Addict
Addict
 
Posts: 1210
Joined: Sun May 24, 2009 10:21 am
Blog: View Blog (0)


Re: My Personal Game

Post by fashizzlepop on Sun Dec 26, 2010 4:31 pm
([msg=51179]see Re: My Personal Game[/msg])

I don't know about Python but in Perl there is the ability to make subroutine (function) references. Using these you can make your code reusable. It's amazing how much references can shorten and clean code. Especially hashes that hold array references or further hashes. These can all be built dynamically at the start of the program from input files suggested above. Check to see if python has the same functionality.

Also, regexs can be used for user input to make it easier to accept many possibilities.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: My Personal Game

Post by fabianhjr on Sun Dec 26, 2010 11:49 pm
([msg=51196]see Re: My Personal Game[/msg])

Will have a look at it tomorrow. I am half-sleep atm. >_>

-- Tue Dec 28, 2010 9:32 am --

Hey just a quick tip for your trick.
str() has a function that returns all strings in lowers so:
Code: Select all
main_choice = str(raw_input("What to do: ")).lower()
if main_choice == "1" or main_choice == "attack":
    FightChoice()

and you will shorten your code a lot!

-- Tue Dec 28, 2010 10:08 am --

Well, you still have to work on the game dynamics. By instace I can get unlimited gold just by searching for it and get any item in less than 10 seconds. The code is really repetitive and all is hardcoded. If you plan to expand it you must write a lot. Example, please add a new weapon: the nuke. It is good for a first game though. :P
Donate bitcoins to me! [1DhRP3hHgmSLQdRTZyT8VPTmzAj7Z2rsGA]
Dunno what bitcoins are? BitcoinMe
fabianhjr
Poster
Poster
 
Posts: 286
Joined: Tue Sep 21, 2010 7:48 pm
Blog: View Blog (0)



Return to Gaming

Who is online

Users browsing this forum: No registered users and 0 guests