137 lines
2.2 KiB
Go
137 lines
2.2 KiB
Go
package main
|
|
|
|
type Board struct {
|
|
Sentinal [4]Card
|
|
Scourge [4]Card
|
|
}
|
|
|
|
func NewBoard() *Board {
|
|
return &Board{
|
|
Sentinal: [4]Card{nil, nil, nil, nil},
|
|
Scourge: [4]Card{nil, nil, nil, nil},
|
|
}
|
|
}
|
|
|
|
func (b *Board) GetRow(id int) []Card {
|
|
if id == 1 {
|
|
return b.Sentinal[:]
|
|
} else {
|
|
return b.Scourge[:]
|
|
}
|
|
}
|
|
|
|
func (b *Board) Move(id, src, dest int) bool {
|
|
var brd [4]Card
|
|
if id == 1 {
|
|
brd = b.Sentinal
|
|
} else {
|
|
brd = b.Scourge
|
|
}
|
|
if brd[src] == nil {
|
|
return false
|
|
}
|
|
if brd[dest] != nil {
|
|
return false
|
|
}
|
|
brd[dest] = brd[src]
|
|
brd[src] = nil
|
|
if id == 1 {
|
|
b.Sentinal = brd
|
|
} else {
|
|
b.Scourge = brd
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (b *Board) Play(id int, c Card, dest int) bool {
|
|
var brd [4]Card
|
|
if id == 1 {
|
|
brd = b.Sentinal
|
|
} else {
|
|
brd = b.Scourge
|
|
}
|
|
if brd[dest] != nil {
|
|
return false
|
|
}
|
|
brd[dest] = c
|
|
if id == 1 {
|
|
b.Sentinal = brd
|
|
} else {
|
|
b.Scourge = brd
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (b *Board) Attack(id int, atk, def int) int {
|
|
var aBrd [4]Card
|
|
var dBrd [4]Card
|
|
if id == 1 {
|
|
aBrd = b.Sentinal
|
|
dBrd = b.Scourge
|
|
} else {
|
|
aBrd = b.Scourge
|
|
dBrd = b.Sentinal
|
|
}
|
|
if aBrd[atk] == nil || !aBrd[atk].CanAttack(atk, def) {
|
|
return -1
|
|
}
|
|
aBrd[atk].Acted()
|
|
if dBrd[def] == nil {
|
|
//health damage
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.Scourge = dBrd
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.Sentinal = dBrd
|
|
}
|
|
return 1
|
|
}
|
|
//Do actual battle math
|
|
attacker := aBrd[atk].Value()
|
|
defender := dBrd[def].Value()
|
|
dBrd[def].Acted()
|
|
//check atk buffs
|
|
for i, v := range aBrd {
|
|
if v.Value() == Two {
|
|
attacker = attacker + 1
|
|
}
|
|
if v.Value() == Three && (i == atk-1 || i == atk+1) {
|
|
attacker = attacker + 1
|
|
}
|
|
}
|
|
for i, v := range dBrd {
|
|
if v.Value() == Two {
|
|
defender = defender + 1
|
|
}
|
|
if v.Value() == Three && (i == def-1 || i == def+1) {
|
|
defender = defender + 1
|
|
}
|
|
}
|
|
if attacker > defender {
|
|
dBrd[def] = nil
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.Scourge = dBrd
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.Sentinal = dBrd
|
|
}
|
|
return 0
|
|
}
|
|
if attacker == defender {
|
|
aBrd[atk] = nil
|
|
dBrd[def] = nil
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.Scourge = dBrd
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.Sentinal = dBrd
|
|
}
|
|
return 0
|
|
}
|
|
return -1
|
|
|
|
}
|