saving new turn

This commit is contained in:
Ilia Denisov
2025-09-26 01:38:49 +03:00
parent 6d87ea6086
commit 282150a253
13 changed files with 170 additions and 57 deletions
+3 -3
View File
@@ -10,7 +10,7 @@ import (
)
type Repo interface {
Persist(game.Game) error
SaveTurn(uint, game.Game) error
}
func NewGame(r Repo, races []string) (uuid.UUID, error) {
@@ -46,7 +46,7 @@ func NewGame(r Repo, races []string) (uuid.UUID, error) {
g.Race[i] = game.Race{
ID: raceID,
Name: races[i],
Ally: raceID,
Vote: raceID,
Drive: 1,
Weapons: 1,
Shields: 1,
@@ -104,7 +104,7 @@ func NewGame(r Repo, races []string) (uuid.UUID, error) {
g.Map = *gameMap
if err := r.Persist(*g); err != nil {
if err := r.SaveTurn(0, *g); err != nil {
return uuid.Nil, fmt.Errorf("persist: %s", err)
}
return g.ID, nil
-92
View File
@@ -1,92 +0,0 @@
package game_test
import (
"testing"
"github.com/iliadenisov/galaxy/pkg/model/game"
"github.com/stretchr/testify/assert"
)
func Test_ShipType(t *testing.T) {
Gunship := game.ShipType{
Drive: 4,
Armament: 2,
Weapons: 2,
Shields: 4,
Cargo: 0,
}
assert.Equal(t, Gunship.EmptyMass(), 11.)
Cruiser := game.ShipType{
Drive: 15,
Armament: 1,
Weapons: 15,
Shields: 15,
Cargo: 0,
}
assert.Equal(t, Cruiser.EmptyMass(), 45.)
sg := game.ShipGroup{
Type: Cruiser,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
upgradeCost := sg.UpgradeDriveCost(2.0) +
sg.UpgradeWeaponsCost(2.0) +
sg.UpgradeShieldsCost(2.0) +
sg.UpgradeCargoCost(2.0)
assert.Equal(t, upgradeCost, 225.)
}
func Test_CargoCapacity(t *testing.T) {
test := func(cargoSize float64, expectCapacity float64) {
ship := game.ShipType{
Drive: 1,
Armament: 1,
Weapons: 1,
Shields: 1,
Cargo: cargoSize,
}
sg := game.ShipGroup{
Type: ship,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
assert.Equal(t, expectCapacity, sg.CargoCapacity())
}
test(1, 1.05)
test(5, 6.25)
test(10, 15)
test(50, 175)
test(100, 600)
}
func Test_BombingPower(t *testing.T) {
Gunship := game.ShipType{
Drive: 60.0,
Armament: 3,
Weapons: 30.0,
Shields: 100.0,
Cargo: 0.0,
}
sg := game.ShipGroup{
Type: Gunship,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
expectedBombingPower := 139.295
result := sg.BombingPower()
assert.Equal(t, expectedBombingPower, result)
}