Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.67 KB | None | 0 0
  1. ' health potion after enemy death
  2.  
  3. Module Module1
  4.  
  5. Dim weaponDurability, minDurabilityLoss, maxDurabilityLoss, playerHealth, maxPlayerHealth, maxDamage, bossesActivated, healthPotions, potionMaxHealAmount, potionMinHealAmount, maxEnemyHealth, minEnemyHealth, potionDropChance, maxEnemyDamage, minEnemyDamage, enemyHealth, enemiesActivated, minDamage, maxBossHealth, minBossHealth, maxBossDamage, minBossDamage, attackAmount, enemyAttackAmount As Integer
  6. Dim weaponDamageBoost As Decimal
  7. Dim enemyActive, enemyAnnounced, newGame, isBoss As Boolean
  8. Dim enemyTypes As String()
  9. Dim enemy, givenDeathReason, attackMethod As String
  10.  
  11. Sub StartGame()
  12.  
  13. newGame = True
  14.  
  15. maxPlayerHealth = 100 ' Starting player health
  16. maxDamage = 36 ' Max damage player can cause
  17. minDamage = 26 ' Min damage player can cause
  18. healthPotions = 3 ' Starting health potions
  19.  
  20. potionMaxHealAmount = 40 ' Max potion healing power
  21. potionMinHealAmount = 25 ' Min potion healing power
  22. potionDropChance = 35 ' Chance of new potion drop
  23.  
  24. maxEnemyHealth = 75 ' Max enemy starting health
  25. minEnemyHealth = 25 ' Min enemy starting health
  26. maxBossHealth = 110 ' Max boss starting health
  27. minBossHealth = 80 ' Min boss starting health
  28. maxBossDamage = 40 ' Max damage boss can cause
  29. minBossDamage = 30 ' Min damage boss can cause
  30. maxEnemyDamage = 30 ' Max damage enemy can cause
  31. minEnemyDamage = 20 ' Min damage enemy can cause
  32.  
  33. weaponDurability = 100 ' Starting weapon durability
  34. weaponDamageBoost = 1.2 ' Whilst weapon active, boost by what decimal
  35. minDurabilityLoss = 6 ' Min durability loss from using weapon
  36. maxDurabilityLoss = 8 ' Max durability loss from using weapon
  37.  
  38. ' Types of enemies that can be used in the game
  39. enemyTypes = {"Skeleton", "Wolf", "Bat", "Assassin", "Zombie", "Giant", "Goblin", "Witch", "Wizard"}
  40.  
  41. ' Do not change these three variables
  42. enemiesActivated = 0
  43. bossesActivated = 0
  44. enemyActive = False
  45.  
  46. Intro()
  47.  
  48. End Sub
  49.  
  50. Sub Intro()
  51.  
  52. playerHealth = maxPlayerHealth
  53.  
  54. Console.ForegroundColor = ConsoleColor.Green
  55. Console.Write("
  56. ▄█ █▄ ▄████████ ▄█ ▄████████ ▄██████▄ ▄▄▄▄███▄▄▄▄ ▄████████
  57. ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄██▀▀▀███▀▀▀██▄ ███ ███
  58. ███ ███ ███ █▀ ███ ███ █▀ ███ ███ ███ ███ ███ ███ █▀
  59. ███ ███ ▄███▄▄▄ ███ ███ ███ ███ ███ ███ ███ ▄███▄▄▄
  60. ███ ███ ▀▀███▀▀▀ ███ ███ ███ ███ ███ ███ ███ ▀▀███▀▀▀
  61. ███ ███ ███ █▄ ███ ███ █▄ ███ ███ ███ ███ ███ ███ █▄
  62. ███ ▄█▄ ███ ███ ███ ███▌ ▄ ███ ███ ███ ███ ███ ███ ███ ███ ███
  63. ▀███▀███▀ ██████████ █████▄▄██ ████████▀ ▀██████▀ ▀█ ███ █▀ ██████████
  64. ")
  65. Console.ForegroundColor = ConsoleColor.Gray
  66. Console.Write($"{vbCrLf} Press enter to begin game...")
  67. Console.SetCursorPosition(4, Console.WindowHeight - 4)
  68. Console.Write($"You start with {playerHealth} HP and {healthPotions} Health Potions. Potion drop chance is {potionDropChance}%.")
  69. Console.SetCursorPosition(4, Console.WindowHeight - 3)
  70. Console.Write($"Regular enemies start with between {minEnemyHealth} and {maxEnemyHealth} health.")
  71. Console.SetCursorPosition(4, Console.WindowHeight - 2)
  72. Console.WriteLine($"Bosses start with between {minBossHealth} and {maxBossHealth} health.")
  73.  
  74. Console.ReadKey()
  75.  
  76. InGame()
  77.  
  78. End Sub
  79.  
  80. Sub EnemyGen()
  81. enemy = enemyTypes(Int(enemyTypes.Length * Rnd()))
  82. enemyHealth = Int((maxEnemyHealth - minEnemyHealth + 1) * Rnd() + minEnemyHealth)
  83. enemyActive = True
  84. enemiesActivated += 1
  85. enemyAnnounced = False
  86. isBoss = False
  87. End Sub
  88.  
  89. Sub PrintOption(ByVal num As Integer, ByVal text As String, Optional ByVal disabled As Boolean = False)
  90. If disabled = True Then
  91. Console.ForegroundColor = ConsoleColor.DarkGray
  92. Console.Write(" [")
  93. Console.ForegroundColor = ConsoleColor.Red
  94. Console.Write(num)
  95. Console.ForegroundColor = ConsoleColor.DarkGray
  96. Else
  97. Console.ForegroundColor = ConsoleColor.Gray
  98. Console.Write(" [")
  99. Console.ForegroundColor = ConsoleColor.Green
  100. Console.Write(num)
  101. Console.ForegroundColor = ConsoleColor.Gray
  102. End If
  103. Console.Write($"] {text}")
  104. Console.ForegroundColor = ConsoleColor.Gray
  105. Console.Write(vbCrLf)
  106.  
  107. End Sub
  108.  
  109. Sub LoseGame(Optional ByVal reason As String = "You were defeated.")
  110.  
  111. Console.Clear()
  112. Console.ForegroundColor = ConsoleColor.Green
  113. Console.Write("
  114. ▄██ ▄ ▄██████▄ ███ █▄ ▄█ ▄██████▄ ▄████████ ███
  115. ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀█████████▄
  116. ███▄▄▄███ ███ ███ ███ ███ ███ ███ ███ ███ █▀ ▀███▀▀██
  117. ▀▀▀▀▀▀███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀
  118. ▄██ ███ ███ ███ ███ ███ ███ ███ ███ ▀███████████ ███
  119. ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  120. ███ ███ ███ ███ ███ ███ ███▌ ▄ ███ ███ ▄█ ███ ███
  121. ▀█████▀ ▀██████▀ ████████▀ █████▄▄██ ▀██████▀ ▄████████▀ ▄████▀
  122. ")
  123. Console.ForegroundColor = ConsoleColor.Gray
  124. Console.WriteLine($"{vbCrLf} {reason}")
  125. Console.WriteLine(" Press enter to play again.")
  126.  
  127.  
  128. Console.ReadKey()
  129. Console.Clear()
  130. StartGame()
  131. Exit Sub
  132. End Sub
  133.  
  134. Sub WinGame(ByVal reason As String)
  135.  
  136. Console.Clear()
  137. Console.ForegroundColor = ConsoleColor.Green
  138. Console.Write("
  139. ▄██ ▄ ▄██████▄ ███ █▄ ▄█ █▄ ▄██████▄ ███▄▄▄▄
  140. ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███▀▀▀██▄
  141. ███▄▄▄███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  142. ▀▀▀▀▀▀███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  143. ▄██ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  144. ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  145. ███ ███ ███ ███ ███ ███ ███ ▄█▄ ███ ███ ███ ███ ███
  146. ▀█████▀ ▀██████▀ ████████▀ ▀███▀███▀ ▀██████▀ ▀█ █▀
  147. ")
  148. Console.ForegroundColor = ConsoleColor.Gray
  149. Console.WriteLine($"{vbCrLf} {reason}")
  150. Console.WriteLine(" Press enter to play again.")
  151.  
  152.  
  153. Console.ReadKey()
  154. Console.Clear()
  155. StartGame()
  156. Exit Sub
  157.  
  158. End Sub
  159.  
  160. Sub Spacer()
  161. Console.Write(" ")
  162. For w = 1 To 50
  163. Console.Write(Chr(215))
  164. Next
  165. Console.Write(vbCrLf)
  166. End Sub
  167.  
  168. Sub NewScreen()
  169. Console.Write(vbCrLf)
  170. Spacer()
  171.  
  172. Console.Write(vbCrLf)
  173. Select Case playerHealth
  174. Case > 75
  175. Console.Write($" Your Health: ")
  176. Console.ForegroundColor = ConsoleColor.Green
  177. Console.Write(playerHealth)
  178. Console.ForegroundColor = ConsoleColor.Gray
  179. Case > 35
  180. Console.Write($" Your Health: ")
  181. Console.ForegroundColor = ConsoleColor.DarkYellow
  182. Console.Write(playerHealth)
  183. Console.ForegroundColor = ConsoleColor.Gray
  184. Case Else
  185. Console.Write($" Your Health: ")
  186. Console.ForegroundColor = ConsoleColor.Red
  187. Console.Write(playerHealth)
  188. Console.ForegroundColor = ConsoleColor.Gray
  189. End Select
  190. Select Case weaponDurability
  191. Case > 75
  192. Console.Write($" Weapon Durability: ")
  193. Console.ForegroundColor = ConsoleColor.Green
  194. Console.Write(weaponDurability)
  195. Console.ForegroundColor = ConsoleColor.Gray
  196. Case > 35
  197. Console.Write($" Weapon Durability: ")
  198. Console.ForegroundColor = ConsoleColor.DarkYellow
  199. Console.Write(weaponDurability)
  200. Console.ForegroundColor = ConsoleColor.Gray
  201. Case Else
  202. Console.Write($" Weapon Durability: ")
  203. Console.ForegroundColor = ConsoleColor.Red
  204. Console.Write(weaponDurability)
  205. Console.ForegroundColor = ConsoleColor.Gray
  206. End Select
  207. Console.Write(vbCrLf)
  208. Select Case enemyHealth
  209. Case > 65
  210. Console.Write($" {enemy} Health: ")
  211. Console.ForegroundColor = ConsoleColor.Green
  212. Console.Write(enemyHealth)
  213. Console.ForegroundColor = ConsoleColor.Gray
  214. Case > 25
  215. Console.Write($" {enemy} Health: ")
  216. Console.ForegroundColor = ConsoleColor.DarkYellow
  217. Console.Write(enemyHealth)
  218. Console.ForegroundColor = ConsoleColor.Gray
  219. Case Else
  220. Console.Write($" {enemy} Health: ")
  221. Console.ForegroundColor = ConsoleColor.Red
  222. Console.Write(enemyHealth)
  223. Console.ForegroundColor = ConsoleColor.Gray
  224. End Select
  225. Select Case healthPotions
  226. Case > 0
  227. Console.ForegroundColor = ConsoleColor.Gray
  228. Console.Write($" Health Potions Left: {healthPotions}")
  229. Console.ForegroundColor = ConsoleColor.Gray
  230. Case Else
  231. Console.ForegroundColor = ConsoleColor.Gray
  232. Console.Write($" Health Potions Left: ")
  233. Console.ForegroundColor = ConsoleColor.Red
  234. Console.Write($"{healthPotions}")
  235. Console.ForegroundColor = ConsoleColor.Gray
  236. End Select
  237. End Sub
  238.  
  239. Sub DamageToEnemy()
  240. attackAmount = Int((maxDamage - minDamage + 1) * Rnd() + minDamage)
  241. If attackMethod = "Weapon" Then
  242. attackAmount = attackAmount * weaponDamageBoost
  243. End If
  244. If attackAmount > enemyHealth Then
  245. attackAmount = enemyHealth
  246. End If
  247. enemyHealth -= attackAmount
  248. End Sub
  249.  
  250. Sub DamageFromEnemy()
  251. enemyAttackAmount = Int((maxEnemyDamage - minEnemyDamage + 1) * Rnd() + minEnemyDamage)
  252. If enemyAttackAmount > playerHealth Then
  253. enemyAttackAmount = playerHealth
  254. End If
  255. playerHealth -= enemyAttackAmount
  256. End Sub
  257.  
  258. Sub DamageFromBoss()
  259. enemyAttackAmount = Int((maxBossDamage - minBossDamage + 1) * Rnd() + minBossDamage)
  260. If enemyAttackAmount > playerHealth Then
  261. enemyAttackAmount = playerHealth
  262. End If
  263. playerHealth -= enemyAttackAmount
  264. End Sub
  265.  
  266. Sub BossFight()
  267.  
  268. If bossesActivated >= 3 Then
  269. EnemyGen()
  270. Exit Sub
  271. End If
  272.  
  273. Console.Write(vbCrLf)
  274. Spacer()
  275. Console.ForegroundColor = ConsoleColor.Green
  276. Console.Write("
  277. ▀█████████▄ ▄██████▄ ▄████████ ▄████████ ▄████████ ▄█ ▄██████▄ ▄█ █▄ ███
  278. ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀█████████▄
  279. ███ ███ ███ ███ ███ █▀ ███ █▀ ███ █▀ ███▌ ███ █▀ ███ ███ ▀███▀▀██
  280. ▄███▄▄▄██▀ ███ ███ ███ ███ ▄███▄▄▄ ███▌ ▄███ ▄███▄▄▄▄███▄▄ ███ ▀
  281. ▀▀███▀▀▀██▄ ███ ███ ▀███████████ ▀███████████ ▀▀███▀▀▀ ███▌ ▀▀███ ████▄ ▀▀███▀▀▀▀███▀ ███
  282. ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  283. ███ ███ ███ ███ ▄█ ███ ▄█ ███ ███ ███ ███ ███ ███ ███ ███
  284. ▄█████████▀ ▀██████▀ ▄████████▀ ▄████████▀ ███ █▀ ████████▀ ███ █▀ ▄████▀
  285. ")
  286. Console.ForegroundColor = ConsoleColor.Gray
  287. If healthPotions < 2 Then
  288. Console.Write($"{vbCrLf} To help you with your battle, a Health Potion drops.{vbCrLf}")
  289. healthPotions += 1
  290. End If
  291. enemiesActivated += 1
  292. bossesActivated += 1
  293. enemy = "Boss " & enemyTypes(Int(enemyTypes.Length * Rnd()))
  294. enemyHealth = Int(((maxBossHealth - minBossHealth + 1) * Rnd() + minBossHealth))
  295. enemyActive = True
  296. isBoss = True
  297.  
  298. End Sub
  299.  
  300. Sub AttackSequence()
  301. DamageToEnemy()
  302.  
  303. Spacer()
  304. Console.WriteLine($"{vbCrLf} Attacked {enemy}, causing {attackAmount} damage.")
  305. If enemyHealth <= 0 Then
  306. Console.Write($" Defeated {enemy}.")
  307. Dim potionDropNum, potionDropRand As Integer
  308.  
  309. potionDropNum = 100 / potionDropChance
  310. potionDropRand = Int(potionDropNum * Rnd() + 1)
  311.  
  312. If potionDropRand = 1 Then
  313. Console.Write($" {enemy} dropped a Health Potion.")
  314. healthPotions += 1
  315. End If
  316. Console.Write(vbCrLf)
  317. enemyActive = False
  318. Else
  319. If isBoss = True Then
  320. DamageFromBoss()
  321. Else
  322. DamageFromEnemy()
  323. End If
  324. Console.WriteLine($" {enemy} retaliated and attacked you for {enemyAttackAmount} damage.")
  325. givenDeathReason = $"{enemy} retaliated and attacked you for {enemyAttackAmount} damage."
  326. End If
  327. End Sub
  328.  
  329. Sub InGame()
  330.  
  331. givenDeathReason = ""
  332.  
  333. Dim userChoice As String
  334.  
  335. Do
  336.  
  337. If enemyActive = False Then
  338.  
  339. If enemiesActivated > 12 & bossesActivated > 1 Then
  340. Console.Write(vbCrLf)
  341.  
  342. WinGame("You outlasted all of the enemies.")
  343. Exit Sub
  344.  
  345. ElseIf enemiesActivated > 9 Then
  346.  
  347. Dim randomPoss As Integer = Int(2 * Rnd() + 1)
  348.  
  349. If randomPoss = 1 & bossesActivated > 1 Then
  350. Console.Write(vbCrLf)
  351.  
  352. WinGame("You outlasted all of the enemies.")
  353. Exit Sub
  354.  
  355. Else
  356.  
  357. Dim bossRnd As Integer = Int(3 * Rnd() + 1)
  358.  
  359. If bossRnd = 1 And isBoss = False Then
  360. BossFight()
  361. Else
  362. EnemyGen()
  363. End If
  364. End If
  365.  
  366. ElseIf enemiesActivated > 6 Then
  367.  
  368. Dim bossRnd As Integer = Int(3 * Rnd() + 1)
  369.  
  370. If bossRnd = 1 And isBoss = False Then
  371. BossFight()
  372. Else
  373. EnemyGen()
  374. End If
  375.  
  376. Else
  377. EnemyGen()
  378.  
  379. End If
  380.  
  381. End If
  382.  
  383. If newGame = True Then
  384. Console.Clear()
  385.  
  386. newGame = False
  387. End If
  388.  
  389. NewScreen()
  390.  
  391. Console.Write(vbCrLf)
  392.  
  393. If enemyAnnounced = False Then
  394. Console.WriteLine($"{vbCrLf} {enemy} appeared, with health {enemyHealth}.")
  395. enemyAnnounced = True
  396. End If
  397.  
  398. Console.WriteLine($"{vbCrLf} What would you like to do now?")
  399. If weaponDurability > 0 Then
  400. PrintOption(1, $"Attack the {enemy} using Weapon (x{weaponDamageBoost} Damage Boost)", False)
  401. Else
  402. PrintOption(1, $"Attack the {enemy} using Weapon", True)
  403. End If
  404. PrintOption(2, $"Attack the {enemy} using Fist", False)
  405. PrintOption(3, "Try to run away", False)
  406. If healthPotions > 0 Then
  407. PrintOption(4, "Consume a health potion", False)
  408. Else
  409. PrintOption(4, "Consume a health potion", True)
  410. End If
  411. Console.Write(" >> ")
  412. userChoice = Console.ReadLine()
  413.  
  414. Console.Write(vbCrLf)
  415.  
  416. Select Case userChoice
  417.  
  418. Case 1
  419.  
  420. If weaponDurability > 0 Then
  421. attackMethod = "Weapon"
  422. weaponDurability = weaponDurability - Int((maxDurabilityLoss - minDurabilityLoss + 1) * Rnd() + minDurabilityLoss)
  423. If weaponDurability < 0 Then
  424. weaponDurability = 0
  425. End If
  426. AttackSequence()
  427. Else
  428.  
  429. Spacer()
  430. Console.WriteLine($"{vbCrLf} You can't do that - your weapon is broken!")
  431. End If
  432.  
  433. Case 2
  434.  
  435. attackMethod = "Fist"
  436. AttackSequence()
  437.  
  438. Case 3
  439.  
  440. If enemiesActivated > 10 Then
  441.  
  442. Dim randomPoss As Integer = Int(5 * Rnd() + 1)
  443.  
  444. If randomPoss >= 1 And randomPoss <= 3 Then
  445. If playerHealth < (maxPlayerHealth * 0.2) Then
  446. LoseGame("You limp away from battle, but don't make it out.")
  447. Exit Sub
  448. Else
  449. WinGame($"You escaped the {enemy}.")
  450. Exit Sub
  451.  
  452. End If
  453.  
  454. Else
  455. Spacer()
  456. If isBoss = True Then
  457. DamageFromBoss()
  458. Else
  459. DamageFromEnemy()
  460. End If
  461. Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
  462. Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
  463. givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
  464. End If
  465.  
  466. ElseIf enemiesActivated > 8 Then
  467.  
  468. Dim randomPoss As Integer = Int(2 * Rnd() + 1)
  469.  
  470. If randomPoss = 1 Then
  471. If playerHealth < (maxPlayerHealth * 0.2) Then
  472. LoseGame("You limp away from battle, but don't make it out.")
  473. Exit Sub
  474. Else
  475. WinGame($"You escaped the {enemy}.")
  476. Exit Sub
  477.  
  478. End If
  479.  
  480. Else
  481. Spacer()
  482. If isBoss = True Then
  483. DamageFromBoss()
  484. Else
  485. DamageFromEnemy()
  486. End If
  487. Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
  488. Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
  489. givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
  490. End If
  491.  
  492. Else
  493.  
  494. Spacer()
  495. If isBoss = True Then
  496. DamageFromBoss()
  497. Else
  498. DamageFromEnemy()
  499. End If
  500. Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
  501. Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
  502. givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
  503.  
  504. End If
  505.  
  506. Case 4
  507.  
  508. Dim regenAmount As Integer
  509.  
  510. If healthPotions > 0 Then
  511.  
  512. Spacer()
  513. regenAmount = Int((potionMaxHealAmount - potionMinHealAmount + 1) * Rnd() + potionMinHealAmount)
  514.  
  515. If regenAmount > (maxPlayerHealth - playerHealth) Then
  516. regenAmount = (maxPlayerHealth - playerHealth)
  517. End If
  518.  
  519. If playerHealth = maxPlayerHealth Then
  520. Console.WriteLine($"{vbCrLf} Can't use health potion, you already have full health.")
  521. Else
  522. healthPotions -= 1
  523. playerHealth += regenAmount
  524. Console.WriteLine($"{vbCrLf} Regenerated {regenAmount} health using a health potion.")
  525. End If
  526.  
  527.  
  528. Else
  529. Spacer()
  530. Console.WriteLine($"{vbCrLf} You can't do that - you have no Health Potions!")
  531.  
  532. End If
  533.  
  534. Case Else
  535. Spacer()
  536. Console.WriteLine($"{vbCrLf} Invalid input!")
  537. End Select
  538.  
  539. Loop While playerHealth > 0
  540.  
  541. If playerHealth <= 0 Then
  542. If givenDeathReason <> "" Then
  543. LoseGame(givenDeathReason)
  544. Else
  545. LoseGame()
  546. End If
  547. Exit Sub
  548. End If
  549.  
  550. End Sub
  551.  
  552. Sub Main()
  553.  
  554. Randomize()
  555. StartGame()
  556.  
  557. Console.ReadKey()
  558.  
  559. End Sub
  560.  
  561. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement