summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2023-01-08 19:52:41 +0800
committerFrederick Yin <fkfd@fkfd.me>2023-01-08 19:52:41 +0800
commit988f9eaf9b1c3e0d56f23bf4b698601adc2e3b9f (patch)
tree2adabbd19d56e4fd28410eebcbf73d700092547c
parentec0654bf0ca057affb37a20ed0588a907e71130f (diff)
Handle Jack and Queen
-rw-r--r--Game.hs15
-rw-r--r--Main.hs5
2 files changed, 12 insertions, 8 deletions
diff --git a/Game.hs b/Game.hs
index 203b66f..c55acf5 100644
--- a/Game.hs
+++ b/Game.hs
@@ -5,14 +5,13 @@ import Control.Monad (when)
import System.Random (RandomGen)
import Player (Player, shed, draw)
import qualified Player as P
-import Card (Card)
+import Card (Card(..))
import qualified Card as C
-data Direction = CCW | CW
data Game = Game { players :: [Player]
, playerIdx :: Int
, attack :: Integer
- , direction :: Direction
+ , direction :: Int -- ^ 1 when CCW, -1 when CW
, stockPile :: [Card]
, discardPile :: [Card]
}
@@ -29,6 +28,7 @@ nextRound n game = do
-- | Let current player take their turn.
nextTurn :: Game -> IO Game
nextTurn game@(Game plyrs pidx att dir stock disc) = do
+ putStrLn $ replicate 80 '-'
decision <- prompt game
let player = plyrs !! pidx
let player' = case decision of
@@ -42,8 +42,13 @@ nextTurn game@(Game plyrs pidx att dir stock disc) = do
Just card -> card:disc
let (left, right) = splitAt pidx plyrs
let plyrs' = left ++ [player'] ++ (tail right)
- let pidx' = (pidx + 1) `mod` (length plyrs)
- let game' = Game plyrs' pidx' att dir stock' disc'
+ let dir' = case decision of
+ Just (Card _ C.Queen) -> negate dir
+ _ -> dir
+ let pidx' = case decision of
+ Just (Card _ C.Jack) -> (pidx + 2 * dir') `mod` length plyrs
+ _ -> (pidx + dir') `mod` length plyrs
+ let game' = Game plyrs' pidx' att dir' stock' disc'
case decision of
Nothing -> do
diff --git a/Main.hs b/Main.hs
index fd10cdf..9cf55fe 100644
--- a/Main.hs
+++ b/Main.hs
@@ -1,7 +1,6 @@
import System.Random (getStdGen)
import Card (fullDecks, showCard, shuffle)
import Game (Game(..),
- Direction(CCW, CW),
players,
playerIdx,
attack,
@@ -29,10 +28,10 @@ main = do
let game = Game { players = defaultPlayers
, playerIdx = 0
, attack = 0
- , direction = CCW
+ , direction = 1
, stockPile = stock
, discardPile = discard
}
- nextRound 1 $ dealCards 1 game
+ nextRound 1 $ dealCards 6 game
print ()