Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module TitleModule =
- type GameTitle = GameTitle of string
- type TitleEvents =
- | Start
- | Exit
- open TitleModule
- open System.Text.RegularExpressions
- open System.Linq
- open System
- module EndGameModule =
- type EndGameTitle = EndGameTitle of string
- type EndGameEvents =
- | PlayAgain
- | Exit
- module BingoModule =
- type Value = Value of int
- type Cell =
- { Value: Value
- X: int
- Y: int }
- type GameState =
- | None
- | Winner of Cell list
- type Bingo =
- { Cells: Cell list
- GameState: GameState }
- type BingoEvents =
- | Loaded of Bingo
- | PlaceValue of X: int * Y: int * Value: Value
- | ValuePlaced of Bingo
- | WinnerFound of Bingo
- | Exit
- let generate height width =
- {
- Cells = []
- GameState = None
- }
- let placeValue bingo value x y = ()
- type Generator =
- { generate: unit -> Value }
- module GameProcessor =
- type CurrentGameState =
- | Title of TitleModule.GameTitle
- | Bingo of BingoModule.Bingo
- | EndGame of EndGameModule.EndGameTitle
- | Exit
- type Events =
- | TitleEvents of TitleModule.TitleEvents
- | BingoEvents of BingoModule.BingoEvents
- | EndGameEvents of EndGameModule.EndGameEvents
- let private applyEvent currentGameState event =
- match currentGameState, event with
- | Title _, TitleEvents titleEvent ->
- match titleEvent with
- | TitleEvents.Start -> Bingo (BingoModule.generate 3 3)
- | TitleEvents.Exit -> EndGame (EndGameModule.EndGameTitle "Buy")
- | _ -> currentGameState
- let processEvents events currentGameState =
- events |> Seq.fold applyEvent currentGameState
- let init = Title (GameTitle "Bingo!")
- let view state = state.ToString()
- open GameProcessor
- [<EntryPoint>]
- let main _ =
- let rec untilPressed regex =
- let consoleOutput = Console.ReadLine()
- match Regex.IsMatch(consoleOutput, regex) with
- | true -> Regex.Matches(consoleOutput, regex)
- .Cast<Match>()
- .First()
- .Groups
- .Cast<Group>()
- .ToList()
- |> List.ofSeq
- |> List.map(fun x -> x.Value)
- | false -> untilPressed regex
- let isPressed regex =
- untilPressed regex |> ignore
- let run =
- let rec loop state =
- printfn "%s" (state |> GameProcessor.view)
- let events =
- seq {
- match state with
- | CurrentGameState.Title _ ->
- isPressed "s"
- yield TitleEvents (TitleEvents.Start)
- isPressed "x"
- yield TitleEvents (TitleEvents.Exit)
- | CurrentGameState.Bingo _ ->
- printfn "Input coordinaes"
- let x, y = untilPressed "(\d+) (\d+)" |> (fun m ->
- printfn "%A" m
- m.[1] |> int, m.[2] |> int)
- yield BingoEvents (BingoModule.BingoEvents.PlaceValue (x, y, BingoModule.Value 3) )
- | _ -> failwith "Unknown state"
- }
- Console.Clear()
- loop (state |> GameProcessor.processEvents events)
- loop GameProcessor.init
- run |> ignore
- Console.ReadKey() |> ignore
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement