Skip to content

Instantly share code, notes, and snippets.

@ciwolsey
Created March 6, 2020 15:05
Show Gist options
  • Save ciwolsey/059c13848820fb5a09a70e438969845e to your computer and use it in GitHub Desktop.
Save ciwolsey/059c13848820fb5a09a70e438969845e to your computer and use it in GitHub Desktop.
open FSharp.Json
open System.IO
open System
open System.Collections.Generic
type Description = {
text: string
}
type Item = {
Description: Description
}
type Room = {
Id: Guid
Description: Description
Exits: Dictionary<string, Room>
Items: Item list
}
type RoomList = {
Rooms: Room list
}
[<EntryPoint>]
let main argv =
let rooms = {
Rooms = [
{
Id = Guid.NewGuid();
Description = { text = "Room 1" };
Exits = Dictionary<string, Room>();
Items = [];
};
{
Id = Guid.NewGuid();
Description = { text = "Room 2" };
Exits = Dictionary<string, Room>();
Items = [];
}]
}
let firstRoom = rooms.Rooms.[1];
let secondRoom = rooms.Rooms.[2];
firstRoom.Exits.Add ("North", secondRoom)
secondRoom.Exits.Add("South", firstRoom)
printfn "%s" firstRoom.Exits.["North"].Description.text
// Can't serialize right now due to recursion
//File.WriteAllText ("World.json", Json.serialize rooms)
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment