this logic got cray cray
parent
a26c1a0043
commit
8c2510d837
|
|
@ -1,6 +1,7 @@
|
|||
package entity
|
||||
|
||||
type Current struct {
|
||||
Bet Currency
|
||||
Turn int
|
||||
Bet Currency
|
||||
Turn int
|
||||
Phase int
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue