123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package main
- import (
- "math/rand"
- "red-green/door"
- "strconv"
- "strings"
- "time"
- )
- type PlayCards struct {
- Door *door.Door
- DB *DBData
- Config *map[string]string
- RNG *rand.Rand
- Seeds []int32
- Total_hands int
- Play_card int
- Current_streak int
- Best_streak int
- Select_card int
- Score int
- Play_day time.Time
- Play_day_t int64
- Days_played int
- Hand int
- }
- // Adjust date to 2:00 AM
- func NormalizeDate(date *time.Time) {
- offset := time.Duration(date.Second())*time.Second +
- time.Duration(date.Minute())*time.Minute +
- time.Duration(date.Hour()-2)*time.Hour +
- time.Duration(date.Nanosecond())*time.Nanosecond
- *date = date.Add(-offset)
- }
- func (pc *PlayCards) Init() {
- // init_values()
- hands := pc.DB.GetSetting("hands_per_day", "3")
- pc.Total_hands, _ = strconv.Atoi(hands)
- pc.Play_card = 28
- pc.Current_streak = 0
- pc.Best_streak = 0
- best := pc.DB.GetSetting("best_streak", "0")
- pc.Best_streak, _ = strconv.Atoi(best)
- pc.Select_card = 23
- pc.Score = 0
- // PlayCards::PlayCards()
- pc.Play_day = time.Now()
- NormalizeDate(&pc.Play_day)
- pc.Play_day_t = pc.Play_day.Unix()
- var last_played int64
- last := pc.DB.GetSetting("last_played", "0")
- last_played, _ = strconv.ParseInt(last, 10, 64)
- days := pc.DB.GetSetting("days_played", "0")
- pc.Days_played, _ = strconv.Atoi(days)
- if last_played != pc.Play_day_t {
- pc.DB.SetSetting("last_played", strconv.FormatInt(pc.Play_day_t, 10))
- pc.DB.SetSetting("days_played", "0")
- pc.Days_played = 0
- }
- pc.Seeds = make([]int32, 0)
- // config _seed
- parts := strings.Split((*pc.Config)["_seed"], ",")
- for _, seed := range parts {
- i, _ := strconv.ParseInt(seed, 10, 32)
- pc.Seeds = append(pc.Seeds, int32(i))
- }
- pc.Hand = 0
- pc.Total_hands = 0
- // Panels ?
- }
|