Added Win Screen

This commit is contained in:
ThatBlokeJosh 2023-09-20 12:17:34 +02:00
parent 45fffc4b13
commit 815d7b14e0
4 changed files with 18 additions and 0 deletions

1
go.mod
View file

@ -9,6 +9,7 @@ require (
)
require (
github.com/abdfnx/gosh v0.4.0 // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect

2
go.sum
View file

@ -1,3 +1,5 @@
github.com/abdfnx/gosh v0.4.0 h1:cBvmHw8yV3oXiAcORpi7Oip+MT6/5HBMOrvpn0cZNYM=
github.com/abdfnx/gosh v0.4.0/go.mod h1:MUTJRMc7FpBb/bFnZ2U0hj48zj8284J1cS3AUiIRZ/o=
github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/charmbracelet/bubbletea v0.23.1 h1:CYdteX1wCiCzKNUlwm25ZHBIc1GXlYFyUIte8WPvhck=

View file

@ -1,6 +1,10 @@
package solitaire
import (
"fmt"
"os"
"strings"
"github.com/brianstrauch/solitaire-tui/pkg"
tea "github.com/charmbracelet/bubbletea"
@ -9,6 +13,8 @@ import (
type deckType int
var kings map[string]bool = make(map[string]bool)
const (
stock deckType = 0
waste deckType = 1
@ -179,6 +185,15 @@ func (s *Solitaire) move(to *index) bool {
if s.selected.card == fromDeck.Size()-1 && toDeck.Size() == 0 && fromDeck.Top().Value == 0 || toDeck.Size() > 0 && fromDeck.Top().Value == toDeck.Top().Value+1 && fromDeck.Top().Suit == toDeck.Top().Suit {
s.toggleSelect(s.selected)
toDeck.Add(fromDeck.Pop())
card := toDeck.Top().String()
cardArr := strings.Split(card, "")
if cardArr[0] == "K" {
kings[card] = true
}
if len(kings) == 4 {
fmt.Println("You Won!")
os.Exit(0)
}
s.selected = nil
return true
}

BIN
solitaire-tui Executable file

Binary file not shown.