Skip to content

Commit

Permalink
Change view code to use elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hendrix and Yulia Tolskaya committed Jun 18, 2015
1 parent e53fb2f commit 2e21f02
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions src/Rogue/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,68 @@ import Array exposing (..)
import Rogue.Model exposing (..)

view : Game -> Element
view g = leftAligned (Text.monospace (Text.fromString (toString g.gameMap)))
view g = viewGameMap g.gameMap

toString : GameMap -> String
toString {board,start,currentPlayerLocation} =
viewGameMap : GameMap -> Element
viewGameMap {board,start,currentPlayerLocation} =
let
rowifier =
(\row ->
Array.map
(\cell ->
if | isAt currentPlayerLocation cell -> "@"
| not <| isOpen cell -> "#"
| otherwise -> "."
if | isAt currentPlayerLocation cell -> person
| not <| isOpen cell -> barrier
| otherwise -> open
)
row
|> toList
|> join ""
|> flow right
)
in
Array.map rowifier board
|> toList
|> join "\n"
|> flow down


txt str =
Text.fromString str
|> Text.monospace
|> centered

person =
txt "@"
|> standardize

barrier =
square 16
|> filled red
|> (\sq -> collage 16 16 [sq])
|> standardize

open =
txt "."
|> standardize

standardize : Element -> Element
standardize el =
el
|> container 16 16 middle

--toString =
-- let
-- rowifier =
-- (\row ->
-- Array.map
-- (\cell ->
-- if | isAt currentPlayerLocation cell -> "@"
-- | not <| isOpen cell -> "#"
-- | otherwise -> "."
-- )
-- row
-- |> toList
-- |> join ""
-- )
-- in
-- Array.map rowifier board
-- |> toList
-- |> join "\n"

0 comments on commit 2e21f02

Please sign in to comment.