this logic got cray cray
parent
a26c1a0043
commit
c4f9ad600d
|
|
@ -1,6 +1,7 @@
|
||||||
package entity
|
package entity
|
||||||
|
|
||||||
type Current struct {
|
type Current struct {
|
||||||
Bet Currency
|
Bet Currency
|
||||||
Turn int
|
Turn int
|
||||||
|
Phase int
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,40 @@
|
||||||
package rule
|
package rule
|
||||||
|
|
||||||
|
import "local/sandbox/cards/src/entity"
|
||||||
|
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
Ends []End
|
Ends []End
|
||||||
Phases []Phase
|
Phases []Phase
|
||||||
Hands []Hand
|
Hands []Hand
|
||||||
Deck Deck
|
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