[net.games] skiing game for UNIX

stevans (11/03/82)

This message contains a skiing game written for UNIX in FORTRAN 77 with
a C program for generating the random number seed.  The basic ideas
were stolen from a similar program at Harvard University.
*
* THIS IS FILE SKI.6
*
.TH SKI 6 "University of Rochester"
.SH NAME
Ski \- skiing on the VAX
.SH SYNOPSIS
.B ski
.SH DESCRIPTION
All the fun and danger of skiing for morons of all IQs.
.PP
There are a few changes from version 1 to 2:
You can now go through the edge to the other side, instead of falling
off a cliff.  You can hop as well as jump, and the fire demon may stick
around a little while.  Scoring takes the distance you travel into
account, not just the number of levels, so you score better if you turn
a lot.
.PP
Changes from version 2 to 3:
The exhaust from your skis may melt the Snowman when you jump over him.
.PP
You are on an infinite
downhill slope, with trees, ice, bare ground, and the Snowman, a horrible
monster.  Each turn prints the next line downhill.  Also, you have put
your skis on backwards, so you can't see ahead, only behind.
.PP
However, you can turn to the right or left, jump through the air,
teleport through hyperspace, launch nuclear ICBMs, and cast spells to create
fire demons.  Since trees, ice, and bare ground occur in patches, you can
try to avoid them.
.PP
You ski until something bad happens to you, and your score is based on
how far you ski, how many jumps you make, how many Snowmen
have melted, and how healthy you are when are finished.
These are the things that you see on the slope behind you:
.PP
"I" - You.  This is where you are.
.PP
"A" - The Snowman.  He will grab you and beat you up if he is within one
space of you on the slope.  He can't move sideways through trees.
Stay away from him and he will eventually melt.  You can melt him
yourself with ICBMs, or sic a fire demon on him.
.PP
"." - Snow.  Completely safe to ski on.
.PP
"Y" - Trees.  They are very dangerous if you hit them.  Watch out.
.PP
" " - Bare ground.  If you try to ski on dirt, you could fall down.
.PP
"#" - Ice.  You might slip, and also you can't turn on ice.
.PP
"*" - An ICBM fired by you.
.PP
"D" - A fire demon you created.
.PP
These are your commands.  You can type any one when you have the "?" on the
right, or just hit a return to do nothing.  All commands must be entered in
lower-case letters:
.PP
R - Turn right.  If you were going straight down, this will make you go
one space to the right every turn, carrying you two meters per turn.
If you type "R" again, then you will go two spaces to the right every
turn.  Type "L" the next turn, and you will again be going one space to
the right every turn.  You can't turn when you are on ice, and if you
go off the edge, you come back on the other side.  You can turn a
maximum of five spaces per level.
.PP
L - Turn left.  The same as turning right, but opposite.
.PP
J - Jump.  When jumping, you don't enter commands for those levels you
jump over.  You can't
fall, hit trees, or get grabbed by the Snowman, but you might land
badly and get hurt.  If you jump over the Snowman, the exhaust from your
jet powered skis may melt him.
.PP
H - Hop.  Makes a hop in the air, which is the like a half jump.
.PP
T - Hyperspace teleport.  This moves you to somewhere else on the slope,
but you could materialize way up in the air and fall.
.PP
I - Launch ICBM with nuclear warhead.  If your backpack is working well,
an ICBM will be launched from it towards the Snowman, travelling at
three spaces per turn.  Launching ICBMs is dangerous.  If it is
launched and doesn't detect a Snowman, it self-destructs immediately,
but that can't hurt you.
.PP
D - Cast spell to create a fire demon.  If the alternate universes
decide to cooperate, a fire demon will appear somewhere on the slope,
and move to attack the Snowman at one space per turn.  If there is
no Snowman around, the demon will eventually get bored and go back
to demonland.  But, if you something goes wrong while casting this
spell, the demon might decide to go for you instead of the Snowman!
.PP
Send bugs and suggestions to Roy's Games, Inc., care of stevans.
.PP
Good luck, and happy skiing.
.SH AUTHOR
Mark Stevans at University of Rochester (allegra!rochester!stevans),
for Roy's Games, Inc..
.SH BUGS
None at present.
*
* THIS IS FILE SKI.C
*
main(argc,argv)
int argc;
char **argv;
{
    int x;
    char skistr[100],
         y[100];

    strncpy(skistr,"skiexec ",20);
    x=time(0) % 10000;
    sprintf(y,"%d",x);
    strncat(skistr,y,10);
    system(skistr);
}
*
* THIS IS FILE SKI.F
*
C                                    S K I !
C                                  VERSION 300
C                              BY ROY'S GAMES, INC.
C                            IN UNIX VAX11 FORTRAN 77
C
C CONCEPT TAKEN FROM SKI ON HARVARD'S PDP11
C
      COMMON/RANCOM/SEED,MAXSED,LEVEL,POS,DELPOS
      INTEGER SEED,MAXSED,LEVEL,POS,DELPOS
