Continuing Work
This commit is contained in:
1
game/config.go
Normal file
1
game/config.go
Normal file
@@ -0,0 +1 @@
|
||||
package game
|
||||
128
game/entities.go
Normal file
128
game/entities.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package game
|
||||
|
||||
// Attributes
|
||||
type stat struct {
|
||||
name string
|
||||
short string
|
||||
value int
|
||||
}
|
||||
|
||||
type attributes struct {
|
||||
health stat
|
||||
strength stat
|
||||
endurance stat
|
||||
dexterity stat
|
||||
wisdom stat
|
||||
intelligence stat
|
||||
}
|
||||
|
||||
// Levels
|
||||
type level struct {
|
||||
experience int
|
||||
points int
|
||||
}
|
||||
|
||||
// Inventory
|
||||
type Item struct {
|
||||
name string
|
||||
id int
|
||||
drop int
|
||||
}
|
||||
|
||||
type Slot struct {
|
||||
amount int
|
||||
content Item
|
||||
}
|
||||
|
||||
// Player and Non Player Characters
|
||||
type Player struct {
|
||||
name string
|
||||
levels []level
|
||||
money int
|
||||
stats attributes
|
||||
inventory []Slot
|
||||
}
|
||||
|
||||
type Enemy struct {
|
||||
name string
|
||||
stats attributes
|
||||
loot []Item
|
||||
money int
|
||||
}
|
||||
|
||||
// Initialization Functions
|
||||
func makeAttributes() attributes {
|
||||
return attributes{
|
||||
health: stat{
|
||||
name: "Health",
|
||||
short: "HP",
|
||||
value: 10,
|
||||
},
|
||||
strength: stat{
|
||||
name: "Strength",
|
||||
short: "Str",
|
||||
value: 1,
|
||||
},
|
||||
endurance: stat{
|
||||
name: "Endurance",
|
||||
short: "End",
|
||||
value: 1,
|
||||
},
|
||||
dexterity: stat{
|
||||
name: "Dexterity",
|
||||
short: "Dex",
|
||||
value: 1,
|
||||
},
|
||||
wisdom: stat{
|
||||
name: "Wisdom",
|
||||
short: "Wis",
|
||||
value: 1,
|
||||
},
|
||||
intelligence: stat{
|
||||
name: "Intelligence",
|
||||
short: "Int",
|
||||
value: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func makeLevelTable() []level {
|
||||
var ourLevels = make([]level, 0, 10)
|
||||
|
||||
for i := 0; i < 11; i++ {
|
||||
var baseXP int = 100
|
||||
var ourPoints int = 0
|
||||
|
||||
if i > 0 && i%2 == 0 {
|
||||
ourPoints = 5
|
||||
} else if i > 0 && i%2 == 1 {
|
||||
ourPoints = 4
|
||||
}
|
||||
|
||||
ourLevels = append(ourLevels, level{
|
||||
experience: baseXP*i,
|
||||
points: ourPoints,
|
||||
})
|
||||
}
|
||||
|
||||
return ourLevels
|
||||
}
|
||||
|
||||
func MakeNewPlayer(playerName string) Player {
|
||||
return Player{
|
||||
name: playerName,
|
||||
levels: makeLevelTable(),
|
||||
money: 0,
|
||||
stats: makeAttributes(),
|
||||
inventory: make([]Slot, 0, 15),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeNewEnemy(enemyName string) Enemy {
|
||||
return Enemy{
|
||||
name: enemyName,
|
||||
stats: makeAttributes(),
|
||||
loot: make([]Item, 0, 5),
|
||||
money: 0,
|
||||
}
|
||||
}
|
||||
39
game/logic.go
Normal file
39
game/logic.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"git.vertinext.com/roryejinn/Ultralight/game"
|
||||
"strings"
|
||||
"math/rand/v2"
|
||||
)
|
||||
|
||||
func (p *Player) AdjustStats(which string, newvalue int) *Player {
|
||||
switch strings.ToLower(which) {
|
||||
case "strength","str":
|
||||
p.stats.strength.value = newvalue
|
||||
case "endurance","end":
|
||||
p.stats.endurance.value = newvalue
|
||||
p.stats.health.value = 5 + (5*newvalue)
|
||||
case "wisdom","wis":
|
||||
p.stats.wisdom.value = newvalue
|
||||
case "intelligence","int":
|
||||
p.stats.intelligence.value = newvalue
|
||||
case "dexterity","dex":
|
||||
p.stats.dexterity.value = newvalue
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Player) AdjustMoney(adjustment int) *Player {
|
||||
p.money += adjustment
|
||||
return p
|
||||
}
|
||||
|
||||
func (i Item) GetAmount() int {
|
||||
chance := rand.IntN(100)+1
|
||||
|
||||
if chance <= i.drop {
|
||||
return 2
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user