Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.73 KB | None | 0 0
  1. # Text-based game
  2. # Mihail Feraru@littlwho
  3. # Old code found in a backup... Nostalgia :((((
  4.  
  5. import os, random, time, sys
  6.  
  7. def menu():# game menu
  8.     print '    Gladiators\' arena\n         1.8v'
  9.     print '\n'
  10.     print '1.New game'
  11.     print '2.Load Game'
  12.     print '3.Quit\n'
  13.  
  14. def slow(text):# intro text (work)
  15.     for c in text:
  16.         sys.stdout.write(c)
  17.         sys.stdout.flush()
  18.         time.sleep(0.015)
  19.  
  20. #start game
  21. def game():
  22.     while True:
  23.         menu()
  24.         c = raw_input('\nEnter the number of your choice:')
  25.         os.system('cls')
  26.  
  27.         if c == '1':
  28.             new_game()
  29.  
  30.         elif c == '2':
  31.             try:
  32.                 load_game()
  33.                 if exit_ == True:
  34.                     sys.exit(0)
  35.             except:
  36.                 print 'No saved games...'
  37.                 os.system('pause')
  38.                 os.system('cls')
  39.  
  40.         elif c == '3':
  41.             sys.exit(0)
  42.  
  43.         else:
  44.             print 'I don\'t understand you!'
  45.             os.system('cls')
  46.  
  47. # new game option!!! (work)
  48. def new_game():
  49.     #variables
  50.     gold = 0
  51.     rounds = 1
  52.     life = 50
  53.     inventory = {
  54.         "weapon" : 5,
  55.         "armor" : 0
  56.         }
  57.    
  58.     #the game
  59.     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!!!'
  60.     slow(intro)
  61.     print '\n'
  62.     while True:
  63.         print 'Gold:'+str(gold),
  64.         print '          Round:'+str(rounds)
  65.         print '1.Let\'s Fight!'
  66.         print '2.Shop'
  67.         print '3.Profile'
  68.         print '4.Save game'
  69.         print '5.Exit\n'
  70.  
  71.         c = raw_input('What is your command? ')
  72.         os.system('cls')
  73.  
  74.         if c == '1':
  75.             fight(inventory['weapon'],inventory['armor'],life,rounds)
  76.             if end == True:
  77.                 sys.exit(0)
  78.             if r == 'win':
  79.                 gold += 500
  80.                 rounds += 1
  81.                 life += 50
  82.             elif r == 'add':
  83.                 gold += add
  84.             elif r == 'lose':
  85.                 inventory['weapon'] = 5
  86.                 inventory['armor'] = 0
  87.             if troll_K == True:
  88.                 inventory['weapon'] += 10
  89.                 inventory['armor'] += 10
  90.             os.system('cls')
  91.  
  92.         elif c == '2':
  93.             if shop(gold):
  94.                 gold -= spend
  95.                 inventory[item] += imbue
  96.             os.system('cls')
  97.            
  98.         elif c == '3':
  99.             print 'Gold:%d\nLife:%d\nWeapon:%d\nArmor:%d\nRound:%d\n' % (gold, life, inventory['weapon'], inventory['armor'], rounds)
  100.             os.system('pause')
  101.             os.system('cls')
  102.            
  103.         elif c == '4':
  104.             f = open('save.py','w')
  105.             data = 'gold='+str(gold)+'\n' + 'rounds='+str(rounds)+'\n' + 'life='+str(life)+'\n' + 'inventory='+str(inventory)
  106.             f.write(data)
  107.             f.close()
  108.             print '\nGame saved...\n'
  109.             os.system('pause')
  110.             os.system('cls')
  111.  
  112.         elif c == '5':
  113.             sys.exit(0)
  114.  
  115.  
  116. #load game option!!! (work)
  117. def load_game():
  118.     global exit_
  119.     exit_ = False
  120.     from save import gold, rounds, inventory, life
  121.     while True:
  122.         print 'Gold:'+str(gold),
  123.         print '          Round:'+str(rounds)
  124.         print '1.Let\'s Fight!'
  125.         print '2.Shop'
  126.         print '3.Profile'
  127.         print '4.Save game'
  128.         print '5.Exit\n'
  129.  
  130.         c = raw_input('What is your command? ')
  131.         os.system('cls')
  132.  
  133.         if c == '1':
  134.             fight(inventory['weapon'],inventory['armor'],life,rounds)
  135.             if end == True:
  136.                 sys.exit(0)
  137.             if r == 'win':
  138.                 gold += 500
  139.                 rounds += 1
  140.                 life += 50
  141.             elif r == 'add':
  142.                 gold += add
  143.             elif r == 'lose':
  144.                 inventory['weapon'] = 5
  145.                 inventory['armor'] = 0
  146.             if troll_K == True:
  147.                 inventory['weapon'] += 10
  148.                 inventory['armor'] += 10
  149.             os.system('cls')
  150.  
  151.         elif c == '2':
  152.             if shop(gold):
  153.                 gold -= spend
  154.                 inventory[item] += imbue
  155.             os.system('cls')
  156.  
  157.         elif c == '3':
  158.             print 'Gold:%d\nLife:%d\nWeapon:%d\nArmor:%d\nRound:%d\n' % (gold, life, inventory['weapon'], inventory['armor'], rounds)
  159.             os.system('pause')
  160.             os.system('cls')
  161.            
  162.         elif c == '4':
  163.             f = open('save.py','w')
  164.             data = 'gold='+str(gold)+'\n' + 'rounds='+str(rounds)+'\n' + 'life='+str(life)+'\n' + 'inventory='+str(inventory)
  165.             f.write(data)
  166.             f.close()
  167.             print '\nGame saved...\n'
  168.             os.system('pause')
  169.             os.system('cls')
  170.  
  171.         elif c == '5':
  172.             exit_ = True
  173.             break
  174.  
  175. #fight option!!! (work)
  176. def fight(weapon,armor,life,rounds):
  177.     global add, r, troll_K, end
  178.     end = False
  179.     troll_K = False
  180.     r = None
  181.     add = 0
  182.     wfe = 0
  183.     afe = 0
  184.     lfe = 0
  185.     print '1.Arena'
  186.     print '2.Forest'
  187.     print '!WARNING if you die in Arena, your weapon and armor will be destroyed!'
  188.     print '3.Back'
  189.  
  190.     c = raw_input('Cammand: ')
  191.     os.system('cls')
  192.  
  193.     if rounds == 1:
  194.         we = 6
  195.         ae = 5
  196.         le = 50
  197.     elif rounds == 2:
  198.         we = 10
  199.         ae = 8
  200.         le = 100
  201.     elif rounds == 3:
  202.         we = 14
  203.         ae = 14
  204.         le = 100
  205.     elif rounds == 4:
  206.         we = 17
  207.         ae = 10
  208.         le = 100
  209.     elif rounds == 5:
  210.         we = 25
  211.         ae = 20
  212.         le = 300
  213.     elif rounds == 6:
  214.         we = 40
  215.         ae = 25
  216.         le = 250
  217.     elif rounds == 7:
  218.         we = 40
  219.         ae = 40
  220.         le = 300
  221.     elif rounds == 8:
  222.         we = 60
  223.         ae = 25
  224.         le = 350
  225.     elif rounds == 9:
  226.         we = 80
  227.         ae = 40
  228.         le = 400
  229.     elif rounds == 10:
  230.         we = 100
  231.         ae = 50
  232.         le = 500
  233.     elif rounds == 11:
  234.         we = 100
  235.         ae = 80
  236.         le = 600
  237.     elif rounds == 12:
  238.         we = 200
  239.         ae = 200
  240.         le = 800
  241.  
  242.     if c == '1':
  243.         while True:
  244.             if le == 0 or le < 0:
  245.                 print 'You win!'
  246.                 if rounds == 5:
  247.                     print 'You killed the one of best gladiators!But you aren\'t free, you must continue fighting!\n Next are rounds comming soon...'
  248.                 if rounds == 10:
  249.                     print 'You DID it agin!!!You are almost FREE!'
  250.                 if rounds == 12:
  251.                     print '           You are FREE!!!FREEDOM is so sweet!'
  252.                     print '\n\n\n             Game produced by\n                &Mihai\n\n\n'
  253.                     end = True
  254.                 os.system('pause')
  255.                 os.system('cls')
  256.                 r = 'win'
  257.                 break
  258.             elif life == 0 or life < 0:
  259.                 print 'You lost!'
  260.                 os.system('pause')
  261.                 os.system('cls')
  262.                 r = 'lose'
  263.                 break
  264.                
  265.             print '   You' + '          Enemy'
  266.             print 'Weapon:' + str(weapon) + '         Weapon:' + str(we)
  267.             print 'Armor:' + str(armor) + '          Armor:' + str(ae)
  268.             print 'Life:' + str(life) + '           Life:' + str(le)
  269.             print '1.Attack!'
  270.             print '2.Retreat!'
  271.            
  272.             c = raw_input('Command? ')
  273.             os.system('cls')
  274.  
  275.             if c == '1':
  276.                 os.system('cls')
  277.                 if we - armor > 0:
  278.                     life = life - (we - armor)
  279.                 if weapon - ae > 0:
  280.                     le = le - (weapon - ae)
  281.             if c == '2':
  282.                 os.system('cls')
  283.                 break
  284.            
  285.     elif c == '2':
  286.         r = 'add'
  287.         while True:
  288.             if troll_K == True:
  289.                 break
  290.             print 'You entered in the dark forest...\n'
  291.             print 'With who you want to fight?\n'
  292.             print '1.Rat (40gold)'
  293.             print '2.Wolf (60gold)'
  294.             print '3.Gigant Bat (100gold)'
  295.             print '4.Tiger (150gold)'
  296.             print '5.Lion (250gold)'
  297.             print '6.Barbar (350gold)'
  298.             print '7.Little Troll (500gold)'
  299.             print '8.Troll Soldier (800gold)'
  300.             print '9.Troll Lord (1500gold)'
  301.             print '10.Troll King! (3000gold)'
  302.             print '11.Back\n'
  303.  
  304.             att = raw_input('Who you will attack? ')
  305.             os.system('cls')
  306.  
  307.             if att == '1':
  308.                 wfe = 2
  309.                 afe = 0
  310.                 lfe = 30
  311.                 for_add = 40
  312.                
  313.             elif att == '2':
  314.                 wfe = 5
  315.                 afe = 1
  316.                 lfe = 40
  317.                 for_add = 60
  318.                
  319.             elif att == '3':
  320.                 wfe = 7
  321.                 afe = 3
  322.                 lfe = 50
  323.                 for_add = 100
  324.                
  325.             elif att == '4':
  326.                 wfe = 10
  327.                 afe = 2
  328.                 lfe = 75
  329.                 for_add = 150
  330.                
  331.             elif att == '5':
  332.                 wfe = 16
  333.                 afe = 5
  334.                 lfe = 100
  335.                 for_add = 250
  336.                
  337.             elif att == '6':
  338.                 wfe = 13
  339.                 afe = 10
  340.                 lfe = 120
  341.                 for_add = 350
  342.                
  343.             elif att == '7':
  344.                 wfe = 18
  345.                 afe = 5
  346.                 lfe = 150
  347.                 for_add = 500
  348.                
  349.             elif att == '8':
  350.                 wfe = 20
  351.                 afe = 20
  352.                 lfe = 200
  353.                 for_add = 800
  354.                
  355.             elif att == '9':
  356.                 wfe = 50
  357.                 afe = 50
  358.                 lfe = 250
  359.                 for_add = 1500
  360.                                                                                
  361.                
  362.             elif att == '10':
  363.                 wfe = 100
  364.                 afe = 100
  365.                 lfe = 500
  366.                 for_add = 3000
  367.             else:
  368.                 break
  369.            
  370.            
  371.             while True:
  372.                 if lfe == 0 or lfe < 0:
  373.                     print 'You win!'
  374.                     add += for_add
  375.                     print 'Your reward is %d' % (add)
  376.                     if att == '10':
  377.                         print 'For your help for Roman Empire by killing the Troll King you receive +10 for weapon and armor.'
  378.                         troll_K = True
  379.                     os.system('pause')
  380.                     os.system('cls')
  381.                     break
  382.                 elif life == 0 or life < 0:
  383.                     print 'You lost!'
  384.                     os.system('pause')
  385.                     os.system('cls')
  386.                     c = 0
  387.                     break
  388.                 print '   You' + '          Enemy'
  389.                 print 'Weapon:' + str(weapon) + '         Weapon:' + str(wfe)
  390.                 print 'Armor:' + str(armor) + '          Armor:' + str(afe)
  391.                 print 'Life:' + str(life) + '           Life:' + str(lfe)
  392.                 print '1.Attack!'
  393.                 print '2.Retreat!'
  394.  
  395.                 co = raw_input('What is your command?')
  396.                 os.system('cls')
  397.                
  398.                 if co == '1':
  399.                     if wfe - armor > 0:
  400.                         life = life - (wfe - armor)
  401.                     if weapon - afe > 0:
  402.                         lfe = lfe - (weapon - afe)
  403.                 elif co == '2':
  404.                     c = 0
  405.                     break
  406.  
  407.             if c == 0:
  408.                 break
  409.     elif c == '3':
  410.         pass
  411.            
  412.     return r
  413.  
  414. # shop option!!! (work)
  415. def shop(gold):
  416.     global spend, imbue, item
  417.     sh = False
  418.     while True:
  419.         spend = 0
  420.         imbue = 0
  421.         item = ''
  422.         items = {
  423.             'w1':350,
  424.             'w2':450,
  425.             'w3':800,
  426.             'w4':1000,
  427.             'w5':1800,
  428.            
  429.             'a1':200,
  430.             'a2':400,
  431.             'a3':600,
  432.             'a4':800,
  433.             'a5':1000
  434.             }
  435.         print 'Welcome to shop!'
  436.         print '1.Weapons'
  437.         print '2.Armors'
  438.         print '3.Back'
  439.  
  440.         i = raw_input('What you want?')
  441.         os.system('cls')
  442.            
  443.         if i == '1':
  444.             print 'Imbue your weapon with:'
  445.             print 'w1.+3(350)\nw2.+5(450)\nw3.+7(800)\nw4.+10(1000)\nw5.+20(1800)\n6.Back'
  446.  
  447.             buy = raw_input('What you want? ')
  448.             os.system('cls')
  449.  
  450.             try:
  451.                 if buy == '6':
  452.                     pass
  453.                 elif items[buy] > gold:
  454.                     print 'Not enought money...'
  455.                     os.system('pause')
  456.                     os.system('cls')
  457.                 elif items[buy] <= gold:
  458.                     sh = True
  459.                     spend += items[buy]
  460.                     if buy == 'w1':
  461.                         imbue += 3
  462.                     if buy == 'w2':
  463.                         imbue += 5
  464.                     if buy == 'w3':
  465.                         imbue += 7
  466.                     if buy == 'w4':
  467.                         imbue += 10
  468.                     if buy == 'w5':
  469.                         imbue += 20
  470.                     item = 'weapon'
  471.                     os.system('cls')
  472.  
  473.             except:
  474.                 print 'Wrong command...\n'
  475.             break
  476.         if i == '2':
  477.             print 'Imbue your armor with:'
  478.             print 'a1.+1(200)\na2.+3(400)\na3.+5(600)\na4.+7(800)\na5.+12(1000)\n6.Back'
  479.             buy = raw_input('What you want? ')
  480.             os.system('cls')
  481.  
  482.             try:
  483.                 if buy == '6':
  484.                     pass
  485.                 elif items[buy] > gold:
  486.                     print 'Not enought money...'
  487.                     os.system('pause')
  488.                     os.system('cls')
  489.                 elif items[buy] <= gold:
  490.                     sh = True
  491.                     spend += items[buy]
  492.                     if buy == 'a1':
  493.                         imbue += 1
  494.                     if buy == 'a2':
  495.                         imbue += 3
  496.                     if buy == 'a3':
  497.                         imbue += 5
  498.                     if buy == 'a4':
  499.                         imbue += 7
  500.                     if buy == 'a5':
  501.                         imbue += 12
  502.                     item = 'armor'
  503.                     os.system('cls')
  504.                     break
  505.             except:
  506.                 print 'Wrong command...'
  507.             break
  508.         if i == '3':
  509.             break
  510.     return sh
  511.    
  512. #let's play
  513. game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement