home *** CD-ROM | disk | FTP | other *** search
- program Snake(input,output);
-
- label
-
- StartSnake, ExitSnake;
-
- const
-
- os = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>';
- ys = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
-
- type
-
- strg1 = string[37];
-
- var
-
- p, d : array[1..2] of integer;
- z1 : strg1;
- a, b, c, di, high, i, n, pt, q, z : integer;
- r : real;
- ch : char;
- Quit, RoundOver : boolean;
- Monitor : char;
- Segment : integer;
-
- procedure SetupAndInitializeVariables;
-
- label
-
- ExitSetup;
-
- begin
- textmode(2); clrscr;
- randomize;
- n:=0;
- Quit:=false; RoundOver:=false;
- writeln(os,'Snake',ys);
- write('Enter Value for Delay (Q for Quit) : ');
- readln(z1);
- clrscr;
- if (z1='Q') or (z1='q') then
- begin
- Quit:=true;
- goto ExitSetup;
- end;
- if z1='' then z:=0
- else
- val(z1,z,q);
- a:=219; b:=177;
- c:=c+1;
- p[1]:=2010; p[2]:=1990;
- d[1]:=2; d[2]:=-2;
- r:=0.7;
- for i:=1 to 80 do
- begin
- mem[segment:(i-1)*2]:=178;
- mem[segment:(i-1)*2+3840]:=178;
- end;
- for i:=2 to 24 do
- begin
- mem[segment:(i-1)*160]:=178;
- mem[segment:158+((i-1)*160)]:=178;
- end;
- ExitSetup:
- gotoxy(1,1);
- end;
-
- procedure MoveUp;
- begin
- d[1]:=-160;
- end;
-
- procedure MoveLeft;
- begin
- d[1]:=-2;
- end;
-
- procedure MoveRight;
- begin
- d[1]:=2;
- end;
-
- procedure MoveDown;
- begin
- d[1]:=160;
- end;
-
- procedure PollKeybd;
- begin
- if keypressed then
- begin
- read(kbd,ch);
- if (ch=#27) and keypressed then
- begin
- read(kbd,ch);
- if ch = #72 then MoveUp;
- if ch = #75 then MoveLeft;
- if ch = #77 then MoveRight;
- if ch = #80 then MoveDown;
- end;
- end;
- end;
-
- procedure SnakeTwoChangeDirection;
-
- label
-
- ExitSTCD, point0, point1;
-
- begin
- if (mem[segment:p[2]+d[2]]=32) and (random<r) then goto ExitSTCD;
- if abs(d[2])=2 then
- begin
- d[2]:=160;
- goto point0;
- end;
- if abs(d[2])=160 then
- begin
- d[2]:=2;
- goto point0;
- end;
- if (mem[segment:p[2]]<2000) and (d[2]=160) then
- d[2]:=-d[2];
- goto point1;
- point0:
- di:=p[2] div 160;
- if di>12 then
- d[2]:=-d[2];
- point1:
- if mem[segment:d[2]+p[2]]<>32 then
- d[2]:=-d[2];
- ExitSTCD:
- end;
-
- procedure WinningTone;
- begin
- i:=200;
- while i<300 do
- begin
- sound(i);
- delay(55);
- i:=i+20;
- end;
- nosound; delay(110);
- for i:=1 to 2 do
- begin
- sound(400);
- delay(165);
- sound(600);
- delay(220);
- nosound;
- end;
- end;
-
- procedure LosingTone;
- begin
- i:=100;
- while i>50 do
- begin
- sound(i);
- delay(55);
- i:=i-5;
- end;
- for i:=1 to 8 do
- begin
- sound(37);
- delay(70);
- sound(39);
- delay(70);
- end;
- nosound;
- end;
-
- procedure UpdateSnakes;
-
- label
-
- PlayerLost, PlayerWon, PostScoreInfo, ExitUpdateSnakes;
-
- begin
- p[1]:=p[1] + d[1];
- p[2]:=p[2] + d[2];
- r:=r+(1-r)/20; n:=n+1;
- if mem[segment:p[1]]<>32 then goto PlayerLost;
- if mem[segment:p[2]]<>32 then goto PlayerWon;
- SnakeTwoChangeDirection;
- delay(z);
- goto ExitUpdateSnakes;
- PlayerLost:
- write('You Lose '); n:=n div 10; LosingTone; goto PostScoreInfo;
- PlayerWon:
- write('You Win '); WinningTone; goto PostScoreInfo;
- PostScoreInfo:
- delay(400);
- if n>high then high:=n;
- pt:=pt+n; i:=pt div c;
- writeln('Score: ',n,' Average Score: ',i,' High Score: ',high);
- RoundOver:=true;
- delay(2000);
- ExitUpdateSnakes:
- mem[segment:p[1]]:=a;
- mem[segment:p[2]]:=b;
- end;
-
- BEGIN
- pt:=0; c:=0; high:=0; n:=0;
- Monitor := 'c';
- Write('Do you have a color or monochrome monitor? (c,m) ');
- Readln(Monitor);
- if monitor in ['M','m'] then
- segment := $b000
- else
- segment := $b800;
- StartSnake:
- SetupAndInitializeVariables;
- if Quit=true then
- goto ExitSnake;
- repeat
- UpdateSnakes;
- PollKeybd;
- until RoundOver=true;
- goto StartSnake;
- ExitSnake:
- i:=pt div c;
- writeln('Average Score: ',i,' High Score: ',high);
- writeln('Thanksssss for playing Sssssnake!');
- end.