you can win the game now

This commit is contained in:
stryan 2021-07-22 13:43:28 -04:00
parent d05b670e23
commit 89c69d6037
3 changed files with 67 additions and 1 deletions

View File

@ -26,6 +26,24 @@ func (b *Board) GetRow(id int) []Card {
}
}
func (b *Board) Empty(id int) bool {
res := true
if id == SentinalID {
for _, v := range b.Sentinal {
if !v.Empty() {
res = false
}
}
} else {
for _, v := range b.Scourge {
if !v.Empty() {
res = false
}
}
}
return res
}
func (b *Board) Move(id, src, dest int) bool {
var brd [4]Card
if id == 1 {

40
game.go
View File

@ -15,6 +15,7 @@ const (
StatusStop
StatusSentinalWin
StatusScourgeWin
StatusDraw
)
const (
@ -63,6 +64,17 @@ func (g *Game) String() string {
}
func (g *Game) Parse(cmd *Command) *CommandResult {
if g.Status != StatusLobby || g.Status != StatusReady || g.Status != StatusPlaying {
return &CommandResult{
PlayerID: cmd.PlayerID,
ResultType: cmd.Type,
StateResult: NewView(cmd.PlayerID, g),
ActionResult: nil,
DebugResult: g,
}
}
var state_res *GameView
var action_res []Card
var debug_res *Game
@ -78,6 +90,7 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
debug_res = g
res_type = DebugCmd
}
g.StateChanges()
return &CommandResult{
PlayerID: cmd.PlayerID,
ResultType: res_type,
@ -87,6 +100,33 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
}
}
func (g *Game) StateChanges() {
//check for no actions first
if len(g.SentinalPlayer.Hand) == 0 && g.SentinalDeck.Size() == 0 {
if g.GameBoard.Empty(SentinalID) {
g.Status = StatusScourgeWin
}
}
if len(g.ScourgePlayer.Hand) == 0 && g.ScourgeDeck.Size() == 0 {
if g.GameBoard.Empty(ScourgeID) {
g.Status = StatusSentinalWin
}
}
//check life
//this is second on purpose so that it shadows deck out win conditions
//if you use your last action to win the game, you should actually win
if g.SentinalPlayer.Life < 0 {
g.Status = StatusScourgeWin
}
if g.ScourgePlayer.Life < 0 {
g.Status = StatusSentinalWin
}
if g.ScourgePlayer.Life < 0 && g.SentinalPlayer.Life < 0 {
g.Status = StatusDraw
}
}
func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
switch cmd {
case "g":

10
main.go
View File

@ -7,7 +7,16 @@ import (
"strings"
)
const DEBUG = true
func main() {
if DEBUG {
local()
}
}
func local() {
reader := bufio.NewReader(os.Stdin)
g := NewGame()
@ -54,5 +63,4 @@ func main() {
fmt.Println(err)
}
}
}