Преглед на файлове

Initial work on PlayCards.

Steve Thielemann преди 3 години
родител
ревизия
aaba545ce9
променени са 2 файла, в които са добавени 95 реда и са изтрити 6 реда
  1. 75 0
      playcards.go
  2. 20 6
      space-ace.go

+ 75 - 0
playcards.go

@@ -0,0 +1,75 @@
+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          []int64
+	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
+}
+
+// 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.Itoa(int(pc.Play_day_t)))
+		pc.DB.SetSetting("days_played", "0")
+		pc.Days_played = 0
+	}
+
+	pc.Seeds = make([]int64, 0)
+
+	// config _seed
+	parts := strings.Split((*pc.Config)["_seed"], ",")
+	for _, seed := range parts {
+		i, _ := strconv.ParseInt(seed, 10, 64)
+		pc.Seeds = append(pc.Seeds, i)
+	}
+
+}

+ 20 - 6
space-ace.go

@@ -317,7 +317,7 @@ func init() {
 		"All", "Brown", "Green", "Red", "Blue", "Cyan", "Magenta", "White"}
 		"All", "Brown", "Green", "Red", "Blue", "Cyan", "Magenta", "White"}
 }
 }
 
 
-func DeckColorMenu() door.Menu {
+func DeckColorMenu(current string) door.Menu {
 	m := door.Menu{Panel: door.Panel{Width: 31,
 	m := door.Menu{Panel: door.Panel{Width: 31,
 		X:           5,
 		X:           5,
 		Y:           5,
 		Y:           5,
@@ -350,8 +350,12 @@ func DeckColorMenu() door.Menu {
 		door.ColorText("BOLD WHI ON BLUE"),
 		door.ColorText("BOLD WHI ON BLUE"),
 		unselectMap)
 		unselectMap)
 
 
-	for _, color := range DeckColors {
+	m.Chosen = 0
+	for idx, color := range DeckColors {
 		m.AddSelection(color[:1], color)
 		m.AddSelection(color[:1], color)
+		if color == current {
+			m.Chosen = idx
+		}
 	}
 	}
 	return m
 	return m
 }
 }
@@ -410,9 +414,13 @@ func Configure(d *door.Door, db *DBData) {
 		switch option {
 		switch option {
 		case 'D':
 		case 'D':
 			// Deck color
 			// Deck color
-			colormenu := DeckColorMenu()
+			current_color := db.GetSetting("DeckColor", "All")
+			colormenu := DeckColorMenu(current_color)
 			d.Write(door.Clrscr)
 			d.Write(door.Clrscr)
-			_ = colormenu.Choose(d)
+			c := colormenu.Choose(d)
+			if c > 0 {
+				db.SetSetting("DeckColor", DeckColors[c-1])
+			}
 			press_a_key(d)
 			press_a_key(d)
 		case 'V':
 		case 'V':
 			// View settings
 			// View settings
@@ -436,6 +444,9 @@ func Help() door.Panel {
 		DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
 		DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
 	help.Lines = append(help.Lines, help.Spacer())
 	help.Lines = append(help.Lines, help.Spacer())
 	copyright := fmt.Sprintf("Space-Ace (C) 2022 Red Green Software")
 	copyright := fmt.Sprintf("Space-Ace (C) 2022 Red Green Software")
+	if door.Unicode {
+		copyright = strings.Replace(copyright, "(C)", "\u00a9", -1)
+	}
 	help.Lines = append(help.Lines,
 	help.Lines = append(help.Lines,
 		door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
 		door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
@@ -471,6 +482,9 @@ func About() door.Panel {
 		DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
 		DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
 	about.Lines = append(about.Lines, about.Spacer())
 	about.Lines = append(about.Lines, about.Spacer())
 	copyright := fmt.Sprintf("Space-Ace (C) 2022 Red Green Software")
 	copyright := fmt.Sprintf("Space-Ace (C) 2022 Red Green Software")
+	if door.Unicode {
+		copyright = strings.Replace(copyright, "(C)", "\u00a9", -1)
+	}
 	about.Lines = append(about.Lines,
 	about.Lines = append(about.Lines,
 		door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
 		door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
@@ -478,8 +492,8 @@ func About() door.Panel {
 		"This door was written by Bugz.",
 		"This door was written by Bugz.",
 		"",
 		"",
 		"It is written in Go, understands CP437 and unicode, adapts",
 		"It is written in Go, understands CP437 and unicode, adapts",
-		"to screen sizes, uses door32.sys, and runs on Linux and",
-		"Windows."} {
+		"to screen sizes, uses door32.sys, supports TheDraw Fonts,",
+		"and runs on Linux and Windows."} {
 		about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, text)})
 		about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, text)})
 	}
 	}
 	return about
 	return about