Last active
June 4, 2020 11:40
-
-
Save dariathecracker/cebd3bcfc1a63ef5a5987f6ae9c1569c to your computer and use it in GitHub Desktop.
Call RunLoop service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ioleo.tictactoe | |
import ioleo.tictactoe.domain.State | |
import zio.{console, App, UIO, ZIO} | |
object TicTacToe extends App { | |
val program = { | |
def loop(state: State): ZIO[app.RunLoop, Nothing, Unit] = | |
app.RunLoop.>.step(state).foldM( | |
_ => UIO.unit | |
, nextState => loop(nextState) | |
) | |
loop(State.default) | |
} | |
def run(args: List[String]): ZIO[Environment, Nothing, Int] = | |
for { | |
env <- prepareEnvironment | |
out <- program.provide(env).foldM( | |
error => console.putStrLn(s"Execution failed with: $error") *> UIO.succeed(1) | |
, _ => UIO.succeed(0) | |
) | |
} yield out | |
private val prepareEnvironment = | |
UIO.succeed( | |
new app.ControllerLive | |
with app.RunLoopLive | |
with cli.TerminalLive | |
with logic.GameLogicLive | |
with logic.OpponentAiLive | |
with mode.ConfirmModeLive | |
with mode.GameModeLive | |
with mode.MenuModeLive | |
with parser.ConfirmCommandParserLive | |
with parser.GameCommandParserLive | |
with parser.MenuCommandParserLive | |
with view.ConfirmViewLive | |
with view.GameViewLive | |
with view.MenuViewLive | |
with zio.console.Console.Live | |
with zio.random.Random.Live {} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment