[comp.sys.ibm.pc] independant incrementation in pascal

baileyc@tramp.Colorado.EDU (BAILEY CHRISTOPHER R) (09/19/89)

Help.  I'm writing a game program in pascal that uses a maze.  For
my maze, I have chosen to use randomly placed boxes, that DON'T
OVERLAP to create this maze.  I am doing this on for an IBM PC that
has a monochrome screen (25 rows, by 80 cols).  My original plan was
to draw 15 boxes per line (max dimensions are 5 x 5 chars, 80/5 = 16),
on like 4-5 lines (each line being 5 rows).  Just now typing this in
I have already found one flaw in my logic (the rows).  So, the big
question, how do I go about this???
    I already have a function that draws the boxes (using random
dimensions).  All of my random numbers are generated by a function
called dice(n) where n represents the number of sides the die has.
I am using 5 sides.
    My original thinking was along the lines of: get a set of random
coordinates (x and y being from 1-5 from dice(5)) for placement of the
box, get a set of random dimensions (x&y from 1-5 again) for the box
itself, and draw it.  Then, since there are 15 boxes on a "line," I
would do the procedure again, except that I would add 5 to the x
coordinate, then 10, 15, and so on, or basically, add 5 * the number of
the pass of the loop.  Then, when it is finished with that "line" of
boxes, it would generate more coords except that this time, the first
one would have 5 added to the y value to move it down a line, and the
second and thereafter would have 5 added to every y and 5, 10, 15, etc.
to each x.  Some box edges would touch on occasion, but that is ok.  The
main problems are, how to make sure the first boxes stay within their 5
line space (ie, a y coord of 5 and a y box dimension of 5 would put the
box down to row 10, and if the drawing processis reversed, it just goes
the other way, for a short y coordinate).  Also, I am not sure how to
create this intricate incrementation process in a reasonable amount of
code.  I don't want to create a million different variables for all 75
boxes.  (actually 300 variables, 4 values for each box)!
    Right now I have a procedure that runs two other procedures which
move to a random location (within above limits), and then draw a 
randomly sized box at that location.  Question is, how do I integrate
the above described incrementations independtly into the first main
procedure?????????????????????????????????????????????????????????????

  ________________________________                                   
 / "No, his mind is not for rent, \      University of Colorado  
|   to any god or government."     |           at Boulder       
|                         -RUSH    |________________________________ 

reeder@reed.UUCP (Doug Reeder) (09/20/89)

try:

xoffset := dice(5);
yoffset := dice(5);
width := dice(5);
height := dice(5);

if xoffset + width > 5 then width := 5 - xoffset;
if yoffset + height > 5 then height := 5 - yoffset;

x := basex + xoffset;
y := basey + yoffset;

-- 
Doug Reeder                         USENET: ...!tektronix!reed!reeder
Institute of Knowledge, Jinx        BITNET: reeder@reed.BITNET
"A blaster can point two ways."  from ARPA: tektronix!reed!reeder@berkeley.EDU
       -Salvor Hardin               Box 722 Reed College,Portland,OR 97202