72 lines
1.4 KiB
Fennel
72 lines
1.4 KiB
Fennel
(local {: rolls} (require :lib.roller))
|
|
(local {: parse } (require :lib.parser))
|
|
|
|
(fn game-over [p m s]
|
|
(set p.cash (+ p.cash (* p.bet m)))
|
|
(set p.turn false)
|
|
(print (string.format s p.bet))
|
|
(print "\nEnter 'm' to return to menu or just press Enter to play again")
|
|
)
|
|
|
|
(fn lose [p]
|
|
(game-over p -1 "You lose $%d"))
|
|
|
|
(fn win [p]
|
|
(game-over p 1 "You win $%d!"))
|
|
|
|
(fn set-point [player pt]
|
|
(set player.point pt)
|
|
(print (string.format "Point set to %d." pt))
|
|
)
|
|
|
|
(fn bank-roll [p]
|
|
(let [t (rolls)
|
|
[ n str ] (parse t)
|
|
pp (fn [x] (table.concat x " "))
|
|
]
|
|
(print (pp t) str)
|
|
(match n
|
|
6 (lose p)
|
|
1 (win p)
|
|
0 (bank-roll p)
|
|
x (set-point p x)
|
|
)
|
|
)
|
|
)
|
|
|
|
(fn player-roll [p]
|
|
(let [t (rolls)
|
|
[ n str ] (parse t)
|
|
pp (fn [x] (table.concat x " "))
|
|
]
|
|
(print (pp t) str)
|
|
(match n
|
|
6 (win p)
|
|
1 (lose p)
|
|
(where x (> x p.point)) (win p)
|
|
_ (player-roll p)
|
|
)
|
|
)
|
|
)
|
|
|
|
{
|
|
:name "play"
|
|
|
|
:display (fn [p]
|
|
(set p.turn true)
|
|
(print "Bank rolls first..")
|
|
(print (bank-roll p))
|
|
(when p.turn
|
|
(print "Player's turn")
|
|
(player-roll p)
|
|
)
|
|
)
|
|
|
|
:key-pressed (fn key-pressed [p k set-mode]
|
|
(match k
|
|
"m" (set-mode :mode.menu)
|
|
"p" (set-mode :mode.play)
|
|
)
|
|
)
|
|
}
|