have to draw first, start moving past debug

This commit is contained in:
stryan 2021-07-22 12:44:25 -04:00
parent 88d2211c36
commit b24a69ac7e
6 changed files with 99 additions and 18 deletions

View File

@ -3,8 +3,8 @@ package main
import "fmt" import "fmt"
type Board struct { type Board struct {
Sentinal [4]Card Sentinal [4]Card `json:"sentinal"`
Scourge [4]Card Scourge [4]Card `json:"scourge"`
} }
func NewBoard() *Board { func NewBoard() *Board {

14
cmd.go Normal file
View File

@ -0,0 +1,14 @@
package main
type CmdType string
const (
ActCmd = "a"
StateCmd = "s"
)
type Command struct {
PlayerID int `json:"player_id"`
Type CmdType `json:"type"`
Cmd string `json:"cmd"`
}

View File

@ -6,7 +6,7 @@ import (
) )
type Deck struct { type Deck struct {
Cards []Card Cards []Card `json:"cards"`
} }
func NewDeck() *Deck { func NewDeck() *Deck {
@ -46,3 +46,7 @@ func (d *Deck) Scry(s int) []Card {
func (d *Deck) Bottom(result []Card) { func (d *Deck) Bottom(result []Card) {
d.Cards = append(result, d.Cards...) //Should shuffle result first? d.Cards = append(result, d.Cards...) //Should shuffle result first?
} }
func (d *Deck) Size() int {
return len(d.Cards)
}

43
game.go
View File

@ -13,6 +13,13 @@ const (
StatusReady StatusReady
StatusPlaying StatusPlaying
StatusStop StatusStop
StatusSentinalWin
StatusScourgeWin
)
const (
SentinalID = 1
ScourgeID = 2
) )
func (g GameStatus) String() string { func (g GameStatus) String() string {
@ -28,6 +35,7 @@ type Game struct {
CurrentTurn int CurrentTurn int
CardBuffer []Card CardBuffer []Card
CanDraw bool CanDraw bool
HasDrawn bool
Status GameStatus Status GameStatus
} }
@ -38,13 +46,14 @@ func NewGame() *Game {
deckB.Shuffle() deckB.Shuffle()
return &Game{ return &Game{
GameBoard: NewBoard(), GameBoard: NewBoard(),
SentinalPlayer: NewPlayer("Sentinal", 1), SentinalPlayer: NewPlayer("Sentinal", SentinalID),
ScourgePlayer: NewPlayer("Scourge", 2), ScourgePlayer: NewPlayer("Scourge", ScourgeID),
SentinalDeck: deckA, SentinalDeck: deckA,
ScourgeDeck: deckB, ScourgeDeck: deckB,
CurrentTurn: 0, //start with no turn CurrentTurn: 0, //start with no turn
CardBuffer: []Card{}, CardBuffer: []Card{},
CanDraw: false, CanDraw: false,
HasDrawn: false,
Status: StatusLobby, Status: StatusLobby,
} }
} }
@ -60,7 +69,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
return g return g
case "g": case "g":
//game state //game state
if id == 1 { if id == SentinalID {
return &Game{ return &Game{
GameBoard: g.GameBoard, GameBoard: g.GameBoard,
SentinalPlayer: g.SentinalPlayer, SentinalPlayer: g.SentinalPlayer,
@ -70,6 +79,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
CurrentTurn: g.CurrentTurn, CurrentTurn: g.CurrentTurn,
CardBuffer: nil, CardBuffer: nil,
CanDraw: g.CanDraw, CanDraw: g.CanDraw,
HasDrawn: g.HasDrawn,
Status: g.Status, Status: g.Status,
} }
} else { } else {
@ -82,6 +92,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
CurrentTurn: g.CurrentTurn, CurrentTurn: g.CurrentTurn,
CardBuffer: nil, CardBuffer: nil,
CanDraw: g.CanDraw, CanDraw: g.CanDraw,
HasDrawn: g.HasDrawn,
Status: g.Status, Status: g.Status,
} }
} }
@ -94,20 +105,21 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
g.ScourgePlayer.Hand = g.ScourgeDeck.Cards[len(g.ScourgeDeck.Cards)-5 : len(g.ScourgeDeck.Cards)] 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.SentinalDeck.Cards = g.ScourgeDeck.Cards[0 : len(g.ScourgeDeck.Cards)-5]
return g return g
case "s": case "s":
//start turn //start turn
if g.Status == StatusReady { if g.Status == StatusReady { //first turn
g.Status = StatusPlaying g.Status = StatusPlaying
g.CurrentTurn = id g.CurrentTurn = id
g.CanDraw = false g.CanDraw = false
g.HasDrawn = false
} else { } else {
g.CanDraw = true g.CanDraw = true
g.HasDrawn = false
} }
if id != g.CurrentTurn { if id != g.CurrentTurn {
return nil return nil
} }
if id == 1 { if id == SentinalID {
for _, v := range g.GameBoard.Sentinal { for _, v := range g.GameBoard.Sentinal {
v.Upkeep(g) v.Upkeep(g)
} }
@ -123,7 +135,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
return nil return nil
} }
g.CardBuffer = []Card{} g.CardBuffer = []Card{}
if id == 1 { if id == SentinalID {
for _, v := range g.GameBoard.Sentinal { for _, v := range g.GameBoard.Sentinal {
v.Endstep(g) v.Endstep(g)
} }
@ -132,10 +144,10 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
v.Endstep(g) v.Endstep(g)
} }
} }
if g.CurrentTurn == 1 { if g.CurrentTurn == SentinalID {
g.CurrentTurn = 2 g.CurrentTurn = ScourgeID
} else { } else {
g.CurrentTurn = 1 g.CurrentTurn = SentinalID
} }
return g return g
} }
@ -193,6 +205,7 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
currD.Bottom(buf) currD.Bottom(buf)
curr.Hand = append(curr.Hand, x) curr.Hand = append(curr.Hand, x)
g.CanDraw = false g.CanDraw = false
g.HasDrawn = true
return curr.Hand return curr.Hand
case "m": case "m":
@ -200,6 +213,9 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
if len(cmd_s) != 3 { if len(cmd_s) != 3 {
return nil return nil
} }
if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1]) x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2]) y_i, _ := strconv.Atoi(cmd_s[2])
res := g.GameBoard.Move(g.CurrentTurn, x_i, y_i) res := g.GameBoard.Move(g.CurrentTurn, x_i, y_i)
@ -213,6 +229,9 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
if len(cmd_s) != 3 { if len(cmd_s) != 3 {
return nil return nil
} }
if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1]) x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2]) y_i, _ := strconv.Atoi(cmd_s[2])
res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i) res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i)
@ -231,7 +250,9 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
fmt.Println("not enough arguments") fmt.Println("not enough arguments")
return nil return nil
} }
fmt.Println("playing") if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1]) x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2]) y_i, _ := strconv.Atoi(cmd_s[2])
card := curr.Hand[x_i] card := curr.Hand[x_i]

42
game_view.go Normal file
View File

@ -0,0 +1,42 @@
package main
type GameView struct {
Board *Board `json:"board"`
Player *Player `json:"player"`
Deck *Deck `json:"deck"`
EnemyDeckSize int `json:"enemy_deck_size"`
EnemyHandSize int `json:"enemy_hand_size"`
CurrentTurn int `json:"current_turn"`
CanDraw bool `json:"can_draw"`
HasDrawn bool `json:"has_drawn"`
Status GameStatus `json:"game_status"`
}
func NewView(id int, g *Game) *GameView {
if id == SentinalID {
return &GameView{
Board: g.GameBoard,
Player: g.SentinalPlayer,
Deck: g.SentinalDeck,
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,
Deck: g.ScourgeDeck,
EnemyDeckSize: g.SentinalDeck.Size(),
EnemyHandSize: len(g.SentinalPlayer.Hand),
CurrentTurn: g.CurrentTurn,
CanDraw: g.CanDraw,
HasDrawn: g.HasDrawn,
Status: g.Status,
}
}
}

View File

@ -1,10 +1,10 @@
package main package main
type Player struct { type Player struct {
Name string Name string `json:"name"`
Id int Id int `json:"id"`
Hand []Card Hand []Card `json:"hand"`
Life int Life int `json:"life"`
} }
func NewPlayer(name string, id int) *Player { func NewPlayer(name string, id int) *Player {