summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2023-01-05 20:59:02 +0800
committerFrederick Yin <fkfd@fkfd.me>2023-01-05 20:59:02 +0800
commit79fba8934969b660298e3a2c875a49d500313d1a (patch)
tree8a32d01c68a64323e079ee428dd4a74e7f003d58
parent8642b92029e8e7072d18fa04f90ee59f7ac3d933 (diff)
Prompt for card to play
-rw-r--r--Game.hs28
-rw-r--r--Main.hs31
2 files changed, 57 insertions, 2 deletions
diff --git a/Game.hs b/Game.hs
index 3b02598..27d7804 100644
--- a/Game.hs
+++ b/Game.hs
@@ -1,11 +1,37 @@
module Game where
-import Player (Player)
+import Data.Char (isDigit)
+import Control.Monad (when)
+import System.Random (RandomGen)
+import Player (Player, shed, draw)
import qualified Player as P
import Card (Card)
import qualified Card as C
+data Direction = CCW | CW
data Game = Game { players :: [Player]
+ , playerIdx :: Int
+ , attack :: Integer
+ , direction :: Direction
, stockPile :: [Card]
, discardPile :: [Card]
}
+
+prompt :: Game -> IO Card
+prompt game@(Game plyrs pidx att _ _ _) = do
+ let player = plyrs !! pidx
+ let cards = P.cards player
+ putStrLn $ P.name player ++ "'s turn"
+ putStrLn $ P.showCards player
+ cardIdxStr <- getLine
+ if any (== False) $ map isDigit cardIdxStr
+ then do
+ putStrLn "Please input card #"
+ prompt game
+ else do
+ let cardIdx = read cardIdxStr - 1
+ if cardIdx < 0 || cardIdx >= length cards
+ then do
+ putStrLn "This card does not exist, try again"
+ prompt game
+ else return $ cards !! cardIdx
diff --git a/Main.hs b/Main.hs
index e42a3f0..48726b7 100644
--- a/Main.hs
+++ b/Main.hs
@@ -1,6 +1,35 @@
import System.Random (getStdGen)
import Card (fullDecks, showCard, shuffle)
+import Game (Game(..),
+ Direction(CCW, CW),
+ players,
+ playerIdx,
+ attack,
+ direction,
+ stockPile,
+ discardPile,
+ prompt,
+ )
+import Player (Player(..))
+import qualified Player as P
+import Card (Card)
+import qualified Card as C
+main :: IO ()
main = do
gen <- getStdGen
- print $ map showCard $ shuffle gen $ fullDecks 2
+ let stock = shuffle gen $ fullDecks 2
+ let discard = []
+ let defaultPlayers = [ Player "Alice" 0 $ take 6 $ fullDecks 1
+ , Player "Bob" 0 $ take 6 $ fullDecks 1
+ , Player "Carol" 0 $ take 6 $ fullDecks 1
+ ]
+ let game = Game { players = defaultPlayers
+ , playerIdx = 0
+ , attack = 0
+ , direction = CCW
+ , stockPile = stock
+ , discardPile = discard
+ }
+ card <- prompt game
+ print card