add targeting
This commit is contained in:
parent
b07d824804
commit
1d45984958
2
deck.go
2
deck.go
@ -32,7 +32,7 @@ func LoadDeck(owner int, cards []int) *Deck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ValidateDeck(cards []int) bool {
|
func ValidateDeck(cards []int) bool {
|
||||||
if len(cards) < 7 {
|
if len(cards) < 15 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, v := range cards {
|
for _, v := range cards {
|
||||||
|
64
game.go
64
game.go
@ -21,6 +21,8 @@ type Game struct {
|
|||||||
CardBuffer *Deck
|
CardBuffer *Deck
|
||||||
CanDraw bool
|
CanDraw bool
|
||||||
HasDrawn bool
|
HasDrawn bool
|
||||||
|
QueuedEffect *Effect
|
||||||
|
TargetReq TargetStatus
|
||||||
Status GameStatus
|
Status GameStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +41,8 @@ func NewGame(sentDeck []int, scoDeck []int) *Game {
|
|||||||
CardBuffer: DeckFromCards([]*Card{}),
|
CardBuffer: DeckFromCards([]*Card{}),
|
||||||
CanDraw: false,
|
CanDraw: false,
|
||||||
HasDrawn: false,
|
HasDrawn: false,
|
||||||
|
QueuedEffect: nil,
|
||||||
|
TargetReq: TargetNone,
|
||||||
Status: StatusLobby,
|
Status: StatusLobby,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +224,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
switch cmd_s[0] {
|
switch cmd_s[0] {
|
||||||
case "s":
|
case "s":
|
||||||
//scry: return scry options off top of deck
|
//scry: return scry options off top of deck
|
||||||
if !g.CanDraw {
|
if !g.CanDraw || g.QueuedEffect != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if g.CardBuffer.Size() <= 0 {
|
if g.CardBuffer.Size() <= 0 {
|
||||||
@ -229,7 +233,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
return g.CardBuffer
|
return g.CardBuffer
|
||||||
case "d":
|
case "d":
|
||||||
//draw: return player hand
|
//draw: return player hand
|
||||||
if !g.CanDraw {
|
if !g.CanDraw || g.QueuedEffect != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(cmd_s) != 2 || !g.CanDraw {
|
if len(cmd_s) != 2 || !g.CanDraw {
|
||||||
@ -261,7 +265,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
if len(cmd_s) != 3 {
|
if len(cmd_s) != 3 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !g.HasDrawn {
|
if !g.HasDrawn || g.QueuedEffect != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
x_i, err := strconv.Atoi(cmd_s[1])
|
x_i, err := strconv.Atoi(cmd_s[1])
|
||||||
@ -285,7 +289,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
if len(cmd_s) != 3 {
|
if len(cmd_s) != 3 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !g.HasDrawn {
|
if !g.HasDrawn || g.QueuedEffect != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
x_i, err := strconv.Atoi(cmd_s[1])
|
x_i, err := strconv.Atoi(cmd_s[1])
|
||||||
@ -333,12 +337,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
return DeckFromCards([]*Card{})
|
return DeckFromCards([]*Card{})
|
||||||
}
|
}
|
||||||
case "p":
|
case "p":
|
||||||
//play: return player boad or [] if invalid
|
//play: return player board or [] if invalid
|
||||||
if len(cmd_s) != 3 {
|
if len(cmd_s) != 3 {
|
||||||
fmt.Println("not enough arguments")
|
fmt.Println("not enough arguments")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !g.HasDrawn {
|
if !g.HasDrawn || !g.QueuedEffect != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
x_i, err := strconv.Atoi(cmd_s[1])
|
x_i, err := strconv.Atoi(cmd_s[1])
|
||||||
@ -368,6 +372,54 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
|||||||
fmt.Println("couldn't play")
|
fmt.Println("couldn't play")
|
||||||
return DeckFromCards([]*Card{})
|
return DeckFromCards([]*Card{})
|
||||||
}
|
}
|
||||||
|
case "t":
|
||||||
|
//target: apply queued effect to target,return affected board or nil
|
||||||
|
if len(cmd_s) != 3 {
|
||||||
|
fmt.Println("not enough arguments")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !g.HasDrawn || g.QueuedEffect == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
board, err := strconv.Atoi(cmd_s[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
pos, err := strconv.Atoi(cmd_s[2])
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if pos < 0 || pos >= 3 {
|
||||||
|
fmt.Println("board position out of bounds")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch g.TargetStatus {
|
||||||
|
case TargetSelf:
|
||||||
|
if board != g.CurrentTurn && g.GetBoard(board)[pos].Id != g.QueuedEffect.Owner {
|
||||||
|
fmt.Println("self target not on self")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case TargetOwn:
|
||||||
|
if board != g.CurrentTurn {
|
||||||
|
fmt.Println("own target not on own board")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case TargetOpp:
|
||||||
|
if board == g.CurrentTurn {
|
||||||
|
fmt.Println("opponent target not on oponents board")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case TargetNone:
|
||||||
|
fmt.Println("NoneTarget'd ability?")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
AddEffect(g.GetBoard(board)[pos], g.QueuedEffect)
|
||||||
|
g.QueuedEffect = nil
|
||||||
|
g.TargetStatus = TargetNone
|
||||||
|
return g.GetBoard(board)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Println("Invalid act command")
|
fmt.Println("Invalid act command")
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user