Designing A Program - IBM SC34-5764-01 Manual

Cics transaction server for vse/esa
Table of Contents

Advertisement

Programming Style and Techniques
then mouse = cat
otherwise
mouse = mouse + move
end
if mouse = hole then leave
if mouse = cat then leave
/*---------------------------------------------------*/
/* Cat turn
/*---------------------------------------------------*/
jump = random(1,spring)
if cat > mouse then do
Temp = cat - jump
if Temp < 1 then nop
else cat = Temp
end
else do
if cat + jump > len then nop
else cat = cat + jump
end
if cat = mouse then leave
end
/*------------------------------------------------------*/
/* Conclusion
/*------------------------------------------------------*/
call display
if cat = mouse then say "Cat wins"
else say "Mouse wins"
exit
/*------------------------------------------------------*/
/* Subroutine to display the state of play
/*
/* Input: CAT and MOUSE
/*
/* Design note: each position in the corridor occupies */
/* three character positions on the screen.
/*------------------------------------------------------*/
corridor = copies(" ",3*len)
corridor = overlay("O",corridor,3*hole-1) /* hole
if mouse ¬= len
then corridor = overlay("@",corridor,3*mouse-1)/* mouse */
corridor = overlay("(",corridor,3*cat-2)
corridor = overlay(")",corridor,3*cat)
say "
|"corridor"|"
return
Figure 46. CATMOUSE EXEC 2/2
Good job! Now, take a while to put your new skills into action, or continue reading.

Designing a Program

Still thinking about method, which is just as important as language, let us take another look at
CATMOUSE EXEC.
The program is about a cat and a mouse and their positions in a corridor. At some stage their positions will
have to be pictured on the screen. The whole thing is too complicated to think about all at once; the first
step is to break it down into:
v Main program: calculate their positions
v Display subroutine: display their positions.
Now let us look at main program. The user (who plays the mouse) will want to see where everybody is
before making a move. The cat will not. The next step is to break the main program down further, into:
92
CICS TS for VSE/ESA: REXX Guide
/* moves
/* reaches hole */
/* hits cat
/* cat tries to jump left */
/* hits wall */
/* cat tries to jump right */
/* hits wall */
/* corridor */
/* mouse in hole? */
/* cat
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents