Skip to content

Instantly share code, notes, and snippets.

@alexozer
Created November 5, 2017 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexozer/555f325191662b30c7666650c1eb010b to your computer and use it in GitHub Desktop.
Save alexozer/555f325191662b30c7666650c1eb010b to your computer and use it in GitHub Desktop.
can you send me the text
(* Raised when an irrecoverable error occurs during runtime. Should never be
* thrown unless there is a problem with the game; all error states should
* either be caught during initialization or be handled through the Illegal
* exception during runtime *)
exception RuntimeError of string
(* [pretty_item_list lst container] is a concatenation of strings in
* [container] separated by newlines *)
let rec pretty_item_list lst container =
let item_str item = item.iid ^ ": " ^ item.idescription in
match lst with
| h::[] -> item_str h
| h::t -> (item_str h) ^ "\n" ^ (pretty_item_list t container)
| [] -> ""
(* [print_item_list lst container] prints out the [lst] of items stored in a
* [container], like the inventory or a room *)
let print_item_list lst container =
let () = match lst with
| [] -> print_endline (container ^ " is empty")
| _::_ -> print_endline (container ^ " has items:\n" ^ (pretty_item_list lst container))
in
print_newline ()
(* [get_room st rid] is the room object in the state [st]
* requires:
* [st] is a valid state
* [rid] is the room id of a room that exists
*)
let get_room st rid =
let rec find_room rid = function
| h::t -> if h.rid = rid then h else find_room rid t
| [] -> raise (RuntimeError ("room " ^ rid ^ " not found"))
in
find_room rid st.rooms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment