mirror of
https://github.com/brianstrauch/solitaire-tui.git
synced 2024-12-27 21:58:40 +01:00
Added Win Screen
This commit is contained in:
parent
45fffc4b13
commit
815d7b14e0
4 changed files with 18 additions and 0 deletions
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/abdfnx/gosh v0.4.0 // indirect
|
||||||
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
|
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
|
||||||
github.com/containerd/console v1.0.3 // indirect
|
github.com/containerd/console v1.0.3 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -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 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
|
||||||
github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
|
github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
|
||||||
github.com/charmbracelet/bubbletea v0.23.1 h1:CYdteX1wCiCzKNUlwm25ZHBIc1GXlYFyUIte8WPvhck=
|
github.com/charmbracelet/bubbletea v0.23.1 h1:CYdteX1wCiCzKNUlwm25ZHBIc1GXlYFyUIte8WPvhck=
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package solitaire
|
package solitaire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/brianstrauch/solitaire-tui/pkg"
|
"github.com/brianstrauch/solitaire-tui/pkg"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
@ -9,6 +13,8 @@ import (
|
||||||
|
|
||||||
type deckType int
|
type deckType int
|
||||||
|
|
||||||
|
var kings map[string]bool = make(map[string]bool)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
stock deckType = 0
|
stock deckType = 0
|
||||||
waste deckType = 1
|
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 {
|
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)
|
s.toggleSelect(s.selected)
|
||||||
toDeck.Add(fromDeck.Pop())
|
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
|
s.selected = nil
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
BIN
solitaire-tui
Executable file
BIN
solitaire-tui
Executable file
Binary file not shown.
Loading…
Reference in a new issue