shithub: klondike

Download patch

ref: 9a98cd3fdac559a31f493d44e84ead8b5f304be8
parent: a30a2d56716a064c1867b6bd1b89088403f11d3c
author: jgstratton <jgstratton@cyber.lan>
date: Thu Sep 30 10:53:34 EDT 2021

Middle click will send the card to the tableau if there is no move to the foundation.

--- a/README.md
+++ b/README.md
@@ -1,7 +1,14 @@
 # plan9-klondike
+Klondike for Plan 9.
+Left click to pick up or flip over cards. Middle click to send a card to the foundation, or tableau. Right click to start a new game or quit. 
+
+### Note on origin of this code.
 This code is originally by Felipe Bichued, and is Public Domain. You can find it listed on https://9p.io/wiki/plan9/Contrib_index/index.html, or, if you are using 9front, under:
-`9fs sources`
-`cd /n/sources/contrib/bichued/root/sys/src/games/klondike/`
+```
+9fs sources
+cd /n/sources/contrib/bichued/root/sys/src/games/klondike/
+```
 
-## Changes made to the original version
+### Changes made to the original version
 1. New mkfile that installs the card images. Card locations added at build time.
+2. Middle click will send the card to the tableau if there is no move to the foundation.
--- a/card.c
+++ b/card.c
@@ -92,6 +92,31 @@
 	drawtable(screen);
 }
 
+void
+putintableau(Point xy)
+{
+	int i;
+	Card *c;
+	Cardstack *src, *dst;
+
+	src = chosenstack(xy);
+	if(src == nil || src == stock
+	|| movpilesize(xy, src) == 0
+	|| !top(src)->up)
+		return;
+	c = pop(src);
+	dst = src;
+	for(i = 0; i < nelem(tableau); i++){
+		dst = tableau[i];
+		if(src != dst)
+			if(validmove(c, dst))
+				break;
+			dst = src;
+	}
+	push(dst, c);
+	drawtable(screen);
+}
+
 int
 canturn(Cardstack *cs)
 {
--- a/klondike.c
+++ b/klondike.c
@@ -202,8 +202,9 @@
 				drag();
 			break;
 		case 2:
-			putinfoundation(mouse.xy);
 			waitbutrelease(2);
+			putinfoundation(mouse.xy);
+			putintableau(mouse.xy);
 			break;
 		case 4:
 			switch(emenuhit(3, &mouse, &menu)){
--- a/klondike.h
+++ b/klondike.h
@@ -59,6 +59,7 @@
 int candrop(Card*, Cardstack*);
 int validmove(Card*, Cardstack*);
 void putinfoundation(Point);
+void putintableau(Point);
 
 /*draw.c*/
 void drawtable(Image*);