:- dynamic at/2, i_am_at/1, i_am_holding/1. dump :- listing(at), listing(i_am_at), listing(at),listing(i_am_holding). /* Που βρίσκεται ο παίκτης */ i_am_at(pilot_room). /* Πως συνδέονται τα δωμάτια */ monopati(pilot_room, right , lobby). monopati(lobby, left , pilot_room). monopati(lobby, right , machine_room). monopati(machine_room, left , lobby). monopati(machine_room, up , escape_room). monopati(escape_room, down , machine_room). up :- go(up). down :- go(down). left :- go(left). right :- go(right). go(Direction) :- i_am_at(Here), monopati(Here, Direction, There), retract(i_am_at(Here)), asserta(i_am_at(There)),look,!. go(_) :- write('There is nothing that way.'). /* Σε ποιο δωμάτιο βρίσκονται τα διάφορα αντικείμενα*/ at(revolver, pilot_room). /* Πως μπορεί ο χρήστης να πάρει ένα αντικείμενο */ take(X) :- i_am_holding(X), write('You''re already holding it!'),nl,!; i_am_at(A), retract(at(X,A)), write('You picked up '), write(X), write('.'), nl, asserta(i_am_holding(X)),!. take(_):-write('I don''t see it here.'),nl. /* Πως να πετάξει κάτι που κρατάει */ drop(X) :- i_am_holding(X), i_am_at(Place), retract(i_am_holding(X)), asserta(at(X, Place)), write('Dropped '),write(X),write('.'),nl,!. drop(_) :- write('You aren''t holding it!'),nl. /* Με το look μπορεί να δεί τι υπάρχει στο δωμάτιο τριγύρω του. */ look :- i_am_at(Place), perigrafi(Place), nl. perigrafi(pilot_room) :- write('You are in the pilot room.'),nl,nl, write('The room consists of two chairs, one for the pilot'),nl, write('and one for the co-pilot. There is the control panel'),nl, write('as well as a communicating screen visible. You can'),nl, write('see a door on your right that leads to the lobby.'),nl. perigrafi(lobby) :- write('You are in the lobby. '),nl,nl, write('There are just a few chairs and a couch. '),nl, write('On the wall you can see a photo of your family.'),nl, write('You can see a door on your right that leads'),nl, write('to the machine room and a door on your left'),nl, write('that leads to the pilot room.'),nl. perigrafi(machine_room) :- write('You are in the machine room.'),nl,nl, write('You can see the engines of the spaceship. '),nl, write('They all seem sabotaged and about to blow up. '),nl, write('You can see a door on your left that leads to '),nl, write('the lobby and another one straight ahead that '),nl, write('leads to the escape room.'),nl. perigrafi(escape_room) :- write('You are in the escape room.'),nl,nl, write('There is an escape capsule that fits 3 people,'),nl, write('as well as a door behind you that leads to '),nl, write('the machine room.'),nl, write('TIP -- Type ''enter.'' to enter the escape capsule'). spaceship_map :- write(' ________ ___________________'),nl, write(' / | |escape |'),nl, write('| pilot | lobby |___/____|'),nl, write('| room / |machine |'),nl, write('| | / |'),nl, write(' \\________|___________|________|'),nl. enter:- i_am_at(escape_room), i_am_holding(revolver), write('You entered the escape capsule.'),nl, finito,!. enter:- i_am_at(escape_room), \+ i_am_holding(revolver), write('It would not be really wise to go out there unprotected.'),nl, write('How ''bout you take that revolver from the pilot room?'),nl,!,fail. enter:- \+ i_am_at(escape_room), write('You do not see anything to enter into.'),nl,!,fail. inventory:- \+ i_am_holding(_), write('You aren''t holding anything!'),nl. inventory:- i_am_holding(X), write('You are holding '),write(X),nl. start :- write('--- MISION I ---'),nl,nl,nl, write('The year is 2056. March 30th 2056.'),nl,nl, write('You are the pilot of a spaceship that delivers aluminum'),nl, write('from Venus to Mars.You are the only person on the spaceship, '),nl, write('when suddenly the machine stops working. Maybe you should'),nl, write('go to the machine room to see what the problem is.'),nl,nl,nl,nl, look. finito:- write('Mission Complete!'),db,!. db:-tell('db1.txt'),listing(i_am_holding),told. help :- instructions. instructions :- nl,nl,write('Must use standard Prolog Syntax.'),nl,nl, write('\t GAME START'),nl, write('\t start. -- start the game. '),nl,nl, write('\t MOVEMENT'),nl, write('\t up. -- go up.'),nl, write('\t down. -- go down.'),nl, write('\t left. -- go left.'),nl, write('\t right. -- go right.'),nl,nl, write('\t PICKING UP OBJECTS'),nl, write('\t take(object). -- pick up object.'),nl,nl, write('\t DROPPING OBJECTS'),nl, write('\t drop(object). -- drop object'),nl,nl, write('\t INVENTORY'),nl, write('\t inventory. -- shows your inventory.'),nl,nl, write('\t THE ROOM'),nl, write('\t look. -- describes the room.'),nl,nl, write('\t MAP'),nl, write('\t spaceship_map -- shows map.'),nl,nl, write('\t HELP'),nl, write('\t help. -- shows instructions.'),nl, write('\t instructions. -- shows instructions.'),nl,nl. :- instructions.