Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' health potion after enemy death
- Module Module1
- 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
- Dim weaponDamageBoost As Decimal
- Dim enemyActive, enemyAnnounced, newGame, isBoss As Boolean
- Dim enemyTypes As String()
- Dim enemy, givenDeathReason, attackMethod As String
- Sub StartGame()
- newGame = True
- maxPlayerHealth = 100 ' Starting player health
- maxDamage = 36 ' Max damage player can cause
- minDamage = 26 ' Min damage player can cause
- healthPotions = 3 ' Starting health potions
- potionMaxHealAmount = 40 ' Max potion healing power
- potionMinHealAmount = 25 ' Min potion healing power
- potionDropChance = 35 ' Chance of new potion drop
- maxEnemyHealth = 75 ' Max enemy starting health
- minEnemyHealth = 25 ' Min enemy starting health
- maxBossHealth = 110 ' Max boss starting health
- minBossHealth = 80 ' Min boss starting health
- maxBossDamage = 40 ' Max damage boss can cause
- minBossDamage = 30 ' Min damage boss can cause
- maxEnemyDamage = 30 ' Max damage enemy can cause
- minEnemyDamage = 20 ' Min damage enemy can cause
- weaponDurability = 100 ' Starting weapon durability
- weaponDamageBoost = 1.2 ' Whilst weapon active, boost by what decimal
- minDurabilityLoss = 6 ' Min durability loss from using weapon
- maxDurabilityLoss = 8 ' Max durability loss from using weapon
- ' Types of enemies that can be used in the game
- enemyTypes = {"Skeleton", "Wolf", "Bat", "Assassin", "Zombie", "Giant", "Goblin", "Witch", "Wizard"}
- ' Do not change these three variables
- enemiesActivated = 0
- bossesActivated = 0
- enemyActive = False
- Intro()
- End Sub
- Sub Intro()
- playerHealth = maxPlayerHealth
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write("
- ▄█ █▄ ▄████████ ▄█ ▄████████ ▄██████▄ ▄▄▄▄███▄▄▄▄ ▄████████
- ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄██▀▀▀███▀▀▀██▄ ███ ███
- ███ ███ ███ █▀ ███ ███ █▀ ███ ███ ███ ███ ███ ███ █▀
- ███ ███ ▄███▄▄▄ ███ ███ ███ ███ ███ ███ ███ ▄███▄▄▄
- ███ ███ ▀▀███▀▀▀ ███ ███ ███ ███ ███ ███ ███ ▀▀███▀▀▀
- ███ ███ ███ █▄ ███ ███ █▄ ███ ███ ███ ███ ███ ███ █▄
- ███ ▄█▄ ███ ███ ███ ███▌ ▄ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ▀███▀███▀ ██████████ █████▄▄██ ████████▀ ▀██████▀ ▀█ ███ █▀ ██████████
- ")
- Console.ForegroundColor = ConsoleColor.Gray
- Console.Write($"{vbCrLf} Press enter to begin game...")
- Console.SetCursorPosition(4, Console.WindowHeight - 4)
- Console.Write($"You start with {playerHealth} HP and {healthPotions} Health Potions. Potion drop chance is {potionDropChance}%.")
- Console.SetCursorPosition(4, Console.WindowHeight - 3)
- Console.Write($"Regular enemies start with between {minEnemyHealth} and {maxEnemyHealth} health.")
- Console.SetCursorPosition(4, Console.WindowHeight - 2)
- Console.WriteLine($"Bosses start with between {minBossHealth} and {maxBossHealth} health.")
- Console.ReadKey()
- InGame()
- End Sub
- Sub EnemyGen()
- enemy = enemyTypes(Int(enemyTypes.Length * Rnd()))
- enemyHealth = Int((maxEnemyHealth - minEnemyHealth + 1) * Rnd() + minEnemyHealth)
- enemyActive = True
- enemiesActivated += 1
- enemyAnnounced = False
- isBoss = False
- End Sub
- Sub PrintOption(ByVal num As Integer, ByVal text As String, Optional ByVal disabled As Boolean = False)
- If disabled = True Then
- Console.ForegroundColor = ConsoleColor.DarkGray
- Console.Write(" [")
- Console.ForegroundColor = ConsoleColor.Red
- Console.Write(num)
- Console.ForegroundColor = ConsoleColor.DarkGray
- Else
- Console.ForegroundColor = ConsoleColor.Gray
- Console.Write(" [")
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write(num)
- Console.ForegroundColor = ConsoleColor.Gray
- End If
- Console.Write($"] {text}")
- Console.ForegroundColor = ConsoleColor.Gray
- Console.Write(vbCrLf)
- End Sub
- Sub LoseGame(Optional ByVal reason As String = "You were defeated.")
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write("
- ▄██ ▄ ▄██████▄ ███ █▄ ▄█ ▄██████▄ ▄████████ ███
- ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀█████████▄
- ███▄▄▄███ ███ ███ ███ ███ ███ ███ ███ ███ █▀ ▀███▀▀██
- ▀▀▀▀▀▀███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀
- ▄██ ███ ███ ███ ███ ███ ███ ███ ███ ▀███████████ ███
- ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ███ ███ ███ ███ ███ ███ ███▌ ▄ ███ ███ ▄█ ███ ███
- ▀█████▀ ▀██████▀ ████████▀ █████▄▄██ ▀██████▀ ▄████████▀ ▄████▀
- ")
- Console.ForegroundColor = ConsoleColor.Gray
- Console.WriteLine($"{vbCrLf} {reason}")
- Console.WriteLine(" Press enter to play again.")
- Console.ReadKey()
- Console.Clear()
- StartGame()
- Exit Sub
- End Sub
- Sub WinGame(ByVal reason As String)
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write("
- ▄██ ▄ ▄██████▄ ███ █▄ ▄█ █▄ ▄██████▄ ███▄▄▄▄
- ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███▀▀▀██▄
- ███▄▄▄███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ▀▀▀▀▀▀███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ▄██ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ███ ███ ███ ███ ███ ███ ███ ▄█▄ ███ ███ ███ ███ ███
- ▀█████▀ ▀██████▀ ████████▀ ▀███▀███▀ ▀██████▀ ▀█ █▀
- ")
- Console.ForegroundColor = ConsoleColor.Gray
- Console.WriteLine($"{vbCrLf} {reason}")
- Console.WriteLine(" Press enter to play again.")
- Console.ReadKey()
- Console.Clear()
- StartGame()
- Exit Sub
- End Sub
- Sub Spacer()
- Console.Write(" ")
- For w = 1 To 50
- Console.Write(Chr(215))
- Next
- Console.Write(vbCrLf)
- End Sub
- Sub NewScreen()
- Console.Write(vbCrLf)
- Spacer()
- Console.Write(vbCrLf)
- Select Case playerHealth
- Case > 75
- Console.Write($" Your Health: ")
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write(playerHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- Case > 35
- Console.Write($" Your Health: ")
- Console.ForegroundColor = ConsoleColor.DarkYellow
- Console.Write(playerHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- Case Else
- Console.Write($" Your Health: ")
- Console.ForegroundColor = ConsoleColor.Red
- Console.Write(playerHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- End Select
- Select Case weaponDurability
- Case > 75
- Console.Write($" Weapon Durability: ")
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write(weaponDurability)
- Console.ForegroundColor = ConsoleColor.Gray
- Case > 35
- Console.Write($" Weapon Durability: ")
- Console.ForegroundColor = ConsoleColor.DarkYellow
- Console.Write(weaponDurability)
- Console.ForegroundColor = ConsoleColor.Gray
- Case Else
- Console.Write($" Weapon Durability: ")
- Console.ForegroundColor = ConsoleColor.Red
- Console.Write(weaponDurability)
- Console.ForegroundColor = ConsoleColor.Gray
- End Select
- Console.Write(vbCrLf)
- Select Case enemyHealth
- Case > 65
- Console.Write($" {enemy} Health: ")
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write(enemyHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- Case > 25
- Console.Write($" {enemy} Health: ")
- Console.ForegroundColor = ConsoleColor.DarkYellow
- Console.Write(enemyHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- Case Else
- Console.Write($" {enemy} Health: ")
- Console.ForegroundColor = ConsoleColor.Red
- Console.Write(enemyHealth)
- Console.ForegroundColor = ConsoleColor.Gray
- End Select
- Select Case healthPotions
- Case > 0
- Console.ForegroundColor = ConsoleColor.Gray
- Console.Write($" Health Potions Left: {healthPotions}")
- Console.ForegroundColor = ConsoleColor.Gray
- Case Else
- Console.ForegroundColor = ConsoleColor.Gray
- Console.Write($" Health Potions Left: ")
- Console.ForegroundColor = ConsoleColor.Red
- Console.Write($"{healthPotions}")
- Console.ForegroundColor = ConsoleColor.Gray
- End Select
- End Sub
- Sub DamageToEnemy()
- attackAmount = Int((maxDamage - minDamage + 1) * Rnd() + minDamage)
- If attackMethod = "Weapon" Then
- attackAmount = attackAmount * weaponDamageBoost
- End If
- If attackAmount > enemyHealth Then
- attackAmount = enemyHealth
- End If
- enemyHealth -= attackAmount
- End Sub
- Sub DamageFromEnemy()
- enemyAttackAmount = Int((maxEnemyDamage - minEnemyDamage + 1) * Rnd() + minEnemyDamage)
- If enemyAttackAmount > playerHealth Then
- enemyAttackAmount = playerHealth
- End If
- playerHealth -= enemyAttackAmount
- End Sub
- Sub DamageFromBoss()
- enemyAttackAmount = Int((maxBossDamage - minBossDamage + 1) * Rnd() + minBossDamage)
- If enemyAttackAmount > playerHealth Then
- enemyAttackAmount = playerHealth
- End If
- playerHealth -= enemyAttackAmount
- End Sub
- Sub BossFight()
- If bossesActivated >= 3 Then
- EnemyGen()
- Exit Sub
- End If
- Console.Write(vbCrLf)
- Spacer()
- Console.ForegroundColor = ConsoleColor.Green
- Console.Write("
- ▀█████████▄ ▄██████▄ ▄████████ ▄████████ ▄████████ ▄█ ▄██████▄ ▄█ █▄ ███
- ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀█████████▄
- ███ ███ ███ ███ ███ █▀ ███ █▀ ███ █▀ ███▌ ███ █▀ ███ ███ ▀███▀▀██
- ▄███▄▄▄██▀ ███ ███ ███ ███ ▄███▄▄▄ ███▌ ▄███ ▄███▄▄▄▄███▄▄ ███ ▀
- ▀▀███▀▀▀██▄ ███ ███ ▀███████████ ▀███████████ ▀▀███▀▀▀ ███▌ ▀▀███ ████▄ ▀▀███▀▀▀▀███▀ ███
- ███ ██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
- ███ ███ ███ ███ ▄█ ███ ▄█ ███ ███ ███ ███ ███ ███ ███ ███
- ▄█████████▀ ▀██████▀ ▄████████▀ ▄████████▀ ███ █▀ ████████▀ ███ █▀ ▄████▀
- ")
- Console.ForegroundColor = ConsoleColor.Gray
- If healthPotions < 2 Then
- Console.Write($"{vbCrLf} To help you with your battle, a Health Potion drops.{vbCrLf}")
- healthPotions += 1
- End If
- enemiesActivated += 1
- bossesActivated += 1
- enemy = "Boss " & enemyTypes(Int(enemyTypes.Length * Rnd()))
- enemyHealth = Int(((maxBossHealth - minBossHealth + 1) * Rnd() + minBossHealth))
- enemyActive = True
- isBoss = True
- End Sub
- Sub AttackSequence()
- DamageToEnemy()
- Spacer()
- Console.WriteLine($"{vbCrLf} Attacked {enemy}, causing {attackAmount} damage.")
- If enemyHealth <= 0 Then
- Console.Write($" Defeated {enemy}.")
- Dim potionDropNum, potionDropRand As Integer
- potionDropNum = 100 / potionDropChance
- potionDropRand = Int(potionDropNum * Rnd() + 1)
- If potionDropRand = 1 Then
- Console.Write($" {enemy} dropped a Health Potion.")
- healthPotions += 1
- End If
- Console.Write(vbCrLf)
- enemyActive = False
- Else
- If isBoss = True Then
- DamageFromBoss()
- Else
- DamageFromEnemy()
- End If
- Console.WriteLine($" {enemy} retaliated and attacked you for {enemyAttackAmount} damage.")
- givenDeathReason = $"{enemy} retaliated and attacked you for {enemyAttackAmount} damage."
- End If
- End Sub
- Sub InGame()
- givenDeathReason = ""
- Dim userChoice As String
- Do
- If enemyActive = False Then
- If enemiesActivated > 12 & bossesActivated > 1 Then
- Console.Write(vbCrLf)
- WinGame("You outlasted all of the enemies.")
- Exit Sub
- ElseIf enemiesActivated > 9 Then
- Dim randomPoss As Integer = Int(2 * Rnd() + 1)
- If randomPoss = 1 & bossesActivated > 1 Then
- Console.Write(vbCrLf)
- WinGame("You outlasted all of the enemies.")
- Exit Sub
- Else
- Dim bossRnd As Integer = Int(3 * Rnd() + 1)
- If bossRnd = 1 And isBoss = False Then
- BossFight()
- Else
- EnemyGen()
- End If
- End If
- ElseIf enemiesActivated > 6 Then
- Dim bossRnd As Integer = Int(3 * Rnd() + 1)
- If bossRnd = 1 And isBoss = False Then
- BossFight()
- Else
- EnemyGen()
- End If
- Else
- EnemyGen()
- End If
- End If
- If newGame = True Then
- Console.Clear()
- newGame = False
- End If
- NewScreen()
- Console.Write(vbCrLf)
- If enemyAnnounced = False Then
- Console.WriteLine($"{vbCrLf} {enemy} appeared, with health {enemyHealth}.")
- enemyAnnounced = True
- End If
- Console.WriteLine($"{vbCrLf} What would you like to do now?")
- If weaponDurability > 0 Then
- PrintOption(1, $"Attack the {enemy} using Weapon (x{weaponDamageBoost} Damage Boost)", False)
- Else
- PrintOption(1, $"Attack the {enemy} using Weapon", True)
- End If
- PrintOption(2, $"Attack the {enemy} using Fist", False)
- PrintOption(3, "Try to run away", False)
- If healthPotions > 0 Then
- PrintOption(4, "Consume a health potion", False)
- Else
- PrintOption(4, "Consume a health potion", True)
- End If
- Console.Write(" >> ")
- userChoice = Console.ReadLine()
- Console.Write(vbCrLf)
- Select Case userChoice
- Case 1
- If weaponDurability > 0 Then
- attackMethod = "Weapon"
- weaponDurability = weaponDurability - Int((maxDurabilityLoss - minDurabilityLoss + 1) * Rnd() + minDurabilityLoss)
- If weaponDurability < 0 Then
- weaponDurability = 0
- End If
- AttackSequence()
- Else
- Spacer()
- Console.WriteLine($"{vbCrLf} You can't do that - your weapon is broken!")
- End If
- Case 2
- attackMethod = "Fist"
- AttackSequence()
- Case 3
- If enemiesActivated > 10 Then
- Dim randomPoss As Integer = Int(5 * Rnd() + 1)
- If randomPoss >= 1 And randomPoss <= 3 Then
- If playerHealth < (maxPlayerHealth * 0.2) Then
- LoseGame("You limp away from battle, but don't make it out.")
- Exit Sub
- Else
- WinGame($"You escaped the {enemy}.")
- Exit Sub
- End If
- Else
- Spacer()
- If isBoss = True Then
- DamageFromBoss()
- Else
- DamageFromEnemy()
- End If
- Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
- Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
- givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
- End If
- ElseIf enemiesActivated > 8 Then
- Dim randomPoss As Integer = Int(2 * Rnd() + 1)
- If randomPoss = 1 Then
- If playerHealth < (maxPlayerHealth * 0.2) Then
- LoseGame("You limp away from battle, but don't make it out.")
- Exit Sub
- Else
- WinGame($"You escaped the {enemy}.")
- Exit Sub
- End If
- Else
- Spacer()
- If isBoss = True Then
- DamageFromBoss()
- Else
- DamageFromEnemy()
- End If
- Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
- Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
- givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
- End If
- Else
- Spacer()
- If isBoss = True Then
- DamageFromBoss()
- Else
- DamageFromEnemy()
- End If
- Console.WriteLine($"{vbCrLf} You tried to run, but got attacked.")
- Console.WriteLine($" {enemy} attacked you for {enemyAttackAmount} damage.")
- givenDeathReason = $"{enemy} attacked you for {enemyAttackAmount} damage."
- End If
- Case 4
- Dim regenAmount As Integer
- If healthPotions > 0 Then
- Spacer()
- regenAmount = Int((potionMaxHealAmount - potionMinHealAmount + 1) * Rnd() + potionMinHealAmount)
- If regenAmount > (maxPlayerHealth - playerHealth) Then
- regenAmount = (maxPlayerHealth - playerHealth)
- End If
- If playerHealth = maxPlayerHealth Then
- Console.WriteLine($"{vbCrLf} Can't use health potion, you already have full health.")
- Else
- healthPotions -= 1
- playerHealth += regenAmount
- Console.WriteLine($"{vbCrLf} Regenerated {regenAmount} health using a health potion.")
- End If
- Else
- Spacer()
- Console.WriteLine($"{vbCrLf} You can't do that - you have no Health Potions!")
- End If
- Case Else
- Spacer()
- Console.WriteLine($"{vbCrLf} Invalid input!")
- End Select
- Loop While playerHealth > 0
- If playerHealth <= 0 Then
- If givenDeathReason <> "" Then
- LoseGame(givenDeathReason)
- Else
- LoseGame()
- End If
- Exit Sub
- End If
- End Sub
- Sub Main()
- Randomize()
- StartGame()
- Console.ReadKey()
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement