Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Text-based game
- # Mihail Feraru@littlwho
- # Old code found in a backup... Nostalgia :((((
- import os, random, time, sys
- def menu():# game menu
- print ' Gladiators\' arena\n 1.8v'
- print '\n'
- print '1.New game'
- print '2.Load Game'
- print '3.Quit\n'
- def slow(text):# intro text (work)
- for c in text:
- sys.stdout.write(c)
- sys.stdout.flush()
- time.sleep(0.015)
- #start game
- def game():
- while True:
- menu()
- c = raw_input('\nEnter the number of your choice:')
- os.system('cls')
- if c == '1':
- new_game()
- elif c == '2':
- try:
- load_game()
- if exit_ == True:
- sys.exit(0)
- except:
- print 'No saved games...'
- os.system('pause')
- os.system('cls')
- elif c == '3':
- sys.exit(0)
- else:
- print 'I don\'t understand you!'
- os.system('cls')
- # new game option!!! (work)
- def new_game():
- #variables
- gold = 0
- rounds = 1
- life = 50
- inventory = {
- "weapon" : 5,
- "armor" : 0
- }
- #the game
- intro = 'Hello, Hero! You was caught by Romans and you must fight in Arena for their fun.\nIf you will win the tournament with 12 rounds , you will be free!\nGood Luck!!!'
- slow(intro)
- print '\n'
- while True:
- print 'Gold:'+str(gold),
- print ' Round:'+str(rounds)
- print '1.Let\'s Fight!'
- print '2.Shop'
- print '3.Profile'
- print '4.Save game'
- print '5.Exit\n'
- c = raw_input('What is your command? ')
- os.system('cls')
- if c == '1':
- fight(inventory['weapon'],inventory['armor'],life,rounds)
- if end == True:
- sys.exit(0)
- if r == 'win':
- gold += 500
- rounds += 1
- life += 50
- elif r == 'add':
- gold += add
- elif r == 'lose':
- inventory['weapon'] = 5
- inventory['armor'] = 0
- if troll_K == True:
- inventory['weapon'] += 10
- inventory['armor'] += 10
- os.system('cls')
- elif c == '2':
- if shop(gold):
- gold -= spend
- inventory[item] += imbue
- os.system('cls')
- elif c == '3':
- print 'Gold:%d\nLife:%d\nWeapon:%d\nArmor:%d\nRound:%d\n' % (gold, life, inventory['weapon'], inventory['armor'], rounds)
- os.system('pause')
- os.system('cls')
- elif c == '4':
- f = open('save.py','w')
- data = 'gold='+str(gold)+'\n' + 'rounds='+str(rounds)+'\n' + 'life='+str(life)+'\n' + 'inventory='+str(inventory)
- f.write(data)
- f.close()
- print '\nGame saved...\n'
- os.system('pause')
- os.system('cls')
- elif c == '5':
- sys.exit(0)
- #load game option!!! (work)
- def load_game():
- global exit_
- exit_ = False
- from save import gold, rounds, inventory, life
- while True:
- print 'Gold:'+str(gold),
- print ' Round:'+str(rounds)
- print '1.Let\'s Fight!'
- print '2.Shop'
- print '3.Profile'
- print '4.Save game'
- print '5.Exit\n'
- c = raw_input('What is your command? ')
- os.system('cls')
- if c == '1':
- fight(inventory['weapon'],inventory['armor'],life,rounds)
- if end == True:
- sys.exit(0)
- if r == 'win':
- gold += 500
- rounds += 1
- life += 50
- elif r == 'add':
- gold += add
- elif r == 'lose':
- inventory['weapon'] = 5
- inventory['armor'] = 0
- if troll_K == True:
- inventory['weapon'] += 10
- inventory['armor'] += 10
- os.system('cls')
- elif c == '2':
- if shop(gold):
- gold -= spend
- inventory[item] += imbue
- os.system('cls')
- elif c == '3':
- print 'Gold:%d\nLife:%d\nWeapon:%d\nArmor:%d\nRound:%d\n' % (gold, life, inventory['weapon'], inventory['armor'], rounds)
- os.system('pause')
- os.system('cls')
- elif c == '4':
- f = open('save.py','w')
- data = 'gold='+str(gold)+'\n' + 'rounds='+str(rounds)+'\n' + 'life='+str(life)+'\n' + 'inventory='+str(inventory)
- f.write(data)
- f.close()
- print '\nGame saved...\n'
- os.system('pause')
- os.system('cls')
- elif c == '5':
- exit_ = True
- break
- #fight option!!! (work)
- def fight(weapon,armor,life,rounds):
- global add, r, troll_K, end
- end = False
- troll_K = False
- r = None
- add = 0
- wfe = 0
- afe = 0
- lfe = 0
- print '1.Arena'
- print '2.Forest'
- print '!WARNING if you die in Arena, your weapon and armor will be destroyed!'
- print '3.Back'
- c = raw_input('Cammand: ')
- os.system('cls')
- if rounds == 1:
- we = 6
- ae = 5
- le = 50
- elif rounds == 2:
- we = 10
- ae = 8
- le = 100
- elif rounds == 3:
- we = 14
- ae = 14
- le = 100
- elif rounds == 4:
- we = 17
- ae = 10
- le = 100
- elif rounds == 5:
- we = 25
- ae = 20
- le = 300
- elif rounds == 6:
- we = 40
- ae = 25
- le = 250
- elif rounds == 7:
- we = 40
- ae = 40
- le = 300
- elif rounds == 8:
- we = 60
- ae = 25
- le = 350
- elif rounds == 9:
- we = 80
- ae = 40
- le = 400
- elif rounds == 10:
- we = 100
- ae = 50
- le = 500
- elif rounds == 11:
- we = 100
- ae = 80
- le = 600
- elif rounds == 12:
- we = 200
- ae = 200
- le = 800
- if c == '1':
- while True:
- if le == 0 or le < 0:
- print 'You win!'
- if rounds == 5:
- print 'You killed the one of best gladiators!But you aren\'t free, you must continue fighting!\n Next are rounds comming soon...'
- if rounds == 10:
- print 'You DID it agin!!!You are almost FREE!'
- if rounds == 12:
- print ' You are FREE!!!FREEDOM is so sweet!'
- print '\n\n\n Game produced by\n &Mihai\n\n\n'
- end = True
- os.system('pause')
- os.system('cls')
- r = 'win'
- break
- elif life == 0 or life < 0:
- print 'You lost!'
- os.system('pause')
- os.system('cls')
- r = 'lose'
- break
- print ' You' + ' Enemy'
- print 'Weapon:' + str(weapon) + ' Weapon:' + str(we)
- print 'Armor:' + str(armor) + ' Armor:' + str(ae)
- print 'Life:' + str(life) + ' Life:' + str(le)
- print '1.Attack!'
- print '2.Retreat!'
- c = raw_input('Command? ')
- os.system('cls')
- if c == '1':
- os.system('cls')
- if we - armor > 0:
- life = life - (we - armor)
- if weapon - ae > 0:
- le = le - (weapon - ae)
- if c == '2':
- os.system('cls')
- break
- elif c == '2':
- r = 'add'
- while True:
- if troll_K == True:
- break
- print 'You entered in the dark forest...\n'
- print 'With who you want to fight?\n'
- print '1.Rat (40gold)'
- print '2.Wolf (60gold)'
- print '3.Gigant Bat (100gold)'
- print '4.Tiger (150gold)'
- print '5.Lion (250gold)'
- print '6.Barbar (350gold)'
- print '7.Little Troll (500gold)'
- print '8.Troll Soldier (800gold)'
- print '9.Troll Lord (1500gold)'
- print '10.Troll King! (3000gold)'
- print '11.Back\n'
- att = raw_input('Who you will attack? ')
- os.system('cls')
- if att == '1':
- wfe = 2
- afe = 0
- lfe = 30
- for_add = 40
- elif att == '2':
- wfe = 5
- afe = 1
- lfe = 40
- for_add = 60
- elif att == '3':
- wfe = 7
- afe = 3
- lfe = 50
- for_add = 100
- elif att == '4':
- wfe = 10
- afe = 2
- lfe = 75
- for_add = 150
- elif att == '5':
- wfe = 16
- afe = 5
- lfe = 100
- for_add = 250
- elif att == '6':
- wfe = 13
- afe = 10
- lfe = 120
- for_add = 350
- elif att == '7':
- wfe = 18
- afe = 5
- lfe = 150
- for_add = 500
- elif att == '8':
- wfe = 20
- afe = 20
- lfe = 200
- for_add = 800
- elif att == '9':
- wfe = 50
- afe = 50
- lfe = 250
- for_add = 1500
- elif att == '10':
- wfe = 100
- afe = 100
- lfe = 500
- for_add = 3000
- else:
- break
- while True:
- if lfe == 0 or lfe < 0:
- print 'You win!'
- add += for_add
- print 'Your reward is %d' % (add)
- if att == '10':
- print 'For your help for Roman Empire by killing the Troll King you receive +10 for weapon and armor.'
- troll_K = True
- os.system('pause')
- os.system('cls')
- break
- elif life == 0 or life < 0:
- print 'You lost!'
- os.system('pause')
- os.system('cls')
- c = 0
- break
- print ' You' + ' Enemy'
- print 'Weapon:' + str(weapon) + ' Weapon:' + str(wfe)
- print 'Armor:' + str(armor) + ' Armor:' + str(afe)
- print 'Life:' + str(life) + ' Life:' + str(lfe)
- print '1.Attack!'
- print '2.Retreat!'
- co = raw_input('What is your command?')
- os.system('cls')
- if co == '1':
- if wfe - armor > 0:
- life = life - (wfe - armor)
- if weapon - afe > 0:
- lfe = lfe - (weapon - afe)
- elif co == '2':
- c = 0
- break
- if c == 0:
- break
- elif c == '3':
- pass
- return r
- # shop option!!! (work)
- def shop(gold):
- global spend, imbue, item
- sh = False
- while True:
- spend = 0
- imbue = 0
- item = ''
- items = {
- 'w1':350,
- 'w2':450,
- 'w3':800,
- 'w4':1000,
- 'w5':1800,
- 'a1':200,
- 'a2':400,
- 'a3':600,
- 'a4':800,
- 'a5':1000
- }
- print 'Welcome to shop!'
- print '1.Weapons'
- print '2.Armors'
- print '3.Back'
- i = raw_input('What you want?')
- os.system('cls')
- if i == '1':
- print 'Imbue your weapon with:'
- print 'w1.+3(350)\nw2.+5(450)\nw3.+7(800)\nw4.+10(1000)\nw5.+20(1800)\n6.Back'
- buy = raw_input('What you want? ')
- os.system('cls')
- try:
- if buy == '6':
- pass
- elif items[buy] > gold:
- print 'Not enought money...'
- os.system('pause')
- os.system('cls')
- elif items[buy] <= gold:
- sh = True
- spend += items[buy]
- if buy == 'w1':
- imbue += 3
- if buy == 'w2':
- imbue += 5
- if buy == 'w3':
- imbue += 7
- if buy == 'w4':
- imbue += 10
- if buy == 'w5':
- imbue += 20
- item = 'weapon'
- os.system('cls')
- except:
- print 'Wrong command...\n'
- break
- if i == '2':
- print 'Imbue your armor with:'
- print 'a1.+1(200)\na2.+3(400)\na3.+5(600)\na4.+7(800)\na5.+12(1000)\n6.Back'
- buy = raw_input('What you want? ')
- os.system('cls')
- try:
- if buy == '6':
- pass
- elif items[buy] > gold:
- print 'Not enought money...'
- os.system('pause')
- os.system('cls')
- elif items[buy] <= gold:
- sh = True
- spend += items[buy]
- if buy == 'a1':
- imbue += 1
- if buy == 'a2':
- imbue += 3
- if buy == 'a3':
- imbue += 5
- if buy == 'a4':
- imbue += 7
- if buy == 'a5':
- imbue += 12
- item = 'armor'
- os.system('cls')
- break
- except:
- print 'Wrong command...'
- break
- if i == '3':
- break
- return sh
- #let's play
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement