Last active
December 18, 2015 01:39
-
-
Save quad/5705722 to your computer and use it in GitHub Desktop.
SANKE THE SNAKE
By Brandon Ethakada & Tai Bell-Liu 10J
Ported Scott Robinson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program YearTenComputerSystemsProjectByBrandonEthakadaAndTaiBellLiu; | |
| uses ptccrt, ptcgraph; | |
| var keyz : string; | |
| selection,speed : integer; | |
| procedure InitIt; | |
| var gd, gm : integer; | |
| begin | |
| Gd := d8bit; | |
| Gm := m640x480; | |
| InitGraph(Gd, Gm, ''); | |
| if GraphResult <> grOk then Halt(1); | |
| end; | |
| function MsgYesNo(msgtext : string) : boolean; | |
| var choice : integer; | |
| begin | |
| choice:=0; {selects yes} | |
| setfillstyle(solidfill,7); {draws everything...} | |
| bar(160,200,480,280); | |
| settextstyle(2,horizdir,0); | |
| setcolor(black); | |
| outtextxy(180,220,msgtext); | |
| outtextxy(227,247,'Y E S'); | |
| outtextxy(380,247,'N O'); | |
| setcolor(white); | |
| rectangle(161,201,480,280); | |
| outtextxy(227,247,'Y'); | |
| outtextxy(380,247,'N'); | |
| rectangle(181,241,311,261); | |
| rectangle(331,241,461,261); | |
| setcolor(8); | |
| line(479,279,161,279); | |
| line(479,279,479,202); | |
| setcolor(black); | |
| line(480,280,160,280); | |
| line(480,280,480,201); | |
| setcolor(8); | |
| line(181,261,311,261); | |
| line(311,261,311,241); | |
| line(331,261,461,261); | |
| line(461,261,461,241); | |
| repeat | |
| setcolor(7); {shows users selection...} | |
| rectangle(180,240,312,262); | |
| rectangle(330,240,462,262); | |
| setcolor(black); | |
| rectangle(180+choice*150,240,312+choice*150,262); | |
| keyz:=readkey; {changes selection...} | |
| if keyz='K' then choice:=0; | |
| if keyz='M' then choice:=1; | |
| until (keyz='y') or (keyz='n') or (keyz=chr(13)); | |
| if keyz='y' then MsgYesNo:=True; {returns users selection...} | |
| if keyz='n' then MsgYesNo:=False; | |
| if keyz=chr(13) then | |
| begin | |
| if choice=0 then MsgYesNo:=True; | |
| if choice=1 then MsgYesNo:=False; | |
| end; | |
| end; | |
| procedure WinButton(x1, y1, x2, y2, style : integer); | |
| begin | |
| setfillstyle(solidfill,7); | |
| bar(x1,y1,x2,y2); | |
| setcolor(white); | |
| rectangle(x1,y1,x2,y2); | |
| setcolor(8); | |
| line(x1,y1+style*(y2-y1),x2,y1+style*(y2-y1)); | |
| line(x1+style*(x2-x1),y2,x1+style*(x2-x1),y1); | |
| end; | |
| procedure TitleScreen; | |
| begin | |
| winbutton(0,0,639,479,1); | |
| winbutton(9,451,629,469,0); | |
| settextstyle(3,horizdir,5); | |
| setcolor(black); | |
| outtextxy(145,140,'SANKE THE SNAKE'); | |
| settextstyle(3,horizdir,3); | |
| outtextxy(100,300,'By Brandon Ethakada & Tai Bell-Liu 10J'); | |
| settextstyle(2,horizdir,0); | |
| setcolor(black); | |
| outtextxy(20,455,'Press Enter To Continue.'); | |
| repeat until readkey=chr(13); | |
| end; | |
| procedure Manual; | |
| var top, left: integer; | |
| begin | |
| top:=getmaxy div 2 - 70; | |
| left:=getmaxx div 2 - 165; | |
| winbutton(left,top,getmaxx-left,getmaxy-top,1); | |
| winbutton(left+10,top+30,getmaxx-left-10,getmaxy-top-10,0); | |
| setfillstyle(solidfill,black); bar(left+11,top+31,getmaxx-left-11,getmaxy-top-11); | |
| setcolor(black); outtextxy(left+13,top+11,'SANKE THE SNAKE By Brandon Ethakada and Tai Bell-Liu'); | |
| setcolor(white); outtextxy(left+12,top+10,'SANKE THE SNAKE By Brandon Ethakada and Tai Bell-Liu'); | |
| outtextxy(175,top+37,'Use the arrow keys to turn your snake.'); | |
| outtextxy(175,top+47,'Eat those dots, they''re tasty.'); | |
| outtextxy(175,top+57,'Watch out for the dots, they''re walls.'); | |
| outtextxy(175,top+72,'Press ''p'' to pause the game.'); | |
| outtextxy(175,getmaxy-top-26,'Press any key to continue....'); | |
| setcolor(red); outtextxy(233,top+47,'red'); | |
| setcolor(yellow); outtextxy(280,top+57,'yellow'); | |
| repeat until keypressed; | |
| end; | |
| procedure speedy; | |
| begin | |
| setcolor(white); | |
| outtextxy(175,GetMaxy div 2,'Speed? (1 - 5)'); | |
| repeat | |
| case readkey of | |
| '1' : speed:=1; | |
| '2' : speed:=2; | |
| '3' : speed:=3; | |
| '4' : speed:=4; | |
| '5' : speed:=5; | |
| end; | |
| until (speed=1) or (speed=2) or (speed=3) or (speed=4) or (speed=5); | |
| setcolor(black); | |
| outtextxy(175,getmaxy div 2,'Speed? (1 - 5)'); | |
| end; | |
| procedure PlayIt; | |
| var SnakeX : array [1..100] of integer; | |
| SnakeY : array [1..100] of integer; | |
| pieces, AppleX, AppleY, SnakeLen, deleterX, deleterY, score : integer; | |
| TEMPKey, sscore, sspeed, cheat, question : string; | |
| GameOver, HIAB, dots, appleZ : boolean; | |
| begin {BEGIN} | |
| cleardevice; | |
| dots:=msgyesno('Would You Like Obstacles?'); | |
| repeat {REPEATS THE GAME UNTIL YOU QUIT} | |
| winbutton(0,0,639,479,1); {DRAWS STUFF} | |
| winbutton(14,14,465,465,0); | |
| setfillstyle(solidfill,0); | |
| bar(15,15,464,464); | |
| setcolor(white); | |
| outtextxy(476,436,'By:'); | |
| outtextxy(476,446,'Brandon Ethakada'); | |
| outtextxy(476,456,'& Tai Bell-Liu 10J'); | |
| outtextxy(476,101,'Score: 0'); | |
| outtextxy(476,91,'Speed:'); | |
| setcolor(black); | |
| outtextxy(475,435,'By:'); | |
| outtextxy(475,445,'Brandon Ethakada'); | |
| outtextxy(475,455,'& Tai Bell-Liu 10J'); | |
| outtextxy(475,100,'Score: 0'); | |
| outtextxy(475,90,'Speed:'); | |
| setcolor(white); | |
| settextstyle(3,horizdir,5); | |
| outtextxy(491,10,'SANKE'); | |
| outtextxy(491,50,'SNAKE'); | |
| settextstyle(3,horizdir,1); | |
| outtextxy(531,45,'THE'); | |
| setcolor(black); | |
| settextstyle(3,horizdir,5); | |
| outtextxy(490,9,'SANKE'); | |
| outtextxy(490,49,'SNAKE'); | |
| settextstyle(3,horizdir,1); | |
| outtextxy(530,44,'THE'); | |
| settextstyle(2,horizdir,0); | |
| keyz:='H'; {SETS DIRECTION TO UP} | |
| score:=0; | |
| snakeX[1]:=23; {SETS POSITIONS OF STARTING PIECES} | |
| snakeY[1]:=23; | |
| snakeX[2]:=23; | |
| snakeY[2]:=24; | |
| snakeX[3]:=23; | |
| snakeY[3]:=25; | |
| SnakeLen:=3; {SETS STARTING LENGTH OF SNAKE} | |
| gameover:=false; | |
| HIAB:=false; | |
| for pieces:=4 to 50 do {RESETS ALL THE PIECES} | |
| begin | |
| snakex[pieces]:=0; | |
| snakey[pieces]:=0; | |
| end; | |
| speedy; | |
| str(speed,sspeed); | |
| setcolor(white); | |
| outtextxy(476,91,'Speed: '+sspeed); | |
| setcolor(black); | |
| outtextxy(475,90,'Speed: '+sspeed); | |
| randomize; | |
| if dots then | |
| begin | |
| for pieces:=1 to 10 do | |
| begin | |
| repeat | |
| applex:=random(43)+1; {ADDS A WALL} | |
| appley:=random(43)+1; {JUST BORROWING APPLES VAR} | |
| until applex<>23; | |
| setfillstyle(solidfill,14); | |
| bar(15+applex*10,15+appley*10,24+applex*10,24+appley*10); | |
| end; | |
| end; | |
| repeat {ADDS AN APPLE} | |
| AppleX:=random(45); | |
| AppleY:=random(45); | |
| until getpixel(17+applex*10,17+appley*10)=black; | |
| setfillstyle(solidfill,4); | |
| bar(15+10*appleX,15+10*appleY,24+10*appleX,24+10*appleY); | |
| repeat {REPEATS UNTIL YOU DIE} | |
| delay(250 div speed); {DELAY BETWEEN MOVEMENT} | |
| nosound; | |
| if keypressed then {U PRESS A KEY...} | |
| begin | |
| TEMPkey:=readkey; | |
| if (tempkey='H') and (keyz<>'P') then keyz:='H'; | |
| if (tempkey='P') and (keyz<>'H') then keyz:='P'; | |
| if (tempkey='K') and (keyz<>'M') then keyz:='K'; | |
| if (tempkey='M') and (keyz<>'K') then keyz:='M'; | |
| if tempkey='p' then | |
| begin | |
| sound(10); | |
| delay(100); | |
| nosound; | |
| cheat:=''; | |
| repeat | |
| tempkey:=readkey; | |
| if tempkey<>'p' then cheat:=cheat+tempkey; | |
| sound(20); | |
| delay(50); | |
| nosound; | |
| until tempkey='p'; | |
| if cheat='hiab' then | |
| begin | |
| if HIAB then HIAB:=false else HIAB:=True; | |
| end; | |
| if cheat='fast1' then speed:=1; | |
| if cheat='fast2' then speed:=2; | |
| if cheat='fast3' then speed:=3; | |
| if cheat='fast4' then speed:=4; | |
| if cheat='fast5' then speed:=5; | |
| if cheat='long10' then snakelen:=10; | |
| if cheat='long20' then snakelen:=20; | |
| if cheat='long30' then snakelen:=30; | |
| if cheat='long40' then snakelen:=40; | |
| if cheat='eatfest' then appleZ:=true; | |
| setfillstyle(solidfill,7); | |
| bar(470,90,638,100); | |
| str(speed,sspeed); | |
| setcolor(white); | |
| outtextxy(476,91,'Speed: '+sspeed); | |
| setcolor(black); | |
| outtextxy(475,90,'Speed: '+sspeed); | |
| sound(10); | |
| delay(100); | |
| nosound; | |
| end; | |
| end; | |
| deleterX:=snakex[snakelen]; {SETS POS OF END OF SNAKE} | |
| deleterY:=snakeY[snakelen]; | |
| if keypressed then {WE DUNNO WHY WE NEED TWO} | |
| begin | |
| TEMPkey:=readkey; | |
| if (tempkey='H') and (keyz<>'P') then keyz:='H'; | |
| if (tempkey='P') and (keyz<>'H') then keyz:='P'; | |
| if (tempkey='K') and (keyz<>'M') then keyz:='K'; | |
| if (tempkey='M') and (keyz<>'K') then keyz:='M'; | |
| if tempkey='p' then repeat until readkey='p'; | |
| end; | |
| for pieces:=0 to snakelen-2 do {MAKES PIECES FOLLOW} | |
| begin | |
| snakex[snakelen-pieces]:=snakex[snakelen-pieces-1]; | |
| snakey[snakelen-pieces]:=snakey[snakelen-pieces-1]; | |
| end; | |
| if keyz='H' then SnakeY[1]:=SnakeY[1]-1; {MOVE UP} | |
| if keyz='P' then SnakeY[1]:=SnakeY[1]+1; {MOVE DOWN} | |
| if keyz='K' then SnakeX[1]:=SnakeX[1]-1; {MOVE LEFT} | |
| if keyz='M' then SnakeX[1]:=SnakeX[1]+1; {MOVE RIGHT} | |
| if (getpixel(17+snakex[1]*10,17+snakey[1]*10)<>black) and (getpixel(17+snakex[1]*10,17+snakey[1]*10)<>4) then | |
| begin | |
| GameOver:=true; | |
| question:='You Lose. Play Again?' | |
| end; | |
| for pieces:= 1 to snakelen do {DRAW THE SNAKE} | |
| begin | |
| setfillstyle(solidfill,8); | |
| bar(15+10*snakex[pieces],15+10*snakey[pieces],24+10*snakex[pieces],24+10*snakey[pieces]); | |
| end; | |
| if hiab=false then | |
| begin | |
| setfillstyle(solidfill,0); {DRAW OVER END OF TAIL} | |
| bar(15+deleterx*10,15+deletery*10,24+deleterx*10,24+deletery*10); | |
| end; | |
| if (SnakeX[1]=AppleX) and (SnakeY[1]=AppleY) then | |
| begin | |
| randomize; | |
| if dots then | |
| begin | |
| repeat | |
| AppleX:=random(43)+1; {NEW WALL PIECE} | |
| AppleY:=random(45)+1; | |
| until getpixel(17+applex*10,17+appley*10)=black; | |
| if appleZ then setfillstyle(solidfill,4) else setfillstyle(solidfill,14); | |
| bar(15+10*appleX,15+10*appleY,24+10*appleX,24+10*appleY); | |
| end; | |
| repeat | |
| AppleX:=random(45); | |
| AppleY:=random(45); | |
| until getpixel(17+applex*10,17+appley*10)=black; | |
| setfillstyle(solidfill,4); | |
| bar(15+10*appleX,15+10*appleY,24+10*appleX,24+10*appleY); | |
| snakelen:=snakelen+1; | |
| score:=score+10; | |
| sound(20); | |
| str(score,sscore); | |
| setfillstyle(solidfill,7); | |
| bar(470,100,638,110); | |
| setcolor(white); | |
| outtextxy(476,101,'Score: '+sscore); | |
| setcolor(black); | |
| outtextxy(475,100,'Score: '+sscore); | |
| if snakelen > 100 then | |
| begin | |
| gameover:=true; | |
| question:='You Win!!! Play Again?'; | |
| end; | |
| end; | |
| until GameOver; | |
| nosound; | |
| until MsgYesNo(question)=false; | |
| end; | |
| procedure menuscreen; | |
| begin | |
| winbutton(0,0,639,479,1); | |
| setcolor(black); | |
| rectangle(260,110+selection*60,640-260,110+selection*60+20); | |
| settextstyle(2,horizdir,0); | |
| outtextxy(295,175,'Play Game'); | |
| outtextxy(303,235,'Manual'); | |
| outtextxy(310,295,'Quit'); | |
| repeat | |
| keyz:=readkey; | |
| setcolor(7); | |
| rectangle(260,110+selection*60,640-260,110+selection*60+20); | |
| if keyz='H' then selection:=selection-1; | |
| if keyz='P' then selection:=selection+1; | |
| if selection<1 then selection:=1; | |
| if selection>3 then selection:=3; | |
| setcolor(black); | |
| rectangle(260,110+selection*60,640-260,110+selection*60+20); | |
| until keyz=chr(13); | |
| if selection=1 then PlayIt; | |
| if selection=2 then Manual; | |
| end; | |
| begin | |
| InitIt; | |
| TitleScreen; | |
| selection:=1; | |
| repeat | |
| repeat | |
| menuscreen; | |
| until selection=3; | |
| until MsgYesNo('Are You Sure You Want To Quit?'); | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment