parent
f348a47281
commit
9e5f22458c
6 changed files with 93 additions and 30 deletions
|
@ -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
32
lib/data/State.hs
Normal 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
|
Reference in a new issue