diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-04-03 21:14:30 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-04-03 21:14:30 +1100 |
commit | 2144edd083e11268c1da351eb73ae469bdb73006 (patch) | |
tree | 4300c4464d2b03d04b615479ce510956927977b4 | |
parent | 0b65dd864a804a6b96ca1b8aeacd947eeb361538 (diff) |
Improved command handling
-rw-r--r-- | command.prolog | 48 | ||||
-rw-r--r-- | main.prolog | 10 |
2 files changed, 34 insertions, 24 deletions
diff --git a/command.prolog b/command.prolog index b8989f4..f897735 100644 --- a/command.prolog +++ b/command.prolog @@ -10,38 +10,38 @@ % functions for parsing a list of words into a recognised command -getCommand(['quit'],C) :- C = [quit]. -getCommand(['exit'],C) :- C = [quit]. +getCommand(['quit'],C) :- C =.. [quit]. +getCommand(['exit'],C) :- C =.. [quit]. -getCommand(['go',X],C) :- C = [move,X]. -getCommand(['move',X],C) :- C = [move,X]. +getCommand(['go',X],C) :- C =.. [move,X]. +getCommand(['move',X],C) :- C =.. [move,X]. -getCommand(['n'],C) :- C = [move,north]. -getCommand(['north'],C) :- C = [move,north]. -getCommand(['s'],C) :- C = [move,south]. -getCommand(['south'],C) :- C = [move,south]. -getCommand(['e'],C) :- C = [move,east]. -getCommand(['east'],C) :- C = [move,east]. -getCommand(['w'],C) :- C = [move,west]. -getCommand(['west'],C) :- C = [move,west]. +getCommand(['n'],C) :- C =.. [move,north]. +getCommand(['north'],C) :- C =.. [move,north]. +getCommand(['s'],C) :- C =.. [move,south]. +getCommand(['south'],C) :- C =.. [move,south]. +getCommand(['e'],C) :- C =.. [move,east]. +getCommand(['east'],C) :- C =.. [move,east]. +getCommand(['w'],C) :- C =.. [move,west]. +getCommand(['west'],C) :- C =.. [move,west]. -getCommand(['nw'],C) :- C = [move,northwest]. -getCommand(['northwest'],C) :- C = [move,northwest]. -getCommand(['ne'],C) :- C = [move,northeast]. -getCommand(['northeast'],C) :- C = [move,northeast]. -getCommand(['sw'],C) :- C = [move,southwest]. -getCommand(['southwest'],C) :- C = [move,southwest]. -getCommand(['se'],C) :- C = [move,southeast]. -getCommand(['southeast'],C) :- C = [move,southeast]. +getCommand(['nw'],C) :- C =.. [move,northwest]. +getCommand(['northwest'],C) :- C =.. [move,northwest]. +getCommand(['ne'],C) :- C =.. [move,northeast]. +getCommand(['northeast'],C) :- C =.. [move,northeast]. +getCommand(['sw'],C) :- C =.. [move,southwest]. +getCommand(['southwest'],C) :- C =.. [move,southwest]. +getCommand(['se'],C) :- C =.. [move,southeast]. +getCommand(['southeast'],C) :- C =.. [move,southeast]. -getCommand(['take',X],C) :- C = [take,X]. -getCommand(['shoot',X],C) :- C = [shoot,X]. +getCommand(['take',X],C) :- C =.. [take,X]. +getCommand(['shoot',X],C) :- C =.. [shoot,X]. -getCommand(['l'],C) :- C = [look]. -getCommand(['look'],C) :- C = [look]. +getCommand(['l'],C) :- C =.. [look]. +getCommand(['look'],C) :- C =.. [look]. diff --git a/main.prolog b/main.prolog index 1dcd4df..ef23f4f 100644 --- a/main.prolog +++ b/main.prolog @@ -9,16 +9,26 @@ play :- init, + look, playLoop. playLoop :- prompt(Line), + evalLine(Line). + + +evalLine(Line) :- getCommand(Line,Command), Command, playLoop. +evalLine(_) :- + write('What?\n\n'), + playLoop. + + quit :- halt(0). |