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