-
Notifications
You must be signed in to change notification settings - Fork 0
Cartesian Desert
peterorme edited this page Feb 24, 2015
·
1 revision
Using a single room that appears to be a large area that you can move inside, and using coordinates to track the player and objects in that room. This is work in progress!
The main ideas are
- using a list of numbers like
{5, 14}
for x/y coordinates inside the room - being able to have a special rule book that triggers on certain locations
- being able to drop (some) items at a given coordinate and pick it up later
I've been using some utility extensions here, they are available in the i7/extensions repo on github.
Include Unit Testing by Peter Orme.
Include Flexible Logger by Peter Orme.
Chapter 1 - Cartesian Coordinates and rooms
Section 1 - Cartesian Coordinates
[
Rather than using a special kind for coordinates, I'm just going with a list of numbers,
implicitly using the first entry for x and the second for y.
]
[ we keep tab of things that have a list of numbers called coords, and also call those
things "coordinate-ready" ]
An object can be coordinate-ready.
Section 2 - Working with coordinates
to decide which number is the x coordinate of (T - a coordinate-ready thing):
decide on entry 1 of the coords of T.
to decide which number is the y coordinate of (T - a coordinate-ready thing):
decide on entry 2 of the coords of T.
to increment the x coordinate of (holder - a coordinate-ready object):
change the x coordinate of holder with 1;
to decrement the x coordinate of (holder - a coordinate-ready object):
change the x coordinate of holder with -1;
to increment the y coordinate of (holder - a coordinate-ready object):
change the y coordinate of holder with 1;
to decrement the y coordinate of (holder - a coordinate-ready object):
change the y coordinate of holder with -1;
to change the x coordinate of (holder - a coordinate-ready object) with (dx - a number):
let V be entry 1 of the coords of the holder;
remove entry 1 from the coords of the holder;
now V is V + dx;
add V at entry 1 in the coords of the holder;
to change the y coordinate of (holder - a coordinate-ready object) with (dy - a number):
let V be entry 2 of the coords of the holder;
remove entry 2 from the coords of the holder;
now V is V + dy;
add V at entry 2 in the coords of the holder;
to modify the coords of (holder - a coordinate-ready object) by (delta - a list of number):
change the x coordinate of holder with entry 1 of delta;
change the y coordinate of holder with entry 2 of delta;
Section 3 - The Player's Coords
The player has a list of number called coords. The player is coordinate-ready.
The coords of the player is {0, 0}.
Section 4 - Endless rooms
[
We could clearly imagine rooms that are cartesian maps that are NOT endless, but right now,
what we need are just "endless" x-y maps with rules that fire at specific locations
]
A room can be endless.
Section 5 - Going in a coordinate system
to update coords of (chosen holder - a coordinate-ready thing) by going (chosen direction - a direction):
if chosen direction is:
-- north:
increment the y coordinate of the player;
-- south:
decrement the y coordinate of the player;
-- east:
increment the x coordinate of the player;
-- west:
decrement the x coordinate of the player;
-- northwest:
modify the coords of the player by {-1, 1};
-- northeast:
modify the coords of the player by {1, 1};
-- southwest:
modify the coords of the player by {1, -1};
-- southeast:
modify the coords of the player by {-1, -1};
-- otherwise:
do nothing.
instead of going in an endless room (called chosen room):
if the noun is a direction:
let chosen direction be the noun;
update coords of the player by going chosen direction;
follow the grid rules for the chosen room;
try looking;
Section 6 - The grid rules
The grid rules are an object based rulebook.
Chapter 2 - Examples
the demo is a room.
the holding room is a room.
The Desert is a endless room. "Just sand.";
desert-holdings is a container in the holding room. It is scenery.
The desert has a container called stash;
The Oasis is a room. "Some palm trees and shade. Outside from the Oasis is just the desert.";
[You don't want to do this:
the desert is outside from the oasis.
Becaues then you can also go "in" to the oasis from the desert.
]
instead of going outside in the oasis:
now the player is in the desert;
now the coords of the player is {5, 0}.
instead of exiting in the oasis:
try going outside.
the player is in the desert.
the player is carrying an orange, an apple, a banana and a lemon.
The orange has a list of numbers called coords. The coords of the orange is {0, 0}.
The orange is coordinate-ready.
after dropping something in the desert:
if the noun is coordinate-ready:
now the noun is in the stash of desert;
now the coords of the noun are the coords of the player;
continue the action;
otherwise:
say "You drop [the noun] and it disappears into the sand.";
remove the noun from play;
a grid rule for the desert (this is the plain grid rule):
if the coords of the player is {5, 0}:
say "By jove! An oasis!";
now the player is in the oasis;
after looking in the desert:
let stuff here be a list of things;
repeat with T running through things in the stash of the desert:
if the coords of T is the coords of the player:
add T to the stuff here;
if stuff here is not empty:
say "You see [stuff here with indefinite articles].";
After deciding the scope of the player while the player is in the desert:
repeat with T running through things in the stash of the desert:
if the coords of T is the coords of the player:
place T in scope;
A rule for reaching inside the holding room: allow access.
A rule for reaching inside a container in the holding room:
debug "allowing access to a stash.";
allow access.
check taking something in the desert when the noun is in the stash of the desert:
continue the action;
Section 7 - tests
Include Checkpoints by Peter Orme.
Table of Checkpoints (continued)
topic assertion message
"orange-dropped" "[unless the orange is in the desert-holdings]fail[end if]" "The orange should be in the desert."
"has-orange" "[unless the player has the orange]fail[end if]" "The player should have the orange."
to perform asserts:
let expected be a list of numbers;
now expected is {2, 3};
assert that {2, 3} is expected ;
assert that {2, 3} is not {3, 2};
when play begins:
perform asserts;
report asserts;
test me with "drop orange / cpa orange-dropped / w / take orange / cpa orange-dropped / e / take orange / cpa has-orange"
~ category: All Examples