Crazy Eights, Spite & Malice, Old Maid: SVG boards" \

discard, suit in play, stock, and the hand.
* cg-spite.el (cg-spite--board-svg, cg-spite--render-text): centre piles,
goal, discards, and hand.
* cg-match.el (cg-om--svg, cg-om--render-text, cg-render-apply): Old Maid
board with clickable target cards; wire mouse-1, zoom, and cg-current-game.
* test/card-games-tests.el: add cgt-eights-svg-smoke, cgt-spite-svg-smoke,
cgt-om-svg-smoke.
* NEWS: note the new boards.
This commit is contained in:
Corwin Brust 2026-07-01 05:06:29 -05:00
parent 2ee802f52d
commit 32fb9f0c6d
5 changed files with 222 additions and 3 deletions

View file

@ -213,8 +213,65 @@ Return the drawn card, or nil when none is available."
"Return the cg-svg display spec (RANK-STRING . SUIT) for CARD."
(cons (aref cg-eights-ranks (cdr card)) (car card)))
(defun cg-eights--board-svg (game)
"Return an SVG board for the Crazy Eights GAME."
(let* ((w cg-svg-card-width) (h cg-svg-card-height) (gap cg-svg-card-gap) (pad 16)
(hand (cg-eights--hand game 0)) (n (length hand))
(cursor (cg-get game :cursor))
(top (cg-eights--top game)) (suit (cg-get game :suit))
(overlap (cond ((> n 11) (- w 24)) ((> n 8) 20) (t 0)))
(step (max 14 (- (+ w gap) overlap)))
(fanw (if (> n 0) (+ (* (1- n) step) w) w))
(np (cg-get game :nplayers)) (nstock (length (cg-get game :stock)))
(y-title 6) (y-info 26)
(y-mid (+ y-info (* (1- np) 16) 14))
(y-hand (+ y-mid h 42))
(height (+ y-hand h 30))
(width (max (+ fanw (* 2 pad)) 560))
(svg (svg-create width height))
(lc (cg-color 'shadow :foreground "gray50"))
(regions '()))
(cl-labels ((txt (str x y &optional sz bold)
(apply #'svg-text svg str :x x :y y :font-size (or sz 12) :fill lc
:font-family cg-svg-font-family (and bold '(:font-weight "bold")))))
(txt "Crazy Eights" pad (+ y-title 12) 13 t)
(let ((yy (+ y-info 4)))
(dotimes (s np)
(unless (= s 0)
(txt (format "Player %d: %d cards (score %d)" s
(length (cg-eights--hand game s)) (aref (cg-get game :scores) s))
pad yy 12)
(setq yy (+ yy 16)))))
(cg-svg-card svg pad y-mid :down (> nstock 0) :gap (= nstock 0))
(txt (format "Stock %d" nstock) pad (+ y-mid h 13) 11)
(let ((dx (+ pad w gap 28)) (sp (cg-eights--spec top)))
(cg-svg-card svg dx y-mid :rank (car sp) :suit (cdr sp))
(txt "Discard" dx (+ y-mid h 13) 11)
(let ((sx (+ dx w gap 34))
(col (if (cg-red-suit-p suit) "#c0392b" "#2c3e50")))
(txt "Suit in play" sx (- y-mid 4) 11)
(svg-text svg (cg-suit-glyph suit) :x (+ sx 12) :y (+ y-mid 46)
:font-size 44 :fill col :font-family cg-svg-font-family)))
(txt "Your hand" pad (- y-hand 6) 11)
(let ((x (max pad (- (/ width 2) (/ fanw 2)))) (i 0))
(dolist (c hand)
(let ((sp (cg-eights--spec c)) (curp (= i cursor))
(hintp (cg-eights--legal-p game c)))
(cg-svg-card svg x y-hand :rank (car sp) :suit (cdr sp)
:highlight curp :hint hintp)
(push (cons (list x y-hand (if (= i (1- n)) w step) h) (cons 'hand i)) regions))
(setq x (+ x step) i (1+ i))))
(txt (or (cg-get game :message) "") pad (- height 8) 12))
(propertize "*" 'display (cg-svg-image svg (cg-scale)) 'cg-regions (nreverse regions))))
(cl-defmethod cg-render ((game cg-eights-game))
"Return a propertized string depicting GAME for a text display."
"Return a depiction of GAME: an SVG board if graphical, else text."
(if (and cg-eights-svg-cards (display-graphic-p))
(cg-eights--board-svg game)
(cg-eights--render-text game)))
(defun cg-eights--render-text (game)
"Return a plain-text depiction of GAME."
(let* ((out (list)) (top (cg-eights--top game))
(hand (cg-eights--hand game 0)) (cursor (cg-get game :cursor)))
(push (format " Crazy Eights\n\n") out)