-
Notifications
You must be signed in to change notification settings - Fork 0
/
Type.elm
105 lines (86 loc) · 1.46 KB
/
Type.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
96
97
98
99
100
101
102
103
104
105
module Type exposing (..)
import Keyboard exposing (KeyCode)
type Key
= Space
| ArrowUp
| ArrowDown
| ArrowLeft
| ArrowRight
type Direction
= Up
| Down
| Left
| Right
type alias Position = {
x: Int,
y: Int
}
type Class
= Box
| Floor
| Target
| Start
| Wall
| Void
type alias Square = {
position: Position,
class: Class
}
type alias Player = {
direction: Direction,
position: Position
}
type alias Size = {
heigth: Int,
width: Int
}
type alias Layer = List Position
type alias Layers = List Layer
type alias Map = {
boxes: Layer,
target: Layer,
wall: Layer,
floor: Layer
}
type alias Statistic = {
moves: Int,
pushes: Int
}
type alias Level = {
number: Int,
size: Size,
map: Map,
player: Player,
statistic: Statistic
}
type alias LevelRow = List Class
type alias LevelData = List (List Class)
type Screen
= ScreenIntro
| ScreenLevel
| ScreenComplete
| ScreenVictory
type alias Model =
{
screen: Screen,
level: Maybe Level
}
type Msg
= KeyDown Keyboard.KeyCode
fromKeyCodeToKey: Int -> Maybe Key
fromKeyCodeToKey keyCode =
case keyCode of
32 -> Just Space
37 -> Just ArrowLeft
39 -> Just ArrowRight
38 -> Just ArrowUp
40 -> Just ArrowDown
_ -> Nothing
fromKeyCodeToDirection: Int -> Maybe Direction
fromKeyCodeToDirection keyCode =
case keyCode of
37 -> Just Left
38 -> Just Up
39 -> Just Right
40 -> Just Down
_ -> Nothing