Created
November 5, 2017 01:49
-
-
Save alexozer/555f325191662b30c7666650c1eb010b to your computer and use it in GitHub Desktop.
can you send me the text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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