80 lines
1.4 KiB
Go
80 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"git.tuxpa.in/a/card_id/common/game"
|
|
"git.tuxpa.in/a/card_id/common/game/card"
|
|
)
|
|
|
|
func main() {
|
|
deal, err := card.NewDealer().ReadFromRoot(os.Getenv("CARD_DATA_DIR"))
|
|
if err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
|
|
g := game.Game{Dealer: deal, Lives: 3}
|
|
|
|
trial := g.CreateTrial(3, 1)
|
|
for {
|
|
if trial != nil {
|
|
if trial.CheckSelection() {
|
|
fmt.Print("\n match found!!!")
|
|
}
|
|
}
|
|
fmt.Printf("\ncardid > ")
|
|
var args [4]string
|
|
alen, _ := fmt.Scanln(&args[0], &args[1], &args[2], &args[3])
|
|
if alen < 0 {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(args[0], "c") {
|
|
args[1] = string(strip([]byte(args[0])))
|
|
args[0] = "c"
|
|
alen = 2
|
|
}
|
|
switch args[0] {
|
|
case "help":
|
|
fmt.Printf("show, select, update")
|
|
case "show":
|
|
fmt.Printf("current hand:\n %+v", trial.Show())
|
|
case "select", "sel", "c":
|
|
if alen > 1 {
|
|
num, _ := strconv.Atoi(args[1])
|
|
cd, err := trial.SelectCard(num)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
if cd.Id > 0 {
|
|
msg := fmt.Sprintf(`
|
|
card %d was %s | lives: %d
|
|
current hand:
|
|
%s`, num, cd.Name, trial.Lives, trial.ShowString())
|
|
fmt.Printf(msg)
|
|
}
|
|
} else {
|
|
trial.SelectCard(0)
|
|
}
|
|
case "debug":
|
|
fmt.Println(trial)
|
|
case "exit", "quit", "q":
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
}
|
|
func strip(s []byte) []byte {
|
|
n := 0
|
|
for _, b := range s {
|
|
if ('0' <= b && b <= '9') ||
|
|
b == ' ' {
|
|
s[n] = b
|
|
n++
|
|
}
|
|
}
|
|
return s[:n]
|
|
}
|