diff --git a/src/entity/curernt.go b/src/entity/curernt.go index 67aac6a..17c48b7 100644 --- a/src/entity/curernt.go +++ b/src/entity/curernt.go @@ -1,6 +1,7 @@ package entity type Current struct { - Bet Currency - Turn int + Bet Currency + Turn int + Phase int } diff --git a/src/game/rule/rule.go b/src/game/rule/rule.go index cdc121a..5518baa 100644 --- a/src/game/rule/rule.go +++ b/src/game/rule/rule.go @@ -1,8 +1,40 @@ package rule +import "local/sandbox/cards/src/entity" + type Rule struct { Ends []End Phases []Phase Hands []Hand Deck Deck } + +func (rule Rule) ShouldEnd(game *entity.Game) bool { + if game == nil { + return false + } + if game.Current.Phase >= len(rule.Phases) { + return true + } + for _, end := range rule.Ends { + if _, ok := end(game); ok { + return true + } + } + return false +} + +func (rule Rule) AdvancedPhase(game *entity.Game) bool { + if game == nil { + return false + } + if rule.ShouldEnd(game) { + game.Current.Phase = len(rule.Phases) + return true + } + if ok := rule.Phases[game.Current.Phase]; ok { + game.Current.Phase += 1 + return true + } + return false +}