Advertisement
The_Filip

Python Dungeon Crawler

Sep 19th, 2022 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.97 KB | Gaming | 0 0
  1. import random, math, time
  2.  
  3. randomMode = 0 # 0 - User Inputs | 1 - Completely Random | 2 - Selective Random
  4.  
  5. sRandChoice = 4
  6.  
  7. global targetFloor
  8. targetFloor = 5
  9. targetFloorChange = 2
  10.  
  11.  
  12.  
  13.  
  14.  
  15. maxDiceRolls = 12
  16. dice=maxDiceRolls/2
  17.  
  18. #STARTING INTEGERS
  19. global coins
  20. coins = 0 #Maybe add to Character class later?
  21. potionCount = 0
  22.  
  23. healthCost = 1
  24. damageCost = 1
  25. speedCost = 1
  26. potionCost = 20
  27.  
  28.  
  29. potionHeal = 5
  30. potionHealBoost = 1
  31.  
  32.  
  33.  
  34. coinLoss = 2
  35.  
  36.  
  37.  
  38. damageMod = 0
  39. speedMod = 0
  40.  
  41. def damage(character):
  42.     basicDamageCalc(character.lowRange,character.highRange)
  43.     character.damageDealt = character.damageMod+basicDamage
  44.     print(character.damageDealt)
  45.  
  46. def basicDamageCalc(low,high):
  47.     global basicDamage
  48.     basicDamage = random.randint(low,high)
  49.  
  50. def speedCheck(character):
  51.     basicSpeedCalc()
  52.     character.speed = character.speedMod+basicSpeed
  53.     print(character.speed)
  54.  
  55. def basicSpeedCalc():
  56.     global basicSpeed
  57.     basicSpeed = random.randint(1,maxDiceRolls)
  58.  
  59. class character_:
  60.     def __init__(self,name,health,damageMod,speedMod,lowRange,highRange):
  61.         self.name = name
  62.         self.health = health
  63.         self.damageMod = damageMod
  64.         self.speedMod = speedMod
  65.         self.lowRange = lowRange
  66.         self.highRange = highRange
  67.  
  68.         self.basicDamage = random.randint(lowRange,highRange) + self.damageMod
  69.         self.basicSpeed = random.randint(1,maxDiceRolls) + self.speedMod
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. global hp1
  81. global hp2
  82. global victory
  83. victory = False
  84.  
  85. def fight(name1,name2,hp1,bonus1_1,bonus1_2,hp2,bonus2_1,bonus2_2):
  86.     global tHP
  87.     #hp1 = tempHealth
  88.     #print(name1, name2)
  89.     #global hp1
  90.     #global winner
  91.     #global hp2
  92.     while hp2 != 0 and hp1 > 0:
  93.         if hp1 < 0:
  94.             #hp2 = 0
  95.             print("Health Lost")
  96.             tHP=hp1
  97.  
  98.             break
  99.         diceRoll1 = random.randint(1,dice)+random.randint(1,dice)+bonus1_1
  100.         diceRoll2 = random.randint(1,dice)+random.randint(1,dice)+bonus2_1
  101.  
  102.  
  103.         while diceRoll1 == diceRoll2:
  104.             diceRoll2 = random.randint(1,dice)+random.randint(1,dice)+bonus2_1
  105.  
  106.         print("Speed Check")
  107.         print(name1,"-",diceRoll1)
  108.         print(name2,"-",diceRoll2)
  109.        
  110.         #choice = input()
  111.         #if choice == ",":
  112.             #hp1 +=1
  113.         #if  choice == ".":
  114.             #hp2 +=1
  115.  
  116.         print (name1,"-",hp1)
  117.         print (name2,"-",hp2)
  118.         diceRoll3 = random.randint(1,dice)+random.randint(1,dice)+bonus1_2
  119.         diceRoll4 = random.randint(1,dice)+random.randint(1,dice)+bonus2_2
  120.         while diceRoll3 == diceRoll4:
  121.             diceRoll4 = random.randint(1,dice)+random.randint(1,dice)+bonus2_2
  122.  
  123.         print("Attack Check")
  124.         print(name1,"-",diceRoll3)
  125.         print(name2,"-",diceRoll4)
  126.  
  127.         if diceRoll1 > diceRoll2:
  128.             if diceRoll3 > diceRoll4:
  129.                 hp2-=1
  130.         else:
  131.             if diceRoll3 < diceRoll4:
  132.                 hp1-=1
  133.  
  134.         print (name1,"-",hp1)
  135.         print (name2,"-",hp2)
  136.         #tempHealth = hp1
  137.         tHP=hp1
  138.     #else:
  139.         #print("Health Lost")
  140.         #location = "Town"
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. p1= character_("Player",10,0,0,1,2)
  158.  
  159.  
  160.  
  161. #locations - Town | Dungeon | Floor1 etc.
  162.  
  163. location = "Town"
  164. coinGain = 0
  165. difficulty = 2
  166. dungeonFloor = 0
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. def shop():
  175.     print("shop")
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. def Town():
  183.     global townVisits
  184.     townVisits += 1
  185.     print ("Town Visits:",townVisits)
  186.     global coins
  187.     global healthCost
  188.     global damageCost
  189.     global speedCost
  190.     global potionCost
  191.     global potionCount
  192.  
  193.     #Give player choice of either going into the dungeon or upgrading stats
  194.     print("1 Dungeon\n2 +1 Max Health - ",healthCost,"\n3 +1 Damage Roll - ",damageCost,"\n4 +1 Speed Roll - ",speedCost,"\n5 Potion - ",potionCost)
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.     choice = 0
  205.  
  206.     if randomMode == 0:
  207.         choice = int(input(">>"))
  208.  
  209.     if randomMode == 1:
  210.         choice = random.randint(1,5) #################################################################
  211.  
  212.  
  213.     if randomMode == 2:
  214.         randNum = random.randint(1,2)
  215.         if randNum == 1:
  216.             choice = 1
  217.         if randNum == 2:
  218.             choice = sRandChoice
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.    
  227.     if choice == 1:
  228.         global location
  229.         victory = True
  230.         location = "Dungeon"
  231.  
  232.     elif choice == 2:
  233.         if coins < healthCost:
  234.             print("Not enough coins")
  235.         else:
  236.             coins -= healthCost
  237.             healthCost+=1
  238.             p1.health+=1
  239.  
  240.     elif choice == 3:
  241.         if coins < damageCost:
  242.             print("Not enough coins")
  243.         else:
  244.             coins -= damageCost
  245.             damageCost += 1
  246.             p1.damageMod+=1
  247.  
  248.     elif choice == 4:
  249.         if coins < speedCost:
  250.             print("Not enough coins")
  251.         else:
  252.             coins -= speedCost
  253.             speedCost += 1
  254.             p1.speedMod+=1
  255.    
  256.     elif choice == 5:
  257.         if coins < potionCost:
  258.             print("Not enough coins")
  259.         else:
  260.             coins -= potionCost
  261.             potionCost = math.floor(potionCost*1.5)
  262.             potionCount+=1
  263.  
  264.  
  265.  
  266. def dungeoningDown():
  267.     global tempHealth
  268.     global tempEnemyAmount
  269.     global dungeonFloor
  270.     global tempCoins
  271.     global victory
  272.     dungeonFloor += 1
  273.     #coinGain = 1
  274.     tempEnemyAmount = difficulty*dungeonFloor
  275.     while tempEnemyAmount > 0:
  276.         while tempHealth > 0:
  277.             fighting()
  278.             tempHealth = tHP
  279.             tempEnemyAmount -= 1
  280.             print("Floor Enemies - ",tempEnemyAmount)
  281.             if tempEnemyAmount <= 0:
  282.                 break
  283.             print("TEMP HP - ",tempHealth)
  284.  
  285.  
  286.         if tempHealth > 0:
  287.             print("Floor",dungeonFloor,"Complete")
  288.             tempCoins += dungeonFloor*coinGain
  289.             victory = True
  290.             break
  291.         if tempHealth <=0:
  292.             print("Dungeon Lost")
  293.             victory = False
  294.             tempCoins = math.floor(tempCoins/coinLoss)
  295.             break
  296.  
  297.  
  298.             #not looping, not saving temp health
  299.  
  300.  
  301.  
  302. #WORKING on this, need to have a fight in place
  303. def FloorDown():
  304.     global tempDamageMod
  305.     global tempSpeedMod
  306.     global tempHealth
  307.     global victory
  308.     global dungeonFloor
  309.     global location
  310.     global tempCoins
  311.     global coins
  312.     global targetFloor
  313.     global potionCount
  314.     global coinGain
  315.     tempHealth = p1.health
  316.     tempDamageMod = p1.damageMod
  317.     tempSpeedMod = p1.speedMod
  318.     tempCoins = 0
  319.     coinGain = 1
  320.     #tempEnemyAmount = difficulty*(dungeonFloor+1)
  321.     dungeonFloor = 0
  322.     victory = False
  323.     print("Dungeon")
  324.     if dungeonFloor == 0:
  325.         dungeoningDown()
  326.     while victory == True:
  327.         print("Hp -",tempHealth)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.         ################################################################## BOSS FLOOR HERE
  335.         if dungeonFloor == targetFloor:
  336.             #fight(BOSS FIGHT)
  337.             #global dungeonFloor
  338.             global difficulty
  339.             global potionHealBoost
  340.             #global targetFloor
  341.             #global coinGain
  342.  
  343.             difficulty += 1
  344.             #if dungeonFloor > targetFloor:
  345.             coinGain=math.floor(coinGain*(difficulty/2))
  346.             targetFloor += math.floor(targetFloor*targetFloorChange)
  347.             potionHealBoost += 1
  348.             print("Victory!!")
  349.             print(townVisits)
  350.             input()
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.         print("---------------")
  360.         print("1 Continue\n2 Potion",potionCount,"\n3 Back To Town")
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.         dungeonChoice = 0
  368.  
  369.  
  370.         if randomMode == 0:
  371.             dungeonChoice = int(input(">>"))
  372.  
  373.  
  374.  
  375.  
  376.         if randomMode == 1 or randomMode == 2:
  377.             dungeonChoice = random.randint(1,3) #################################################################
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.         if dungeonChoice == 1:
  389.             dungeoningDown()
  390.         if dungeonChoice == 2:
  391.             if potionCount > 0:
  392.                 potionCount -= 1
  393.                 tempHealth += potionHeal*potionHealBoost
  394.                 if tempHealth > p1.health:
  395.                     tempHealth = p1.health
  396.             else:
  397.                 print("Not enough potions")
  398.         if dungeonChoice == 3:
  399.             victory = False
  400.             location = "Town"
  401.             coins += tempCoins
  402.             tempCoins = 0
  403.             break
  404.     if victory == False:
  405.         location = "Town"
  406.         coins += tempCoins
  407.         #coins += dungeonFloor
  408.  
  409.  
  410.     #CONTINUE DOWN OR GO BACK TO TOWN
  411.    
  412.    
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421. def fighting():
  422.     e1 = character_("Enemy",random.randint(1,dungeonFloor+1),random.randint(0,dungeonFloor),random.randint(0,dungeonFloor),1,random.randint(1,dungeonFloor+1))
  423.     global tempHealth
  424.  
  425.  
  426.     if dungeonFloor == targetFloor:
  427.         fight(p1.name,e1.name,tempHealth,p1.damageMod,p1.speedMod,e1.health,e1.damageMod,e1.speedMod)
  428.             #fight(BOSS FIGHT)
  429.             #global dungeonFloor
  430.         #    global difficulty
  431.         #    global tempEnemyAmount
  432.         #    tempEnemyAmount = 1
  433.         #   bossName = ("Big Boss",dungeonFloor)
  434.         #    boss1 = character_(bossName,random.randint(dungeonFloor,dungeonFloor*(difficulty/2)),dungeonFloor,dungeonFloor,dungeonFloor,random.randint(dungeonFloor,(dungeonFloor*(difficulty/2))))
  435.         #    fight(p1.name,boss1.name,tempHealth,p1.damageMod,p1.speedMod,boss1.health,boss1.damageMod,boss1.speedMod)
  436.  
  437.     if dungeonFloor != targetFloor:
  438.         fight(p1.name,e1.name,tempHealth,p1.damageMod,p1.speedMod,e1.health,e1.damageMod,e1.speedMod)
  439.  
  440.     #print("fight happens")
  441.     #tempHealth = hp1
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449. townVisits = 0
  450.  
  451. #damage(p1)
  452. def _main_():
  453.  
  454.  
  455.     print("|",p1.name,"| hp -",p1.health,"| $ -",coins,"| dmg/def -",p1.damageMod,"| spd -",p1.speedMod,"|","| pot -",potionCount,"|")
  456.    
  457.     #Check where the player is - Town or in dungeon
  458.     if location == "Town" and victory == False:
  459.         Town()
  460.     if location == "Dungeon":
  461.         FloorDown()
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470. while True:
  471.     _main_()
  472. print("End")
Tags: game python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement