start using util functions

This commit is contained in:
stryan 2021-10-07 13:29:51 -04:00
parent 82d2afa3fa
commit 66fb3cc777

82
game.go
View File

@ -168,10 +168,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
g.Status = StatusPlaying g.Status = StatusPlaying
} }
//skip draw step when 0 life //skip draw step when 0 life
if id == SentinalID && g.SentinalPlayer.Life <= 0 { if g.GetPlayer(id).Life <= 0 {
g.CanDraw = false
g.HasDrawn = true
} else if id == ScourgeID && g.ScourgePlayer.Life <= 0 {
g.CanDraw = false g.CanDraw = false
g.HasDrawn = true g.HasDrawn = true
} else { } else {
@ -181,14 +178,8 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
if id != g.CurrentTurn { if id != g.CurrentTurn {
return nil return nil
} }
if id == SentinalID { for _, v := range g.GetBoard(id) {
for _, v := range g.GameBoard.Sentinal { OracleUpkeep(v, g)
OracleUpkeep(v, g)
}
} else {
for _, v := range g.GameBoard.Scourge {
OracleUpkeep(v, g)
}
} }
case "e": case "e":
//end turn and clean up //end turn and clean up
@ -196,14 +187,8 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
return nil return nil
} }
g.CardBuffer = DeckFromCards([]*Card{}) g.CardBuffer = DeckFromCards([]*Card{})
if id == SentinalID { for _, v := range g.GetBoard(id) {
for _, v := range g.GameBoard.Sentinal { OracleEndstep(v, g)
OracleEndstep(v, g)
}
} else {
for _, v := range g.GameBoard.Scourge {
OracleEndstep(v, g)
}
} }
if g.CurrentTurn == SentinalID { if g.CurrentTurn == SentinalID {
g.CurrentTurn = ScourgeID g.CurrentTurn = ScourgeID
@ -221,15 +206,9 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
var curr *Player var curr *Player
var opp *Player var opp *Player
var currD *Deck var currD *Deck
if id == g.SentinalPlayer.Id { curr = g.GetPlayer(id)
curr = g.SentinalPlayer opp = g.GetOpponent(id)
opp = g.ScourgePlayer currD = g.GetDeck(id)
currD = g.SentinalDeck
} else {
curr = g.ScourgePlayer
opp = g.SentinalPlayer
currD = g.ScourgeDeck
}
cmd_s := strings.Split(cmd, " ") cmd_s := strings.Split(cmd, " ")
if len(cmd_s) < 1 { if len(cmd_s) < 1 {
return nil return nil
@ -319,15 +298,10 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g) OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g)
res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i) res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i)
var aid, did int var aid, did int
if id == SentinalID { aid = g.GetPlayer(id).Id
aid = SentinalID did = g.GetOpponent(id).Id
did = ScourgeID attacker := g.GetBoard(aid)[x_i]
} else { defender := g.GetBoard(did)[y_i]
aid = ScourgeID
did = SentinalID
}
attacker := g.GameBoard.GetRow(aid)[x_i]
defender := g.GameBoard.GetRow(did)[y_i]
switch res { switch res {
case 1: case 1:
opp.Life = opp.Life - 1 opp.Life = opp.Life - 1
@ -396,3 +370,35 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
func Debug(g *Game) { func Debug(g *Game) {
return return
} }
func (g *Game) GetPlayer(id int) *Player {
if id == SentinalID {
return g.SentinalPlayer
} else if id == ScourgeID {
return g.ScourgePlayer
} else {
return nil
}
}
func (g *Game) GetOpponent(id int) *Player {
if id == SentinalID {
return g.ScourgePlayer
} else if id == ScourgeID {
return g.SentinalPlayer
} else {
return nil
}
}
func (g *Game) GetDeck(id int) *Deck {
if id == SentinalID {
return g.SentinalDeck
} else if id == ScourgeID {
return g.ScourgeDeck
} else {
return nil
}
}
func (g *Game) GetBoard(id int) []*Card {
return g.GameBoard.GetRow(id)
}