From d8777b0dda77bf847a13ed53a60329dcca68c211 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 26 Jul 2021 14:19:05 -0400 Subject: [PATCH] maybe don't give sentinal scourges deck huh --- internal/game/deck.go | 9 ++++----- internal/game/effect.go | 3 +++ internal/game/game.go | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/internal/game/deck.go b/internal/game/deck.go index ff90427..19aaee4 100644 --- a/internal/game/deck.go +++ b/internal/game/deck.go @@ -20,12 +20,13 @@ func (d *Deck) String() string { } func NewDeck(owner int) *Deck { - cards := []*Card{NewCard(0, owner, -1, uuid.Nil)} + cards := []*Card{} for i := 0; i < 3; i++ { for j := 1; j < 9; j++ { cards = append(cards, NewCard(j, owner, -1, uuid.Nil)) } } + cards = append(cards, NewCard(0, owner, -1, uuid.Nil)) return &Deck{ Cards: cards, } @@ -38,13 +39,11 @@ func DeckFromCards(c []*Card) *Deck { } func (d *Deck) Shuffle() { - cards := d.Cards r := rand.New(rand.NewSource(time.Now().UnixNano())) - for i := range cards { + for i := range d.Cards { j := r.Intn(i + 1) - cards[i], cards[j] = cards[j], cards[i] + d.Cards[i], d.Cards[j] = d.Cards[j], d.Cards[i] } - d.Cards = cards } func (d *Deck) Scry(s int) []*Card { diff --git a/internal/game/effect.go b/internal/game/effect.go index a236bf4..904fbb6 100644 --- a/internal/game/effect.go +++ b/internal/game/effect.go @@ -28,6 +28,9 @@ func AddEffect(c *Card, e *Effect) { log.Println("Can't add effect to empty card") return } + if c.Position < 0 { + log.Println("trying to apply effect to card not on the board") + } for _, v := range c.Effects { if v.Owner == e.Owner && v.ID == e.ID && v.Target == e.Target { log.Println("can't stack effects") diff --git a/internal/game/game.go b/internal/game/game.go index 22664fc..10d64f5 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -151,6 +151,8 @@ func (g *Game) StateChanges() { func (g *Game) PlayerStateAct(id int, cmd string) *GameView { switch cmd { + case "d": + Debug(g) case "g": //game state return NewView(id, g) @@ -160,8 +162,9 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView { //TODO check for ready on both accounts first g.SentinalPlayer.Hand = g.SentinalDeck.Cards[len(g.SentinalDeck.Cards)-5 : len(g.SentinalDeck.Cards)] g.SentinalDeck.Cards = g.SentinalDeck.Cards[0 : len(g.SentinalDeck.Cards)-5] + g.ScourgePlayer.Hand = g.ScourgeDeck.Cards[len(g.ScourgeDeck.Cards)-5 : len(g.ScourgeDeck.Cards)] - g.SentinalDeck.Cards = g.ScourgeDeck.Cards[0 : len(g.ScourgeDeck.Cards)-5] + g.ScourgeDeck.Cards = g.ScourgeDeck.Cards[0 : len(g.ScourgeDeck.Cards)-5] case "s": //start turn if g.Status == StatusReady { //first turn @@ -255,13 +258,11 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { return nil } x := g.CardBuffer.Cards[x_i] - buf := g.CardBuffer - for i, v := range buf.Cards { - if v == x { - buf.Cards = append(buf.Cards[:i], buf.Cards[i+1:]...) - } + if x.Owner != g.CurrentTurn { + log.Println("drew a card from our deck that isn't our own") } - currD.Bottom(buf.Cards) + g.CardBuffer.Cards = append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...) + currD.Bottom(g.CardBuffer.Cards) curr.Hand = append(curr.Hand, x) g.CanDraw = false g.HasDrawn = true @@ -363,6 +364,9 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { log.Println(err) return nil } + if x_i < 0 || x_i > len(curr.Hand) { + return nil + } card := curr.Hand[x_i] shouldPlace := true if g.GameBoard.CanPlay(g.CurrentTurn, card, y_i) { @@ -383,3 +387,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { } return nil } + +func Debug(g *Game) { + return +}