-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.elm
95 lines (79 loc) · 2.54 KB
/
Main.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module Main where
import Keyboard
import String
import Text
import Grid
import Generator
import Generator.Standard
import GameModel
import GameUpdate
import GameView
import MapGen
port title : String
port title = "Chimera"
seed : Int
seed = 2015
dimensions : (Int, Int)
dimensions = (30, 20)
gen : GameModel.Random
gen = Generator.Standard.generator seed
initialLevel : Grid.Grid GameModel.Tile
initialLevel =
let toTile c = case c of
' ' -> GameModel.Floor
'#' -> GameModel.Wall
'+' -> GameModel.Door
'~' -> GameModel.Acid
s = [ "####################"
, "# # #"
, "# # #"
, "# #"
, "# # #"
, "# # #"
, "####################"
]
in Grid.fromList <| map (\x -> map toTile <| String.toList x) s
initialExplored : Grid.Grid GameModel.Visibility
initialExplored =
let grid = Grid.toList initialLevel
in map (\row -> map (\_ -> GameModel.Unexplored) row) grid |> Grid.fromList
setExplored : Grid.Grid GameModel.Tile -> Grid.Grid GameModel.Visibility
setExplored level =
let grid = Grid.toList level
in map (\row -> map (\_ -> GameModel.Unexplored) row) grid |> Grid.fromList
initialPlayer : GameModel.Random -> (GameModel.Player, GameModel.Random)
initialPlayer gen =
let elem = "@"
|> toText
|> monospace
|> Text.color white
|> centered
in GameModel.player elem "You" gen
initialEnemy : GameModel.Random -> (GameModel.Enemy, GameModel.Random)
initialEnemy gen =
let elem = "e"
|> toText
|> monospace
|> Text.color white
|> centered
in GameModel.enemy elem "enemy" gen
initialState : GameModel.State
initialState =
let (player, gen') = initialPlayer gen
(enemy, gen'') = initialEnemy gen'
(firstMap, gen''') = MapGen.randomCave dimensions gen''
firstExplored = setExplored firstMap
in GameModel.State
player
[enemy]
firstMap
firstExplored
["you enter the dungeon"]
gen'''
|> GameUpdate.placeEntities |> GameUpdate.reveal
inputs : Signal GameModel.Input
inputs = GameModel.handle <~ Keyboard.lastPressed
state : Signal GameModel.State
state = foldp GameUpdate.update initialState inputs
main : Signal Element
main = GameView.display <~ state