Added fighting; adjusted weapon stats
This commit is contained in:
parent
3f438abb68
commit
86d1316ff1
72
battle.go
72
battle.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
@ -12,31 +11,76 @@ type Character struct {
|
||||
Damage int
|
||||
Weapons [5]Weapon
|
||||
Spell Spell
|
||||
Initiative int
|
||||
}
|
||||
|
||||
func Battle(hero, enemy Character) {
|
||||
speed := time.Second
|
||||
speed := time.Second * 1
|
||||
|
||||
heroDamage := hero.Damage + hero.Weapons[0].Damage
|
||||
enemyDamage := enemy.Damage + enemy.Weapons[0].Damage
|
||||
|
||||
heroInitiative := rand.Intn(7) + hero.Initiative
|
||||
enemyInitiative := rand.Intn(7) + enemy.Initiative
|
||||
|
||||
damage := 0
|
||||
|
||||
for {
|
||||
printCombatantStats(&hero, &enemy, heroInitiative, enemyInitiative)
|
||||
|
||||
if heroInitiative >= enemyInitiative {
|
||||
damage = rand.Intn(heroDamage)
|
||||
enemy.Health -= damage
|
||||
print(enemy.Name, " was hit for ", damage, " damage!\n")
|
||||
|
||||
if enemy.Health > 0 {
|
||||
damage = rand.Intn(enemyDamage)
|
||||
hero.Health -= damage
|
||||
print(hero.Name, " was hit for ", damage, " damage!\n")
|
||||
}
|
||||
} else {
|
||||
damage = rand.Intn(enemyDamage)
|
||||
hero.Health -= damage
|
||||
print(hero.Name, " was hit for ", damage, " damage!\n")
|
||||
|
||||
if hero.Health > 0 {
|
||||
damage = rand.Intn(heroDamage)
|
||||
enemy.Health -= damage
|
||||
print(enemy.Name, " was hit for ", damage, " damage!\n")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Random Int: ", rand.Intn(11))
|
||||
time.Sleep(speed)
|
||||
print("Hero: ", hero.Name, "\n")
|
||||
print("Enemy: ", enemy.Name, "\n")
|
||||
|
||||
if spellOrAttack() == "spell" {
|
||||
print("Spell Damage: ", hero.Spell.Damage, "\n")
|
||||
if enemy.Health <= 0 || hero.Health <= 0 {
|
||||
ClearScreen()
|
||||
printCombatantStats(&hero, &enemy, heroInitiative, enemyInitiative)
|
||||
|
||||
print("It's over\n")
|
||||
if enemy.Health <= 0 {
|
||||
print("The ", enemy.Name, " is dead!\n")
|
||||
} else {
|
||||
print("Attack Damage: ", hero.Damage, "\n")
|
||||
print("Rest in peace ", hero.Name, "\n")
|
||||
}
|
||||
|
||||
if enemy.Name == "Goblin" {
|
||||
print("This is a goblin character\n")
|
||||
break
|
||||
}
|
||||
ClearScreen()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func spellOrAttack() string {
|
||||
if rand.Intn(2) == 1 {
|
||||
return "spell"
|
||||
func flipCoin() string {
|
||||
if rand.Intn(10) < 5 {
|
||||
return "heads"
|
||||
} else {
|
||||
return "attack"
|
||||
return "tails"
|
||||
}
|
||||
}
|
||||
|
||||
func printCombatantStats(hero, enemy *Character, heroInitiative, enemyInitiative int) {
|
||||
|
||||
print("Hero: ", hero.Name, "\t", "Enemy: ", enemy.Name, "\n")
|
||||
print("Health: ", hero.Health, "\t", "Health: ", enemy.Health, "\n")
|
||||
print("Initiative: ", heroInitiative, "\t", "Initiative: ", enemyInitiative, "\n\n")
|
||||
}
|
||||
|
10
main.go
10
main.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -14,16 +13,18 @@ var (
|
||||
|
||||
Name: "Daniel",
|
||||
Health: 100,
|
||||
Damage: 60,
|
||||
Damage: 30,
|
||||
Spell: firearrow,
|
||||
Weapons: [5]Weapon{Broadsword}}
|
||||
Weapons: [5]Weapon{Broadsword},
|
||||
Initiative: 4}
|
||||
|
||||
goblin = Character{
|
||||
|
||||
Name: "Goblin",
|
||||
Health: 100,
|
||||
Damage: 20,
|
||||
Weapons: [5]Weapon{GoblinClaw}}
|
||||
Weapons: [5]Weapon{GoblinClaw},
|
||||
Initiative: 3}
|
||||
|
||||
firearrow = Spell{
|
||||
Name: "Fire Arrow",
|
||||
@ -36,7 +37,6 @@ var (
|
||||
func main() {
|
||||
initGame()
|
||||
Battle(player, goblin)
|
||||
fmt.Println(goblin.Weapons[0].Damage)
|
||||
}
|
||||
|
||||
func initGame() {
|
||||
|
@ -9,7 +9,7 @@ type Weapon struct {
|
||||
var (
|
||||
Broadsword = Weapon{
|
||||
Name: "Broadsword",
|
||||
Damage: 25,
|
||||
Damage: 3,
|
||||
Active: false}
|
||||
|
||||
GoblinClaw = Weapon{
|
||||
|
Loading…
x
Reference in New Issue
Block a user