Added state #6, #7, #8

This commit is contained in:
Tibo De Peuter 2022-12-14 15:13:43 +01:00
parent f348a47281
commit 9e5f22458c
6 changed files with 93 additions and 30 deletions

View file

@ -2,21 +2,24 @@
module Game
( Game(..)
, initGame -- Initialize the game
-- Initialize the game
, initGame
) where
import State
----------------------------- Constants ------------------------------
-- TODO Add more
data Game = Game {
-- TODO Add more
playerName :: String
-- Current state of the game
state :: State
}
----------------------------------------------------------------------
-- Initialize the game
-- TODO Expand
initGame :: Game
initGame = Game {
playerName = "Tibo"
state = defaultState
}

32
lib/data/State.hs Normal file
View file

@ -0,0 +1,32 @@
-- Describes the current state of the game,
-- e.g. Main menu, game, pause, win or lose
-- Allows to easily go to a next state and change rendering accordingly
module State
( State(..)
-- Default state of the game, Menu
, defaultState
-- Get the next state based on the current state
, nextState
) where
----------------------------- Constants ------------------------------
-- Current state of the game.
data State = Menu
| Playing
| Pause
| Win
| Lose
----------------------------------------------------------------------
defaultState :: State
defaultState = Menu
nextState :: State -> State
nextState Menu = Playing
nextState Playing = Pause
nextState Pause = Playing
nextState _ = Menu