All pastes #2061801 Raw Edit

Something

public text v1 · immutable
#2061801 ·published 2011-05-16 20:29 UTC
rendered paste body
frame world;
default x_coord is 0 and         % initial values
default y_coord is 0.


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.

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    % update the Y coordinate
    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_x) and
	write(' , ') and
	write(hero_y) 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_x) and
	write(' , ') and
	write(hero_y) 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_x) and
	write(' , ') and
	write(hero_y) 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_x) and
	write(' , ') and
	write(hero_y) and
	nl.

action wander(Randnum);
	do write('wandering') and
	nl and
	if Randnum is 0 then do move_north else
	if Randnum is 1 then do move_south else
	if Randnum is 2 then do move_east else
	if Randnum is 3 then do move_west else do nl
	end if
	end if
	end if
	end if and
	nl.