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) {