% ag_server5.erl - (Silver) Adventure Game Server -module(ag_server5). -author('Alan G. Labouseur'). %-------- % Public %-------- -export([start/0, goToLocale/2]). start() -> io:fwrite("Starting AG server.~n",[]), spawn(fun serverLoop/0). goToLocale(ServerPid, Destination) -> rpc(ServerPid, Destination). %--------- % Private %--------- rpc(ToPid, Request) -> ToPid ! {self(), Request}, receive {ToPid, Response} -> Response % This waits for a response from ToPid. end. serverLoop() -> receive { FromPid, {0, L} } -> FromPid ! {self(), io:format("You are standing west of a house. Inventory: ~w.~n", [L])}, serverLoop(); { FromPid, {1, L} } -> FromPid ! {self(), io:format("You have come to the base of a large tree. Inventory: ~w.~n", [L])}, serverLoop(); { FromPid, {_, L} } -> FromPid ! {self(), io:format("You are lost in unknown locale. Good going, Indiana. Perhaps one of these items will help: ~w.~n", [L])}, serverLoop() end.