C
      INTEGER SPOS,IPOS,DPOS
      REAL PTREE(4),PICE(4),PGRO(4)
      REAL JMPCNT
      INTEGER RNDINT,SEVERE
      LOGICAL PROB
      CHARACTER*1 SNOW,TREE,MAN,GROUND,ICE,SNOMAN,ICBM,DEMON
      CHARACTER*1 SLOPE(65),LYNE(65),LYNE2(65)
      CHARACTER*1 CHAR
      CHARACTER*40 INJURY(8)
C
      DATA INJURY/'But you weren''t hurt at all.            ',
     1            'But you only got a few scratches.       ',
     2            'You got a concussion and bruises.       ',
     3            'You now have a broken arm.              ',
     4            'You have a broken arm and a broken leg. ',
     5            'You have four broken limbs and a cut!   ',
     6            'You broke every bone in your body!      ',
     7            'I''m afraid that you''re dead....         '/
      DATA SNOW,TREE,MAN,GROUND,ICE,SNOMAN,ICBM,DEMON
     1     /'.','Y','I',' ','#','A','*','D'/
C
C THE PROBABILITY CONSTANTS
C     THE FIRST CONTROLS HOW OFTEN NEW ONES WILL APPEAR WITH NOTHING ARO
C     THE SECOND CONTROLS EDGE GROWING
C     THE THIRD CONTROLS EDGE STABILITY AND GAP JOINING
C     THE FOURTH CONTROLS APPEARANCE OF HOLES IN ESTABLISHED AREAS
C
      DATA PTREE/   .5,  30.,  70., 95./
      DATA PICE /   .5,  30.,  70., 95./
      DATA PGRO /   .5,  30.,  70., 95./
C
C INITIALIZE
C
      CALL INIRAN
C
      LEVEL=1
      METERS=0
      POS=RNDINT(65)
      JUMP=-1
      JMPCNT=0.
      DELPOS=0
      SPOS=0
      IPOS=0
      DPOS=0
      NSMEN=0
      DO 10 I=1,65
      LYNE2(I)=SNOW
   10 CONTINUE
C
C CREATE THE SLOPE
C
   20 DO 30 I=1,65
      LYNE(I)=LYNE2(I)
      SLOPE(I)=LYNE(I)
   30 CONTINUE
C
C IF THERE IS NO SNOWMAN WE MAY CREATE ONE
C
      IF(SPOS.GT.0)GOTO 40
      IF(PROB(95.))GOTO 70
      SPOS=RNDINT(65)
      GOTO 50
C
C THE SNOWMAN MAY MELT
C
   40 IF(PROB(98.))GOTO 50
      SPOS=0
      NSMEN=NSMEN+1
      GOTO 70
C
C MOVE THE SNOWMAN
C
   50 IF(SPOS.GT.POS)GOTO 60
      IF(LYNE(SPOS+1).NE.TREE)SPOS=SPOS+1
      GOTO 70
C
   60 IF(LYNE(SPOS-1).NE.TREE)SPOS=SPOS-1
C
C MOVE THE ICBM
C
   70 IF(IPOS.LE.0)GOTO 90
      IF(SPOS.LE.0)GOTO 85
      IF(IPOS.GT.SPOS)GOTO 80
      IPOS=IPOS+3
      GOTO 90
C
   80 IPOS=IPOS-3
      GOTO 90
C
   85 IPOS=0
C
C MOVE THE DEMON
C
   90 IF(DPOS.LE.0)GOTO 110
      IF(SPOS.LE.0)GOTO 105
      IF(DPOS.GT.SPOS)GOTO 100
      DPOS=DPOS+1
      GOTO 110
C
  100 DPOS=DPOS-1
      GOTO 110
C
  105 IF(PROB(25.))DPOS=0
C
C PUT YOU, THE SNOWMAN, THE ICBM, AND THE DEMON ON THE SLOPE
C
  110 SLOPE(POS)=MAN
      IF(SPOS.GT.0)SLOPE(SPOS)=SNOMAN
      IF(IPOS.GT.0)SLOPE(IPOS)=ICBM
      IF(DPOS.GT.0)SLOPE(DPOS)=DEMON
C
C WRITE THE SLOPE OUT
C
      WRITE(6,120)LEVEL,SLOPE
  120 FORMAT(I4,X,65A1,X,$)
C
C SEE IF THE SNOWMAN GETS MELTED
C
      IF(IPOS.LE.0)GOTO 135
      IF(IABS(SPOS-IPOS).GT.2)GOTO 135
      IPOS=0
      GOTO 136
C
  135 IF(DPOS.LE.0)GOTO 138
      IF(IABS(SPOS-DPOS).GT.1)GOTO 138
      DPOS=0
  136 SPOS=0
      NSMEN=NSMEN+1
C
C IF WE ARE JUMPING, DON'T READ IN ANY COMMANDS OR LET US HIT TREES,
C SLIP ON ICE, GET GRABBED BY THE SNOWMAN, OR FALL ON THE GROUND
C
  138 IF(JUMP.GT.0)GOTO 242
C
      IF(JUMP.EQ.0.AND.PROB(5.))GOTO 420
      IF(LYNE(POS).EQ.TREE)GOTO 320
      IF(LYNE(POS).EQ.GROUND.AND.PROB(20.))GOTO 360
      IF(LYNE(POS).EQ.ICE.AND.PROB(5.))GOTO 380
      IF(SPOS.GT.0.AND.IABS(SPOS-POS).LE.1)GOTO 400
C
  140 WRITE(6,150)
  150 FORMAT('? ',$)
C
      READ(5,160)CHAR
  160 FORMAT(A1)
      IF(CHAR.EQ.' ')GOTO 244
      IF(CHAR.EQ.'r')GOTO 190
      IF(CHAR.EQ.'l')GOTO 200
      IF(CHAR.EQ.'h')GOTO 205
      IF(CHAR.EQ.'j')GOTO 210
      IF(CHAR.EQ.'t')GOTO 220
      IF(CHAR.EQ.'i')GOTO 230
      IF(CHAR.EQ.'d')GOTO 240
      GOTO 244
C
C RIGHT
C
  190 IF(LYNE(POS).NE.ICE.AND.DELPOS.LE.5)DELPOS=DELPOS+1
      GOTO 244
C
C LEFT
C
  200 IF(LYNE(POS).NE.ICE.AND.DELPOS.GE.-5)DELPOS=DELPOS-1
      GOTO 244
C
C HOP
C
  205 CALL SNDBEL
      JUMP=RNDINT(4)
      JMPCNT=JMPCNT+.5
      GOTO 244
C
C JUMP
C
  210 CALL SNDBEL
      JUMP=RNDINT(5)+3
      JMPCNT=JMPCNT+1.
      GOTO 244
C
C TELEPORT
C
  220 IF(PROB(10.))GOTO 440
      POS=RNDINT(65)
      GOTO 244
C
C LAUNCH ICBM
C
  230 IF(PROB(40.))GOTO 460
      IPOS=POS
      GOTO 244
C
C INCANT DEMON
C
  240 IF(PROB(15.))GOTO 480
      DPOS=RNDINT(65)
      GOTO 244
C
C HE IS JUMPING, SO FINISH THE LINE FOR HIM
C
  242 WRITE(6,130)
  130 FORMAT(' ')
C
C OUR JET POWERED SKIS MAY MELT THE SNOWMAN
C
      IF(SPOS.LE.0.OR.IABS(SPOS-POS).GT.1)GOTO 244
      IF(PROB(80.))GOTO 244
      SPOS=0
      NSMEN=NSMEN+1
C
C GO TO THE NEXT LEVEL, MOVE THE MAN
C
  244 LEVEL=LEVEL+1
      METERS=METERS+1+IABS(DELPOS)
      POS=MREF(POS+DELPOS)
      JUMP=JUMP-1
C
C GENERATE THE NEW SLOPE
C
  250 DO 310 I=1,65
      LYNE2(I)=LYNE(I)
      NTREE=0
      NICE=0
      NGRO=0
      IF(LYNE(I).EQ.TREE)NTREE=NTREE+1
      IF(LYNE(I).EQ.ICE)NICE=NICE+1
      IF(LYNE(I).EQ.GROUND)NGRO=NGRO+1
      IF(I.LE.1)GOTO 260
      IF(LYNE(I-1).EQ.TREE)NTREE=NTREE+1
      IF(LYNE(I-1).EQ.ICE)NICE=NICE+1
      IF(LYNE(I-1).EQ.GROUND)NGRO=NGRO+1
  260 IF(I.GE.65)GOTO 270
      IF(LYNE(I+1).EQ.TREE)NTREE=NTREE+1
      IF(LYNE(I+1).EQ.ICE)NICE=NICE+1
      IF(LYNE(I+1).EQ.GROUND)NGRO=NGRO+1
