From 1606a2953be37654bb4841d95ab6bdc4f73bdcae Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 7 Oct 2021 13:32:47 -0400 Subject: [PATCH] more util methods --- game.go | 10 +++++++++- game_view.go | 38 +++++++++++--------------------------- oracle.go | 6 +++--- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/game.go b/game.go index 170279d..802e618 100644 --- a/game.go +++ b/game.go @@ -398,7 +398,15 @@ func (g *Game) GetDeck(id int) *Deck { return nil } } - +func (g *Game) GetOpponentDeck(id int) *Deck { + if id == SentinalID { + return g.ScourgeDeck + } else if id == ScourgeID { + return g.SentinalDeck + } else { + return nil + } +} func (g *Game) GetBoard(id int) []*Card { return g.GameBoard.GetRow(id) } diff --git a/game_view.go b/game_view.go index b29abbf..dc4cff3 100644 --- a/game_view.go +++ b/game_view.go @@ -5,32 +5,16 @@ import ( ) func NewView(id int, g *Game) *GameView { - if id == SentinalID { - return &GameView{ - Board: g.GameBoard, - Player: g.SentinalPlayer, - DeckSize: g.SentinalDeck.Size(), - EnemyLife: g.ScourgePlayer.Life, - EnemyDeckSize: g.ScourgeDeck.Size(), - EnemyHandSize: len(g.ScourgePlayer.Hand), - CurrentTurn: g.CurrentTurn, - CanDraw: g.CanDraw, - HasDrawn: g.HasDrawn, - Status: g.Status, - } - } else { - return &GameView{ - Board: g.GameBoard, - Player: g.ScourgePlayer, - DeckSize: g.ScourgeDeck.Size(), - EnemyLife: g.SentinalPlayer.Life, - EnemyDeckSize: g.SentinalDeck.Size(), - EnemyHandSize: len(g.SentinalPlayer.Hand), - CurrentTurn: g.CurrentTurn, - CanDraw: g.CanDraw, - HasDrawn: g.HasDrawn, - Status: g.Status, - } - + return &GameView{ + Board: g.GameBoard, + Player: g.GetPlayer(id), + DeckSize: g.GetDeck(id).Size(), + EnemyLife: g.GetOpponent(id).Life, + EnemyDeckSize: g.GetOpponentDeck(id).Size(), + EnemyHandSize: len(g.GetOpponent(id).Hand), + CurrentTurn: g.CurrentTurn, + CanDraw: g.CanDraw, + HasDrawn: g.HasDrawn, + Status: g.Status, } } diff --git a/oracle.go b/oracle.go index d24bc0e..61fcbbb 100644 --- a/oracle.go +++ b/oracle.go @@ -55,7 +55,7 @@ func OracleTick(c *Card, g *Game) { if c.Type == EmptyValue { return } - row := g.GameBoard.GetRow(c.Owner) + row := g.GetBoard(c.Owner) switch c.Type { case Two: @@ -80,7 +80,7 @@ func OracleLeaves(c *Card, g *Game) { if c.Empty() { return } - row := g.GameBoard.GetRow(c.Owner) + row := g.GetBoard(c.Owner) switch c.Type { case Two: //remove +1 to all @@ -116,7 +116,7 @@ func OracleMove(c *Card, src, dest int, g *Game) { c.Sick = true switch c.Type { case Three: - row := g.GameBoard.GetRow(c.Owner) + row := g.GetBoard(c.Owner) if src-1 >= 0 { RemoveEffect(c.Id, row[src-1]) }