Advertisement
plirof2

Python DopeWars v006

Jun 9th, 2022
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.18 KB | None | 0 0
  1. import random
  2.  
  3. #
  4. #
  5. #To Do
  6. #- Check city  option is valid number
  7. #- Check city  Don't change values for same city
  8. #
  9.  
  10.  
  11. debug=1
  12. totalitems=3
  13. gamedaysduration=30
  14. counter=0
  15. cash=1000
  16. debt=1000
  17. daycount=0
  18. myproductslist = ["Acid","Mushrooms","Peyote"]
  19. inventory=       [     0,           0,     0]
  20. myproductprices =[    10,          20,    30]
  21. flux_price_global=0.3
  22. special_event_chance=0.05
  23. special_event_flux=0.9
  24. #flux_price_special      =[     0.5, 1 ,0.3         ]
  25. currentprices=myproductprices.copy()
  26. city=["Chicago","Athens","Rome"]
  27. currentcity=0
  28.  
  29. #print(mylist[2]) # prints 3
  30.  
  31. def travel_to_city(a):
  32.      global daycount,cash,debt,currentcity
  33.      print ("------------------------------")
  34.      print ("Please select city to travel :")
  35.      for i in range(totalitems):
  36.            print (i,')',city[i])
  37.            
  38.      #print("Please select option :")
  39.      traveloption=999
  40.      while not (traveloption in range(totalitems)):
  41.         traveloption = int(input('please select city number : '))
  42.      traveling(traveloption)    
  43.      daycount=daycount+1
  44.      return 0                                                        
  45.  
  46. def positive_or_negative():
  47.     return 1 if random.random() < 0.5 else -1
  48.  
  49. def random_event_happened():
  50.     return 1 if random.random() < special_event_chance else 0    
  51.  
  52. def reroll_prices(a):
  53.     #if(debug) : print("DEBUG reroll prices : ",a)
  54.     #global daycount,cash,debt,currentcity                            
  55.     #currentcity=a
  56.     #print("Your Current City is : ",city[currentcity])
  57.    
  58.     for i in range(totalitems):
  59.       flux_tmp=flux_price_global*random.random()
  60.       s=positive_or_negative()
  61.     #currentprices[i]:
  62.  
  63.       tmp=int(currentprices[i]+s*flux_tmp*currentprices[i])
  64.       if(debug) : print("DEBUG reroll prices tmp: ",tmp," s=",s , "  flux_tmp=",flux_tmp)
  65.       if (tmp>0) : currentprices[i]=tmp  
  66.       if(random_event_happened()):
  67.         if(debug) : print ("RANDOm EVENT for ",myproductslist[i])
  68.         s=positive_or_negative()
  69.         if(s>0): print ("*** POLICE Bust!!!*** Prices are high for ",myproductslist[i])
  70.         else : print ("*** PRICE DROP *** Prices have dropped for ",myproductslist[i])
  71.         flux_tmp=special_event_flux*random.random()
  72.         tmp=int(currentprices[i]+s*flux_tmp*currentprices[i])
  73.         if (tmp>0) : currentprices[i]=tmp
  74.  
  75.     return 0
  76.  
  77.                                      
  78. def traveling(a):
  79.        global daycount,cash,debt,currentcity                            
  80.        currentcity=a
  81.        print("Your Current City is : ",city[currentcity])
  82.        reroll_prices(a)    
  83.        return 0
  84.  
  85.  
  86. def selectproduct(b_or_c):
  87.     if(debug) : print("DEBUG selectproduct b_or_c : ",b_or_c)
  88.     id = int(input('Please select item number: '))
  89.     q=int(input('Please select item quantity: '))
  90.     if(b_or_c.upper()=='B'): buy(id,q)
  91.     if(b_or_c.upper()=='S'): sell(id,q)
  92.     return 0
  93.    
  94.  
  95. def buy(id,q):
  96.     if(debug) : print("DEBUG buy id= ",id,' , q=',q)
  97.     global daycount,cash,debt,currentcity
  98.     #p = int(input('Please enter : ') )  
  99.     payprice=currentprices[id]*q
  100.     print(payprice)
  101.     if payprice<=cash :
  102.         if(debug) : print("====can BUY=====")
  103.         cash=cash-payprice
  104.         inventory[id]=inventory[id]+q
  105.  
  106.     return 0
  107.  
  108.  
  109. def sell(id,q):
  110.     if(debug) : print("DEBUG sell id= ",id,' , q=',q)
  111.     global daycount,cash,debt,currentcity
  112.     #p = int(input('Please enter : ') )  
  113.     if q<=inventory[id] :
  114.         if(debug) : print ("====can SELL=====")
  115.         payprice=currentprices[id]*q
  116.         cash=cash+payprice
  117.         inventory[id]=inventory[id]-q
  118.     return 0
  119.  
  120.      
  121. #for x in myproductslist:
  122. # print(" ",counter,')',x,end="")
  123. # counter=counter+1
  124. #for y in myproductprices:
  125. # print(y)
  126.  
  127.  
  128.  
  129. def mainpage(a):
  130.     global daycount,cash,debt,currentcity
  131.     print("=========================================")
  132.     print("You are in city : ",city[currentcity], end="")
  133.     print ( "  | Day:",daycount ," | Cash : " , cash, " | Debt:",debt)
  134.     labels = '##){:<12}  {:>12}  {:>12}'.format ("Product", "Owned", "Price")
  135.     labels2 = '---{:<12}  {:>12}  {:>12}'.format("--------", "------", "------")
  136.     print (labels)
  137.     print (labels2)
  138.     for i in range(totalitems):
  139.      line_new = '{:<12}  {:>12}  {:>12}'.format(myproductslist[i], inventory[i], currentprices[i])
  140.      #print (i,')',myproductslist[i],' | owned: ',inventory[i]," | price: ",currentprices[i])
  141.      print (i,')',line_new)
  142.     print("Please select option :")
  143.     option = (input('(B)uy , (S)ell , (T)ravel: '))
  144.     print ("You selected : ",option)
  145.     #a = int(input('(B)uy , (S)ell , (T)ravel: ')
  146.    
  147.     #if 4==3 or 3==3 : print ("ok")
  148.    
  149.     if option=='b' or option=='B'  :
  150.          print ("Buy")
  151.          selectproduct('b')
  152.          
  153.          
  154.     if option.upper()=='S'  :
  155.          print ("Sell")
  156.          selectproduct('s')
  157.    
  158.          
  159.     if option=='T' or option=='t'  :
  160.          print ("Travel")
  161.          travel_to_city('t')        
  162.          
  163.  
  164. while daycount<=gamedaysduration:
  165.     mainpage(1)  
  166.  
  167.  
  168. print ("Game Ended!!!")
  169. print("You are in city : ",city[currentcity])
  170. print ( "  | Day:",daycount ," | Cash : " , cash, " | Debt:",debt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement