Skip to content

Commit

Permalink
Add level statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
ufocoder committed Jan 4, 2017
1 parent b79162f commit dee4ec0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/Data.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ generateLevel levelNumber levelData =
player = {
direction = Left,
position = extractPlayerPosition positionsTuples
},
statistic = {
moves = 0,
pushes = 0
}
}

Expand Down
26 changes: 18 additions & 8 deletions src/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,25 @@ movePlayer: Direction -> Position -> Level -> Level
movePlayer direction position level =
let
gamePlayer = level.player
levelStatistic = level.statistic
in
{
level | player = {
gamePlayer |
position = position,
direction = direction
}
level |
statistic = {
levelStatistic | moves = levelStatistic.moves + 1
},
player = {
gamePlayer |
position = position,
direction = direction
}
}

moveBox: Direction -> Position -> Level -> Level
moveBox direction position level =
let
levelMap = level.map
levelStatistic = level.statistic
mapBoxes = levelMap.boxes
|> List.map (
\square ->
Expand All @@ -71,9 +77,13 @@ moveBox direction position level =
)
in
{
level | map = {
levelMap | boxes = mapBoxes
}
level |
statistic = {
levelStatistic | pushes = levelStatistic.pushes + 1
},
map = {
levelMap | boxes = mapBoxes
}
}

move: Position -> Direction -> Position
Expand Down
9 changes: 9 additions & 0 deletions src/Render.elm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ player player =
Html.div [Style.player player.position player.direction] []


statistic: Statistic -> Html msd
statistic statistic =
Html.div [Style.statistic] [
text (
"moves " ++ (toString statistic.moves) ++ ", " ++
"pushes " ++ (toString statistic.pushes)
)
]

square: Class -> Position -> Html msg
square class position =
case class of
Expand Down
1 change: 1 addition & 0 deletions src/Screen/Complete.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ render model =
Just level ->
Render.layout [
Render.title ("Level " ++ (toString (level.number + 1)) ++ " complete"),
Render.statistic level.statistic,
Render.menu "Press spacebar to play next level"
]

Expand Down
1 change: 1 addition & 0 deletions src/Screen/Level.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ render model =
Just level ->
Render.layout [
Render.title ("Level " ++ (toString (level.number + 1))),
Render.statistic level.statistic,
Render.grid level.size [
Render.player level.player,
Render.layer Floor level.map.floor,
Expand Down
25 changes: 18 additions & 7 deletions src/Style.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ menu = style
title: Attribute msg
title = style
[
("position", "absolute"),
("top", "120px"),
("position", "relative"),
("top", "0px"),
("color", "#bac4c5"),
("font-family", "'Orbitron', sans-serif"),
("font-size", "40px"),
Expand All @@ -61,16 +61,26 @@ title = style
("width", "100%")
]

statistic: Attribute msg
statistic =
style [
("position", "relative"),
("top", "0px"),
("color", "#bac4c5"),
("font-family", "'Orbitron', sans-serif"),
("font-size", "16px"),
("line-heigth", "16px"),
("text-align", "center"),
("width", "100%")
]

grid: Int -> Int -> Attribute msg
grid height width = style
[
("position", "absolute"),
("position", "relative"),
("height", toPixels (height * squareSize)),
("width", toPixels (width * squareSize)),
("left", "50%"),
("top", "50%"),
("margin-left", "-" ++ toPixels (width * squareSize // 2)),
("margin-top", "-" ++ toPixels (height * squareSize // 2))
("margin", "auto 0")
]


Expand Down Expand Up @@ -99,6 +109,7 @@ player position direction =
]
)


baseSquare: Position -> List (String, String)
baseSquare position =
[
Expand Down
8 changes: 7 additions & 1 deletion src/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ type alias Map = {
floor: Layer
}

type alias Statistic = {
moves: Int,
pushes: Int
}

type alias Level = {
number: Int,
size: Size,
map: Map,
player: Player
player: Player,
statistic: Statistic
}

type alias LevelRow = List Class
Expand Down

0 comments on commit dee4ec0

Please sign in to comment.