package main import ( "red-green/door" "strings" ) type Deck struct { Cards []door.Panel Backs []door.Panel Mark []door.Panel } func (d *Deck) Init() { d.Cards = make([]door.Panel, 52) for x := 0; x < 52; x++ { d.Cards[x] = CardOf(x) } d.Backs = make([]door.Panel, 5) for x := 0; x < 5; x++ { d.Backs[0] = BackOf(x) } d.Mark = make([]door.Panel, 2) d.Mark[0] = MarkOf(0) d.Mark[1] = MarkOf(1) } func CardOf(c int) door.Panel { suit := GetSuit(c) rank := GetRank(c) var is_red bool = suit < 2 var color string if is_red { color = door.ColorText("RED ON WHITE") } else { color = door.ColorText("BLACK ON WHITE") } p := door.Panel{ X: 0, Y: 0, Width: 5} r := RankSymbol(rank) s := SuitSymbol(suit) p.Lines = append(p.Lines, door.Line{Text: string(r) + string(s) + " ", DefaultColor: color}) p.Lines = append(p.Lines, door.Line{Text: " " + string(s) + " ", DefaultColor: color}) p.Lines = append(p.Lines, door.Line{Text: " " + string(s) + string(r), DefaultColor: color}) return p } func BackOf(level int) door.Panel { p := door.Panel{ X: 0, Y: 0, Width: 5, } for x := 0; x < 3; x++ { p.Lines = append(p.Lines, door.Line{Text: strings.Repeat(string(BackSymbol(level)), 5)}) } return p } func MarkOf(c int) door.Panel { p := door.Panel{Width: 1} color := door.ColorText("BLUE ON WHITE") var m rune if c == 0 { m = ' ' } else { if door.Unicode { m = '\u25a0' } else { m = '\xfe' } } p.Lines = append(p.Lines, door.Line{Text: string(m), DefaultColor: color}) return p } func RankSymbol(c int) rune { const symbols = "A23456789TJQK" return rune(symbols[c]) } func SuitSymbol(c int) rune { if door.Unicode { switch c { case 0: return '\u2665' case 1: return '\u2666' case 2: return '\u2663' case 3: return '\u2660' } } else { if door.Full_CP437 { switch c { case 0: return '\x03' case 1: return '\x04' case 2: return '\x05' case 3: return '\x06' } } else { switch c { case 0: return '*' case 1: return '^' case 2: return '%' case 3: return '$' } } } return '?' } func BackSymbol(level int) rune { if level == 0 { return ' ' } if door.Unicode { switch level { case 1: return '\u2591' case 2: return '\u2592' case 3: return '\u2593' case 4: return '\u2588' } } else { switch level { case 1: return '\xb0' case 2: return '\xb1' case 3: return '\xb2' case 4: return '\xdb' } } return '?' } func GetRank(c int) int { return (c % 52) % 13 } func GetSuit(c int) int { return (c % 52) / 13 } func GetDeck(c int) int { return c / 52 }