Added fighting; adjusted weapon stats

This commit is contained in:
Logen Kain 2017-10-09 01:41:59 -07:00
parent 3f438abb68
commit 86d1316ff1
3 changed files with 78 additions and 34 deletions

View File

@ -1,42 +1,86 @@
package main
import (
"fmt"
"math/rand"
"time"
)
type Character struct {
Name string
Health int
Damage int
Weapons [5]Weapon
Spell Spell
Name string
Health int
Damage int
Weapons [5]Weapon
Spell Spell
Initiative int
}
func Battle(hero, enemy Character) {
speed := time.Second
speed := time.Second * 1
fmt.Println("Random Int: ", rand.Intn(11))
time.Sleep(speed)
print("Hero: ", hero.Name, "\n")
print("Enemy: ", enemy.Name, "\n")
heroDamage := hero.Damage + hero.Weapons[0].Damage
enemyDamage := enemy.Damage + enemy.Weapons[0].Damage
if spellOrAttack() == "spell" {
print("Spell Damage: ", hero.Spell.Damage, "\n")
} else {
print("Attack Damage: ", hero.Damage, "\n")
}
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")
}
}
time.Sleep(speed)
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("Rest in peace ", hero.Name, "\n")
}
break
}
ClearScreen()
if enemy.Name == "Goblin" {
print("This is a goblin character\n")
}
}
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")
}

22
main.go
View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"math/rand"
"os"
"os/exec"
@ -12,18 +11,20 @@ import (
var (
player = Character{
Name: "Daniel",
Health: 100,
Damage: 60,
Spell: firearrow,
Weapons: [5]Weapon{Broadsword}}
Name: "Daniel",
Health: 100,
Damage: 30,
Spell: firearrow,
Weapons: [5]Weapon{Broadsword},
Initiative: 4}
goblin = Character{
Name: "Goblin",
Health: 100,
Damage: 20,
Weapons: [5]Weapon{GoblinClaw}}
Name: "Goblin",
Health: 100,
Damage: 20,
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() {

View File

@ -9,7 +9,7 @@ type Weapon struct {
var (
Broadsword = Weapon{
Name: "Broadsword",
Damage: 25,
Damage: 3,
Active: false}
GoblinClaw = Weapon{