implemented startNewGame

This commit is contained in:
Jonathan Lamothe
2019-08-22 01:18:02 -04:00
parent ca60d71006
commit c300542635
5 changed files with 47 additions and 12 deletions

View File

@@ -41,4 +41,6 @@ resetYtd
-- | Starts a new game -- | Starts a new game
startNewGame :: ProgState -> ProgState startNewGame :: ProgState -> ProgState
startNewGame = undefined startNewGame
= (progMode .~ NewGame newGameState)
. (database . dbGames .~ 0)

View File

@@ -40,7 +40,4 @@ handleEvent e = do
case m of case m of
MainMenu -> menuHandler mainMenu e MainMenu -> menuHandler mainMenu e
NewSeason -> menuHandler newSeasonMenu e >> return True NewSeason -> menuHandler newSeasonMenu e >> return True
NewGame -> newGame e >> return True NewGame _ -> return True
newGame :: C.Event -> StateT ProgState C.Curses ()
newGame = undefined

View File

@@ -24,7 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Types ( module Mtlstats.Types (
-- * Types -- * Types
ProgState (..), ProgState (..),
GameState (..),
ProgMode (..), ProgMode (..),
GameType (..),
Database (..), Database (..),
Player (..), Player (..),
PlayerStats (..), PlayerStats (..),
@@ -34,6 +36,10 @@ module Mtlstats.Types (
-- ** ProgState Lenses -- ** ProgState Lenses
database, database,
progMode, progMode,
-- ** GameState Lenses
gameType,
homeScore,
visitorScore,
-- ** Database Lenses -- ** Database Lenses
dbPlayers, dbPlayers,
dbGoalies, dbGoalies,
@@ -63,6 +69,7 @@ module Mtlstats.Types (
gsTies, gsTies,
-- * Constructors -- * Constructors
newProgState, newProgState,
newGameState,
newDatabase, newDatabase,
newPlayer, newPlayer,
newPlayerStats, newPlayerStats,
@@ -93,11 +100,24 @@ data ProgState = ProgState
, _progMode :: ProgMode , _progMode :: ProgMode
} deriving (Eq, Show) } deriving (Eq, Show)
-- | The game state
data GameState = GameState
{ _gameType :: Maybe GameType
, _homeScore :: Maybe Int
, _visitorScore :: Maybe Int
} deriving (Eq, Show)
-- | The program mode -- | The program mode
data ProgMode data ProgMode
= MainMenu = MainMenu
| NewSeason | NewSeason
| NewGame | NewGame GameState
deriving (Eq, Show)
-- | The type of game
data GameType
= HomeGame
| AwayGame
deriving (Eq, Show) deriving (Eq, Show)
-- | Represents the database -- | Represents the database
@@ -271,19 +291,28 @@ instance ToJSON GoalieStats where
"ties" .= t "ties" .= t
makeLenses ''ProgState makeLenses ''ProgState
makeLenses ''GameState
makeLenses ''Database makeLenses ''Database
makeLenses ''Player makeLenses ''Player
makeLenses ''PlayerStats makeLenses ''PlayerStats
makeLenses ''Goalie makeLenses ''Goalie
makeLenses ''GoalieStats makeLenses ''GoalieStats
-- | Constructor for a new 'ProgState' -- | Constructor for a 'ProgState'
newProgState :: ProgState newProgState :: ProgState
newProgState = ProgState newProgState = ProgState
{ _database = newDatabase { _database = newDatabase
, _progMode = MainMenu , _progMode = MainMenu
} }
-- | Constructor for a 'GameState'
newGameState :: GameState
newGameState = GameState
{ _gameType = Nothing
, _homeScore = Nothing
, _visitorScore = Nothing
}
-- | Constructor for a 'Database' -- | Constructor for a 'Database'
newDatabase :: Database newDatabase :: Database
newDatabase = Database newDatabase = Database

View File

@@ -36,8 +36,5 @@ draw s = do
case s ^. progMode of case s ^. progMode of
MainMenu -> drawMenu mainMenu MainMenu -> drawMenu mainMenu
NewSeason -> drawMenu newSeasonMenu NewSeason -> drawMenu newSeasonMenu
NewGame -> newGame NewGame _ -> return ()
C.render C.render
newGame :: C.Update ()
newGame = return ()

View File

@@ -49,7 +49,17 @@ startNewSeasonSpec = describe "startNewSeason" $ do
s ^. database . dbGames `shouldBe` 0 s ^. database . dbGames `shouldBe` 0
startNewGameSpec :: Spec startNewGameSpec :: Spec
startNewGameSpec = describe "startGame" $ return () startNewGameSpec = describe "startNewGame" $ do
let
s = newProgState
& database . dbGames .~ 1
& startNewGame
it "should set the number of games to 0" $
s ^. database . dbGames `shouldBe` 0
it "should set the mode to NewGame" $
s ^. progMode `shouldBe` NewGame newGameState
resetYtdSpec :: Spec resetYtdSpec :: Spec
resetYtdSpec = describe "resetYtd" $ resetYtdSpec = describe "resetYtd" $