Skip to content
Permalink
Browse files

Random.generate to query random directions

  • Loading branch information...
magopian committed Aug 8, 2019
1 parent 9b904a5 commit f7dba5a3b78980d3c6cc44e17058519d35cee2d8
Showing with 18 additions and 2 deletions.
  1. +1 −0 elm.json
  2. +17 −2 src/Main.elm
@@ -10,6 +10,7 @@
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/random": "1.0.0",
"elm/svg": "1.0.1"
},
"indirect": {
@@ -4,6 +4,7 @@ import Browser
import Browser.Events
import Json.Decode as Decode
import Process
import Random
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Task
@@ -64,6 +65,7 @@ type Msg
| KeyUp PlayerAction
| RestartGame
| NewWinner Player
| NewDirection Int


type PlayerAction
@@ -159,12 +161,25 @@ update msg model =

updatedScore =
updateScores model.score player

sleepCmd =
Process.sleep 500
|> Task.perform alwaysRestartGame
in
( { model | gameStatus = Winner player, score = updatedScore }
, Process.sleep 500
|> Task.perform alwaysRestartGame
, Cmd.batch
[ sleepCmd
, Random.generate NewDirection (Random.int 0 100)
]
)

NewDirection direction ->
let
_ =
Debug.log "New random direction" direction
in
( model, Cmd.none )

KeyDown playerAction ->
case playerAction of
RightPaddleUp ->

0 comments on commit f7dba5a

Please sign in to comment.
You can’t perform that action at this time.