From 08a3559c992578a7f881df722acc50997624d197 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 25 Jul 2021 22:53:40 -0400 Subject: [PATCH] argument safety, reset card effect stacks on tick --- internal/game/board.go | 5 ++++- internal/game/game.go | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/internal/game/board.go b/internal/game/board.go index f3ca276..df7e9ff 100644 --- a/internal/game/board.go +++ b/internal/game/board.go @@ -78,6 +78,7 @@ func (b *Board) CanMove(id, src, dest int) bool { func (b *Board) Move(id, src, dest int) bool { brd := b.GetRow(id) brd[dest] = brd[src] + brd[dest].Position = dest brd[src] = NewEmpty(src) return true } @@ -96,8 +97,8 @@ func (b *Board) CanPlay(id int, c *Card, dest int) bool { func (b *Board) Play(id int, c *Card, dest int, should bool) bool { brd := b.GetRow(id) if should { - brd[dest] = c c.Position = dest + brd[dest] = c } else { return false } @@ -150,8 +151,10 @@ func (b *Board) Attack(id, atk, def int) int { func (b *Board) ResetCards() { for _, v := range b.Sentinal { v.Power = v.BasePower + v.Effects = []Effect{} } for _, v := range b.Scourge { v.Power = v.BasePower + v.Effects = []Effect{} } } diff --git a/internal/game/game.go b/internal/game/game.go index e96b5d1..c40b45c 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -248,12 +248,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { return DeckFromCards(curr.Hand) } x_i, err := strconv.Atoi(cmd_s[1]) - if x_i > 2 || x_i < 0 { - return nil - } if err != nil { panic(err) } + if x_i > 2 || x_i < 0 { + return nil + } x := g.CardBuffer.Cards[x_i] buf := g.CardBuffer for i, v := range buf.Cards { @@ -275,8 +275,15 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { if !g.HasDrawn { return nil } - x_i, _ := strconv.Atoi(cmd_s[1]) - y_i, _ := strconv.Atoi(cmd_s[2]) + x_i, err := strconv.Atoi(cmd_s[1]) + if err != nil { + log.Println(err) + return nil + } + y_i, err := strconv.Atoi(cmd_s[2]) + if err != nil { + log.Println(err) + } if g.GameBoard.CanMove(g.CurrentTurn, x_i, y_i) { OracleMove(g.GameBoard.GetCard(g.CurrentTurn, x_i), x_i, y_i, g) g.GameBoard.Move(g.CurrentTurn, x_i, y_i) @@ -292,8 +299,16 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { if !g.HasDrawn { return nil } - x_i, _ := strconv.Atoi(cmd_s[1]) - y_i, _ := strconv.Atoi(cmd_s[2]) + x_i, err := strconv.Atoi(cmd_s[1]) + if err != nil { + log.Println(err) + return nil + } + y_i, err := strconv.Atoi(cmd_s[2]) + if err != nil { + log.Println(err) + return nil + } if g.GameBoard.CanAttack(g.CurrentTurn, x_i, y_i) { OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g) res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i) @@ -338,8 +353,16 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { if !g.HasDrawn { return nil } - x_i, _ := strconv.Atoi(cmd_s[1]) - y_i, _ := strconv.Atoi(cmd_s[2]) + x_i, err := strconv.Atoi(cmd_s[1]) + if err != nil { + log.Println(err) + return nil + } + y_i, err := strconv.Atoi(cmd_s[2]) + if err != nil { + log.Println(err) + return nil + } card := curr.Hand[x_i] shouldPlace := true if g.GameBoard.CanPlay(g.CurrentTurn, card, y_i) {