Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- frame world;
- default x_coord is 0 and % initial values
- default y_coord is 0 and
- default monster_limit is 6 and
- default cellCoord is 9000.
- frame monster;
- default monster_x is null and
- default monster_y is null and
- default monster_state is alive.
- instance monster0 is a monster;
- monster_type is goblin.
- instance monster1 is a monster;
- monster_type is goblin.
- instance monster2 is a monster;
- monster_type is goblin.
- instance monster3 is a monster;
- monster_type is goblin.
- instance monster4 is a monster;
- monster_type is ogre.
- instance monster5 is a monster;
- monster_type is spider.
- frame key1;
- default key_x is null and
- default key_y is null.
- frame global; % can refer to slots without referring to global
- default world_extent is 5 and % 5 x 5 grid. Can change this
- default hero_x is 0 and
- default hero_y is 0 and
- default hero_health is 100 and
- default hero_name is 'Dr Graham Winstanley the Magnificent' and
- default hero_has_key is 0 and
- default number_n is 0 and
- default number_m is 0 and
- default cellCounter is 9000.
- action cleanse_world;
- cellCounter becomes 9000 and
- hero_x becomes 0 and
- hero_y becomes 0 and
- hero_health becomes 100 and
- for every M is an instance of monster do
- M`s monster_x becomes null and
- M`s monster_y becomes null and
- M`s monster_state becomes alive
- end for and
- number_n becomes 0 and
- number_m becomes 0 and
- key1`s key_y becomes null and
- key1`s key_x becomes null.
- action cleanse_world2;
- cellCounter becomes 9000 and
- hero_x becomes 0 and
- hero_y becomes 0 and
- for every M is an instance of monster do
- M`s monster_x becomes null and
- M`s monster_y becomes null and
- M`s monster_state becomes alive
- end for and
- hero_has_key becomes 0 and
- number_n becomes 0 and
- number_m becomes 0.
- action damage;
- hero_health becomes hero_health-20.
- action create_world; % main action
- do
- for A from 0 to world_extent^2 step world_extent % outer for
- do
- for X from 0 to world_extent-1
- do
- create_instance_name(X+A,Y) and % another action to create a name
- new_instance(Y,world) and % make the instance
- Y`s x_coord becomes X and % update the X coordinate
- Y`s y_coord becomes A/world_extent and % update the Y coordinate
- Y`s cellCoord becomes cellCounter and
- cellCounter becomes cellCounter+1
- end for
- end for .
- action create_instance_name(X,Y); % the create name action
- do
- number_atom(X,Z) and % make the number into an atom (type change)
- cat({'cell_',Z},Y,L). % concatenate the 2 atoms to make cell_0 (say)
- action create_world2; % main action
- do
- for A from 0 to world_extent^2 step world_extent % outer for
- do
- for X from 0 to world_extent-1
- do
- create_instance_name(X+A,Y) and % another action to create a name
- new_instance(Y,world) and % make the instance
- Y`s x_coord becomes X and % update the X coordinate
- Y`s y_coord becomes A/world_extent and % update the Y coordinate
- Y`s cellCoord becomes cellCounter and
- cellCounter becomes cellCounter+1
- end for
- end for .
- action create_instance_name(X,Y); % the create name action
- do
- number_atom(X,Z) and % make the number into an atom (type change)
- cat({'cell_',Z},Y,L). % concatenate the 2 atoms to make cell_0 (say)
- action move_north;
- do check that Current_tile is an instance of world
- whose x_coord is hero_x and
- whose y_coord is hero_y and
- check that Tile_north is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord+1 and
- hero_x becomes Tile_north`s x_coord and
- hero_y becomes Tile_north`s y_coord and
- write('hero ') and
- write(hero_x) and
- write(' , ') and
- write(hero_y) and
- draw_hero(Tile_north`s cellCoord,Current_tile`s cellCoord) and
- nl.
- action move_south;
- do check that Current_tile is an instance of world
- whose x_coord is hero_x and
- whose y_coord is hero_y and
- check that Tile_south is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord-1 and
- hero_x becomes Tile_south`s x_coord and
- hero_y becomes Tile_south`s y_coord and
- write('hero ') and
- write(hero_x) and
- write(' , ') and
- write(hero_y) and
- draw_hero(Tile_south`s cellCoord,Current_tile`s cellCoord) and
- nl.
- action move_east;
- do check that Current_tile is an instance of world
- whose x_coord is hero_x and
- whose y_coord is hero_y and
- check that Tile_east is an instance of world
- whose x_coord is Current_tile`s x_coord+1 and
- whose y_coord is Current_tile`s y_coord and
- hero_x becomes Tile_east`s x_coord and
- hero_y becomes Tile_east`s y_coord and
- write('hero ') and
- write(hero_x) and
- write(' , ') and
- write(hero_y) and
- draw_hero(Tile_east`s cellCoord,Current_tile`s cellCoord) and
- nl.
- action move_west;
- do check that Current_tile is an instance of world
- whose x_coord is hero_x and
- whose y_coord is hero_y and
- check that Tile_west is an instance of world
- whose x_coord is Current_tile`s x_coord-1 and
- whose y_coord is Current_tile`s y_coord and
- hero_x becomes Tile_west`s x_coord and
- hero_y becomes Tile_west`s y_coord and
- write('hero ') and
- write(hero_x) and
- write(' , ') and
- write(hero_y) and
- draw_hero(Tile_west`s cellCoord,Current_tile`s cellCoord) and
- nl.
- action printname;
- do write(hero_name) and
- nl.
- %make the monsters wander
- action generate_monsters_locations;
- do number_n becomes 0 and
- repeat
- do generate_locations(world_extent-1, number_n)
- and number_n becomes number_n+1
- until number_n is world`s monster_limit
- end repeat.
- action spawn_monster(X,Y,N);
- do number_atom(N,Z) and
- cat({'monster',Z},A,_) and
- write(A) and
- A`s monster_x becomes X and
- A`s monster_y becomes Y and
- nl and
- write(A`s monster_x) and
- nl and
- write(A`s monster_y) and
- nl.
- %Generate the key location in a random location, but not in 0,0
- action generate_key_location;
- do generate_key_location(world_extent-1).
- %Now spawn key1
- action spawn_key1(X,Y);
- key1`s key_x becomes X and
- key1`s key_y becomes Y.
- %monster movement
- %needs re-adapting for monster use
- action move_monsters;
- do for every M is an instance of monster
- do
- if M`s monster_state is alive then do
- random_numby(M) else do nl
- end if
- end for
- and
- nl.
- action wander(A,B);
- if A is 0 then do monster_move_north(B) else
- if A is 1 then do monster_move_south(B) else
- if A is 2 then do monster_move_east(B) else
- if A is 3 then do monster_move_west(B) else do nl
- end if end if end if end if
- and
- nl.
- action monster_move_north(A);
- do check that Current_tile is an instance of world
- whose x_coord is A`s monster_x and
- whose y_coord is A`s monster_y and
- check that Tile_north is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord+1 and
- A`s monster_x becomes Tile_north`s x_coord and
- A`s monster_y becomes Tile_north`s y_coord and
- write(A) and
- write(' ') and
- write(A`s monster_x) and
- write(' , ') and
- write(A`s monster_y) and
- nl.
- action monster_move_south(A);
- do check that Current_tile is an instance of world
- whose x_coord is A`s monster_x and
- whose y_coord is A`s monster_y and
- check that Tile_south is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord-1 and
- A`s monster_x becomes Tile_south`s x_coord and
- A`s monster_y becomes Tile_south`s y_coord and
- write(A) and
- write(' ') and
- write(A`s monster_x) and
- write(' , ') and
- write(A`s monster_y) and
- nl.
- action monster_move_east(A);
- do check that Current_tile is an instance of world
- whose x_coord is A`s monster_x and
- whose y_coord is A`s monster_y and
- check that Tile_east is an instance of world
- whose x_coord is Current_tile`s x_coord+1 and
- whose y_coord is Current_tile`s y_coord and
- A`s monster_x becomes Tile_east`s x_coord and
- A`s monster_y becomes Tile_east`s y_coord and
- write(A) and
- write(' ') and
- write(A`s monster_x) and
- write(' , ') and
- write(A`s monster_y) and
- nl.
- action monster_move_west(A);
- do check that Current_tile is an instance of world
- whose x_coord is A`s monster_x and
- whose y_coord is A`s monster_y and
- check that Tile_west is an instance of world
- whose x_coord is Current_tile`s x_coord-1 and
- whose y_coord is Current_tile`s y_coord and
- A`s monster_x becomes Tile_west`s x_coord and
- A`s monster_y becomes Tile_west`s y_coord and
- write(A) and
- write(' ') and
- write(A`s monster_x) and
- write(' , ') and
- write(A`s monster_y) and
- nl.
- % combat
- action combat(X);
- do for every M is an instance of monster
- do if M`s monster_state is alive and
- M`s monster_x is equal to hero_x and
- M`s monster_y is equal to hero_y then do
- if X is 0 then do
- update_status('you have found a monster') and
- nl
- else do
- update_status('a monster has found you') and
- nl
- end if
- and
- M`s monster_state becomes dead and
- cat({M,' has died'},C,_) and
- update_status(C) and
- nl
- else do
- nl
- end if
- end for.
- %check if we are on the door cell and if we have the key
- action check_door;
- if hero_x is 4 and
- hero_y is 4 and
- hero_has_key is 1 then do
- start2
- else if hero_x is 4 and
- hero_y is 4 and
- hero_has_key is 0 and
- key1`s key_x is not null then do
- update_status('You need the key to go up to the next level')
- else do
- nl
- end if
- end if.
- %check if we just found a key
- action check_key;
- if hero_x is key1`s key_x and
- hero_y is key1`s key_y then do
- hero_has_key becomes 1 and
- update_status('You found a key!') and
- key1`s key_x becomes null and
- key1`s key_y becomes null
- else do
- nl
- end if.
- %dangers in adjacent cells
- action check_for_dangers;
- do check that Current_tile is an instance of world
- whose x_coord is hero_x and
- whose y_coord is hero_y and
- if Tile_north is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord+1 then do
- nl and
- check_for_monster(Tile_north`s x_coord,Tile_north`s y_coord,'north')
- else nl
- end if and
- if Tile_south is an instance of world
- whose x_coord is Current_tile`s x_coord and
- whose y_coord is Current_tile`s y_coord-1 then do
- nl and
- check_for_monster(Tile_south`s x_coord,Tile_south`s y_coord,'south')
- else nl
- end if and
- if Tile_east is an instance of world
- whose x_coord is Current_tile`s x_coord+1 and
- whose y_coord is Current_tile`s y_coord then do
- nl and
- check_for_monster(Tile_east`s x_coord,Tile_east`s y_coord,'east')
- else nl
- end if and
- if Tile_west is an instance of world
- whose x_coord is Current_tile`s x_coord-1 and
- whose y_coord is Current_tile`s y_coord then do
- nl and
- check_for_monster(Tile_west`s x_coord,Tile_west`s y_coord,'west')
- else nl
- end if.
- action check_for_monster(X,Y,L);
- do for every M is an instance of monster
- do if M`s monster_state is alive and
- M`s monster_x is equal to X and
- M`s monster_y is equal to Y then do
- cat({'You hear footsteps to the ',L},Q,_) and
- update_status(Q) and
- write(Q) and nl
- else do nl
- end if
- end for.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement