-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.fs
104 lines (87 loc) · 2.15 KB
/
Model.fs
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
[<AutoOpen>]
module Model
type Visibility =
| Full
| Explored
| Sight
with
override this.ToString () =
match this with
| Full -> "Full (easy)"
| Explored -> "Explored (medium)"
| Sight -> "Sight (hard)"
member this.Next = nextUnionCase this
member this.Prev = prevUnionCase this
type ScrollSpeed =
| Slowest
| Slow
| Medium
| Fast
| Fastest
with
member this.Next = nextUnionCase this
member this.Prev = prevUnionCase this
member this.Delay =
match this with
| Slowest -> 60
| Slow -> 45
| Medium -> 30
| Fast -> 15
| Fastest -> 0
type Config = {
RoomWidth: int
RoomHeight: int
Visibility: Visibility
ScrollSpeed: ScrollSpeed
}
with
member this.CharWidth = this.RoomWidth*2 + 1
member this.CharHeight = this.RoomHeight*2 + 1
static member Default = {
RoomWidth = 32
RoomHeight = 16
Visibility = Explored
ScrollSpeed = Medium
}
type Menu = {
Config: Config
Cursor: int
}
type Direction = Up | Down | Left | Right
type Room = {
// Whether this room has a wall to the North (Up)
N: bool
// Whether this room has a wall to the West (Left)
W: bool
}
type RoomWall = N | W
type Game = {
Config: Config
Rooms: Room array
RenderedMaze: char array array
/// Set of visible char coordinates
VisibleCoords: (int * int) Set
ViewPos: int * int
PendingViewPos: int * int
Start: int
Finish: int
Player: int
}
with
member this.Width = this.Config.RoomWidth
member this.Height = this.Config.RoomHeight
member this.Won = this.Player = this.Finish
type State =
| Menu of Menu
| Game of Game
with
member this.IsInMenu =
match this with Menu _ -> true | _ -> false
member this.Config =
match this with
| Menu m -> m.Config
| Game g -> g.Config
open Serialization
let private configFilePath = System.IO.Path.Join(appDataDirectory, "Eskape", "settings.txt")
let loadConfig () = readFile configFilePath Config.Default
let saveConfig (config: Config) = writeFile configFilePath config