瀏覽代碼

Ported more code over.

Steve Thielemann 3 年之前
父節點
當前提交
c408ad187a
共有 2 個文件被更改,包括 70 次插入0 次删除
  1. 66 0
      deck.go
  2. 4 0
      playcards.go

+ 66 - 0
deck.go

@@ -11,6 +11,14 @@ type Deck struct {
 	Mark  []door.Panel
 }
 
+func (d *Deck) SetBackColor(color string) {
+	for x := 0; x < 5; x++ {
+		for idx, _ := range d.Backs[x].Lines {
+			d.Backs[x].Lines[idx].DefaultColor = color
+		}
+	}
+}
+
 func (d *Deck) Init() {
 	d.Cards = make([]door.Panel, 52)
 	for x := 0; x < 52; x++ {
@@ -174,3 +182,61 @@ func GetSuit(c int) int {
 func GetDeck(c int) int {
 	return c / 52
 }
+
+type CardPair struct {
+	card1 int
+	card2 int
+}
+
+var blocks []CardPair
+
+func init() {
+	blocks = []CardPair{
+		CardPair{3, 4},
+		CardPair{5, 6},
+		CardPair{7, 8},
+		CardPair{9, 10},
+		CardPair{10, 11},
+		CardPair{12, 13},
+		CardPair{13, 14},
+		CardPair{15, 16},
+		CardPair{16, 17},
+		CardPair{18, 19},
+		CardPair{19, 20},
+		CardPair{20, 21},
+		CardPair{21, 22},
+		CardPair{22, 23},
+		CardPair{23, 24},
+		CardPair{24, 25},
+		CardPair{25, 26},
+		CardPair{26, 27},
+	}
+}
+
+// Which card(s) are unblocked by this card?
+func Unblocks(card int) []int {
+	var result []int
+	for idx := range blocks {
+		if blocks[idx].card1 == card || blocks[idx].card2 == card {
+			result = append(result, idx)
+		}
+	}
+	return result
+}
+
+func CanPlay(card1 int, card2 int) bool {
+	rank1 := GetRank(card1)
+	rank2 := GetRank(card2)
+
+	if (rank1+1)%13 == rank2 {
+		return true
+	}
+
+	if rank1 == 0 {
+		rank1 += 13
+	}
+	if rank1-1 == rank2 {
+		return true
+	}
+	return false
+}

+ 4 - 0
playcards.go

@@ -142,6 +142,7 @@ type PlayCards struct {
 	CmdPanel         door.Panel
 	NextQuitPanel    door.Panel
 	Calendar         door.Panel
+	DeckPanel        Deck
 }
 
 // Adjust date to 2:00 AM
@@ -218,6 +219,8 @@ func (pc *PlayCards) Init() {
 	NormalizeDate(&pc.Play_day)
 	pc.Play_day_t = pc.Play_day.Unix()
 
+	pc.DeckPanel.Init()
+
 	var last_played int64
 	last := pc.DB.GetSetting("last_played", "0")
 	last_played, _ = strconv.ParseInt(last, 10, 64)
@@ -566,6 +569,7 @@ func (pc *PlayCards) PlayCards() int {
 	off_y += 3
 
 	currentDefault := pc.DB.GetSetting("DeckColor", "ALL")
+	deck_color := StringToANSIColor(currentDefault)
 
 	return 0
 }