C
C GENERATE THE SURFACE AT THIS POINT
C
  270 IF(PROB(PTREE(NTREE+1)))GOTO 280
      IF(PROB(PICE(NICE+1)))GOTO 290
      IF(PROB(PGRO(NGRO+1)))GOTO 300
      LYNE2(I)=SNOW
      GOTO 310
C
  280 LYNE2(I)=TREE
      GOTO 310         
C
  290 LYNE2(I)=ICE
      GOTO 310
C
  300 LYNE2(I)=GROUND
  310 CONTINUE
      GOTO 20
C
C HIT A TREE
C
  320 CALL SNDBEL
      WRITE(6,330)
  330 FORMAT(//'Oh, no!  You hit a tree!  ',$)
      SEVERE=RNDINT(6)+2
      GOTO 500       
C
C FELL ON GROUND
C
  360 CALL SNDBEL
      WRITE(6,370)
  370 FORMAT(//'You fell on the ground!  ',$)
      SEVERE=RNDINT(6)+1
      GOTO 500
C
C SLIPPED ON ICE
C
  380 CALL SNDBEL
      WRITE(6,390)
  390 FORMAT(//'Ooops!  You slipped on the ice!  ',$)
      SEVERE=RNDINT(6)
      GOTO 500
C
C SNOWMAN GETS HIM
C
  400 CALL SNDBEL
      WRITE(6,410)
  410 FORMAT(//'Help!  The Snowman''s got you!  ',$)
      SEVERE=RNDINT(6)+2
      GOTO 500
C
C BAD LANDING AT END OF JUMP
C
  420 CALL SNDBEL
      WRITE(6,430)
  430 FORMAT(//'Whoops!  A bad landing!  ',$)
      SEVERE=RNDINT(6)+1
      GOTO 500
C
C FAILED TELEPORT
C
  440 CALL SNDBEL
      WRITE(6,450)
  450 FORMAT(//'You materialized 25 feet in the air!  ',$)
      SEVERE=RNDINT(6)
      GOTO 500
C
C BAD ICBM LAUNCH
C
  460 CALL SNDBEL
      WRITE(6,470)
  470 FORMAT(//'Nuclear blast in your backpack!  ',$)
      SEVERE=RNDINT(6)+2
      GOTO 500
C
C BAD CREATE DEMON SPELL
C
  480 CALL SNDBEL
      WRITE(6,490)
  490 FORMAT(//'Bad spell -- the demon grabs you!  ',$)
      SEVERE=RNDINT(6)+1
C
  500 WRITE(6,510)INJURY(SEVERE)
  510 FORMAT(A40)
C
      ISCORE=320+METERS+IFIX(JMPCNT*20.)+NSMEN*100-SEVERE*40
C
      WRITE(6,520)METERS,JMPCNT,NSMEN,ISCORE
  520 FORMAT('You skiied',I5,' meters with',F5.1,' jumps and melted',
     1                I3,' Snowmen.'/
     2       'Your score for this run is',I6,'.')
      STOP
      END


      SUBROUTINE SNDBEL
      INTEGER BELCHR
      DATA BELCHR/7/
C
C      WRITE(6,10)BELCHR
C   10 FORMAT(R1,$)
      RETURN
      END


      INTEGER FUNCTION MREF(IREF)
C
      DATA LYNSIZ/65/
C
      MREF=MOD(IREF-1,LYNSIZ)+1
      IF(MREF.LT.1)MREF=MREF+LYNSIZ
      RETURN
      END


      SUBROUTINE INIRAN
C
      COMMON/RANCOM/SEED,MAXSED,LEVEL,POS,DELPOS
      INTEGER SEED,MAXSED,LEVEL,POS,DELPOS
C
      CHARACTER*4 TIME
      EQUIVALENCE (SEED,TIME)
C
      MAXSED=10000
      CALL GETARG(1,TIME)
      SEED=MOD(IABS(SEED),MAXSED)
      RETURN
      END

      LOGICAL FUNCTION PROB(X)
      REAL X
      INTEGER RNDINT
C
      PROB=(RNDINT(10000)/100.).LE.X
      RETURN
      END


      INTEGER FUNCTION RNDINT(LIMIT)
      INTEGER LIMIT
C
      COMMON/RANCOM/SEED,MAXSED,LEVEL,POS,DELPOS
      INTEGER SEED,MAXSED,LEVEL,POS,DELPOS
C
      INTEGER MOD
C
      RNDINT=MOD(SEED,LIMIT)+1
      SEED=SEED*17+LEVEL+POS+DELPOS+7193
      SEED=MOD(SEED,MAXSED)
C
      RETURN
      END