Current area: HOME ->

Zip File view

Yeakisen's Snake v1.0


This page allows you to view the contents of a file contained inside a ZIP archive available at Programmer's Heaven. This means you can view the code and find what you need from it without having to download the ZIP file first. If the file contains source code for a language we recognize, we have syntax highlighted it.

Filename displayed: YS\YS.pas
Found in file: 54787.zip

Download: MyDeveloper Tools for VS.NET 2.10 MyDeveloper Tools (formerly known as MySQL Developer Tools) is a powerful add-in designed to simplify the MySQL database application development process. It integrates into Visual Studio, making all ...
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                            !Yeakisen's Snake!                              //
//                       Yeakisen Productions (2007)                          //
//                               Main Source                                  //
//                     Written by Matthew Gianfrancesco                       //
//                            December 11, 2007                               //
//                       Completed December 27, 2007                          //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
PROGRAM YS;

USES
    YSCG,YSKB;

TYPE
    Coordinate = RECORD
        X,Y:Smallint;
        END;

VAR
    Yp_Logo, Menu_Start, Menu_Score, Menu_Quit,
    Menu_Title, Menu_Down, Menu_Up:YSImage;
    GameScreen:(Intro,Menu,MenuScore,LevelBegin,
                InGame,InGameOptions,InGameEnd);
    QuitTrigger, ScoreDraw:Boolean;
    MenuSelect, SnakeGrowth, Level, Timer, Score, FoodCol, InGameSelect,
    InGameGlobect:Integer;
    Keypressed, Initial1, Initial2, Initial3, InitialChange, LetterChange,
    CurrentInitial:Byte;
    SnakeDir:(Up,Down,Left,Right);
    Snake:ARRAY[0..150]OF Coordinate;
    Food:Coordinate;
    ScoreFile:Text;
    HighScores:ARRAY[0..9]OF Integer;
    ScoreNames:ARRAY[0..9]OF String;


PROCEDURE InitiateYS;
    VAR
    Counter:Integer;
    BEGIN
    GameScreen:=Intro;
    QuitTrigger:=FALSE;
    Assign(ScoreFile,'Scores.dat');
    Reset(ScoreFile);
    FOR Counter:=0 TO 9 DO
        BEGIN
        Readln(ScoreFile,HighScores[Counter]);
        Readln(ScoreFile,ScoreNames[Counter]);
        END;
    Close(ScoreFile);
    InitYSCG;
    InitYSKB;
    Yp_Logo:=LoadImage('YSIs\YP_LOGO.YSI');
    Menu_Title:=LoadImage('YSIs\TITLE.YSI');
    Menu_Start:=LoadImage('YSIs\START.YSI');
    Menu_Score:=LoadImage('YSIs\SCORE.YSI');
    Menu_Quit:=LoadImage('YSIs\QUIT.YSI');
    Menu_Down:=LoadImage('YSIs\DOWNARROW.YSI');
    Menu_Up:=LoadImage('YSIs\UPARROW.YSI');
    MenuSelect:=1;
    DrawColor(FALSE,ColBlack);
    Pause(3000);
    DrawImage(2,7,Yp_Logo);
    Pause(5500);
    ClearScreen;
    Pause(1000);
    END;

PROCEDURE InitiateMenu;
    BEGIN
    GameScreen:=Menu;
    DrawImage(2,1,Menu_Title);
    DrawImage(13,9,Menu_Up);
    DrawImage(13,21,Menu_Down);
    SetXY(30,49);
    DrawColor(TRUE,ColCyan);
    Write('Programmed By : Matthew Gianfrancesco');
    END;

PROCEDURE FoodCollisionDetection;
    VAR
    SnakeCounter:Integer;
    SnakeCollision:Boolean;
    BEGIN
    Random(30);
    Random(30);
    REPEAT
        SnakeCollision:=FALSE;
        Food.X:=Random(28)+1;
        Food.Y:=Random(17)+2;
        FOR SnakeCounter:=0 TO SnakeGrowth DO
            BEGIN
            IF(Food.X=Snake[SnakeCounter].X)AND(Food.Y=Snake[SnakeCounter].Y)
                THEN
                SnakeCollision:=TRUE;
            END;
    UNTIL(SnakeCollision=FALSE);
    END;

PROCEDURE KeyboardMenu;
    BEGIN
    IF(GameScreen=Menu)THEN
        BEGIN
        IF(Keypressed=KeyUpArrow)
            THEN
            MenuSelect:=MenuSelect-1;
        IF(Keypressed=KeyDownArrow)
            THEN
            MenuSelect:=MenuSelect+1;
        IF(Keypressed=KeyEnter)THEN
            BEGIN
            CASE MenuSelect OF
            1BEGIN
                GameScreen:=LevelBegin;
                Level:=1;
                Timer:=0;
                Score:=0;
                FoodCol:=0;
                DrawColor(FALSE,ColBlack);
                ClearScreen;
                END;
            2BEGIN
                GameScreen:=MenuScore;
                ScoreDraw:=FALSE;
                DrawColor(FALSE,ColBlack);
                ClearScreen;
                keypressed:=0;
                END;
            3BEGIN
                QuitTrigger:=TRUE;
                END;
            END;
            END;
        IF(MenuSelect < 1)
            THEN
            MenuSelect:=3;
        IF(MenuSelect > 3)
            THEN
            MenuSelect:=1;
        END;
    END;

PROCEDURE KeyboardInGame;
    VAR
    Counter:Integer;
    BEGIN
    IF(GameScreen=InGame)THEN
        BEGIN
        IF(Keypressed=KeyUpArrow)THEN
            BEGIN
            IF NOT(SnakeDir=Down)
                THEN
                SnakeDir:=Up;
            END;
        IF(Keypressed=KeyDownArrow)THEN
            BEGIN
            IF NOT(SnakeDir=Up)
                THEN
                SnakeDir:=Down;
            END;
        IF(Keypressed=KeyLeftArrow)THEN
            BEGIN
            IF NOT(SnakeDir=Right)
                THEN
                SnakeDir:=Left;
            END;
        IF(Keypressed=KeyRightArrow)THEN
            BEGIN
            IF NOT(SnakeDir=Left)
                THEN
                Snakedir:=Right;
            END;
        IF(Keypressed=KeyEnter)THEN
            BEGIN
            DrawColor(FALSE,ColBlack);
            FOR Counter:=0 TO 29 DO
                BEGIN
                DrawPixel(Counter,0);
                END;
            InGameSelect:=1;
            InGameGlobect:=3;
            ClearInput;
            Keypressed:=0;
            GameScreen:=InGameOptions;
            END;
        END;
    END;

PROCEDURE KeyboardInGameOptions;
    VAR
    Counter:Integer;
    BEGIN
    IF(GameScreen=InGameOptions)THEN
        BEGIN
        IF(Keypressed=KeyUpArrow)
            THEN
            InGameSelect:=InGameSelect-1;
        IF(Keypressed=KeyDownArrow)
            THEN
            InGameSelect:=InGameSelect+1;
        IF(InGameSelect<1)
            THEN
            InGameSelect:=2;
        IF(InGameSelect>2)
            THEN
            InGameSelect:=1;
        IF(Keypressed=KeyEnter)THEN
            BEGIN
            IF(InGameSelect=1)THEN
                BEGIN
                DrawColor(FALSE,ColBlack);
                FOR Counter:=0 TO 29 DO
                    BEGIN
                    DrawPixel(Counter,0);
                    END;
                GameScreen:=InGame;
                END;
            IF(InGameSelect=2)THEN
                BEGIN
                DrawColor(FALSE,ColBlack);
                ClearScreen;
                ClearInput;
                InitiateMenu;
                Exit;
                END;
            END;
        END;
    END;

PROCEDURE KeyboardMenuScore;
    BEGIN
    IF(GameScreen=MenuScore)THEN
        BEGIN
        IF(Keypressed=KeyEnter)THEN
            BEGIN
            DrawColor(FALSE,ColBlack);
            ClearScreen;
            Keypressed:=0;
            InitiateMenu;
            Exit;
            END;
        END;
    END;

FUNCTION GetInitial(Initial:Byte):String;
    BEGIN
    CASE Initial OF
    1:Result:='A';
    2:Result:='B';
    3:Result:='C';
    4:Result:='D';
    5:Result:='E';
    6:Result:='F';
    7:Result:='G';
    8:Result:='H';
    9:Result:='I';
    10:Result:='J';
    11:Result:='K';
    12:Result:='L';
    13:Result:='M';
    14:Result:='N';
    15:Result:='O';
    16:Result:='P';
    17:Result:='Q';
    18:Result:='R';
    19:Result:='S';
    20:Result:='T';
    21:Result:='U';
    22:Result:='V';
    23:Result:='W';
    24:Result:='X';
    25:Result:='Y';
    26:Result:='Z';
    END;
    END;

PROCEDURE WriteScores;
    VAR
    Name:String;
    Counter,Position:Integer;
    BEGIN
    Name:=GetInitial(Initial1)+GetInitial(Initial2)+GetInitial(Initial3);
    Position:=10;
    FOR Counter:=9 DOWNTO 0 DO
        BEGIN
        IF(Score>HighScores[Counter])
            THEN
            Position:=Counter;
        END;
    IF(Position<10)THEN
        BEGIN
        FOR Counter:=9 DOWNTO Position DO
            BEGIN
            IF(Counter=Position)THEN
                BEGIN
                HighScores[Counter]:=Score;
                ScoreNames[Counter]:=Name;
                END
            ELSE
                BEGIN
                HighScores[Counter]:=HighScores[Counter-1];
                ScoreNames[Counter]:=ScoreNames[Counter-1];
                END;
            END;
        Assign(ScoreFile,'Scores.dat');
        Rewrite(ScoreFile);
        FOR Counter:=0 TO 9 DO
            BEGIN
            Writeln(ScoreFile,HighScores[Counter]);
            Writeln(ScoreFile,ScoreNames[Counter]);
            END;
        Close(ScoreFile);
        END;
    END;

PROCEDURE KeyboardInGameEnd;
    BEGIN
    If(GameScreen=InGameEnd)THEN
        BEGIN
        IF(Keypressed=KeyUpArrow)THEN
            BEGIN
            IF(CurrentInitial=1)
                THEN
                Initial1:=Initial1-1;
            IF(CurrentInitial=2)
                THEN
                Initial2:=Initial2-1;
            IF(CurrentInitial=3)
                THEN
                Initial3:=Initial3-1;
            END;
        IF(Keypressed=KeyDownArrow)THEN
            BEGIN
            IF(CurrentInitial=1)
                THEN
                Initial1:=Initial1+1;
            IF(CurrentInitial=2)
                THEN
                Initial2:=Initial2+1;
            IF(CurrentInitial=3)
                THEN
                Initial3:=Initial3+1;
            END;
        If(Keypressed=KeyLeftArrow)
            THEN
            CurrentInitial:=CurrentInitial-1;
        IF(Keypressed=KeyRightArrow)
            THEN
            CurrentInitial:=CurrentInitial+1;
        IF(Keypressed=KeyEnter)THEN
            BEGIN
            WriteScores;
            DrawColor(FALSE,ColBlack);
            ClearScreen;
            Keypressed:=0;
            InitiateMenu;
            Exit;
            END;
        IF(Initial1<1)
            THEN
            Initial1:=26;
        IF(Initial1>26)
            THEN
            Initial1:=1;
        IF(Initial2<1)
            THEN
            Initial2:=26;
        IF(Initial2>26)
            THEN
            Initial2:=1;
        IF(Initial3<1)
            THEN
            Initial3:=26;
        IF(Initial3>26)
            THEN
            Initial3:=1;
        IF(CurrentInitial<1)
            THEN
            CurrentInitial:=3;
        IF(CurrentInitial>3)
            THEN
            CurrentInitial:=1;
        END;
    END;

PROCEDURE DrawMenu;
    BEGIN
    CASE MenuSelect OF
    1:DrawImage(4,13,Menu_Start);
    2:DrawImage(4,13,Menu_Score);
    3:DrawImage(4,13,Menu_Quit);
    END;
    END;

PROCEDURE DrawMenuScore;
    VAR
    Counter:Integer;
    BEGIN
    If(ScoreDraw=FALSE)THEN
        BEGIN
        SetXY(42,5);
        Write('SCORES');
        FOR Counter:=0 TO 9 DO
            BEGIN
            SetXY(37,8+3*Counter);
            Writeln(Counter+1:2,' : ',ScoreNames[Counter],' : ',HighScores[Counter]);
            END;
        ScoreDraw:=TRUE;
        END;
    END;

PROCEDURE DrawInGame;
    VAR
    DrawCounter,SnakeCounter,ScoreKeep,Counter:Integer;
    BEGIN
    FOR SnakeCounter:=SnakeGrowth DOWNTO 0 DO
        BEGIN
        Snake[SnakeCounter+1]:=Snake[SnakeCounter];
        END;
    DrawColor(FALSE,ColBlack);
    FOR SnakeCounter:=SnakeGrowth TO 150 DO
        BEGIN
        DrawPixel(Snake[SnakeCounter].X,Snake[SnakeCounter].Y);
        END;
    CASE SnakeDir OF
    Up   :Snake[0].Y:=Snake[0].Y-1;
    Down :Snake[0].Y:=Snake[0].Y+1;
    Left :Snake[0].X:=Snake[0].X-1;
    Right:Snake[0].X:=Snake[0].X+1;
    END;
    IF(Snake[0].X=Food.X)AND(Snake[0].Y=Food.Y)THEN
        BEGIN
        SnakeGrowth:=SnakeGrowth+1;
        FoodCol:=FoodCol+1;
        IF(SnakeGrowth>150)
            THEN
            SnakeGrowth:=150;
        IF(FoodCol>150)
            THEN
            FoodCol:=150;
        ScoreKeep:=(30*Level)-Timer;
        IF(ScoreKeep<0)
            THEN
            ScoreKeep:=0;
        Score:=Score+ScoreKeep;
        Timer:=0;
        FoodCollisionDetection;
        CASE FoodCol OF
        0..12:Level:=1;
        13..24:Level:=2;
        25..45:Level:=3;
        46..70:Level:=4;
        71..92:Level:=5;
        93..102:Level:=6;
        103..114:Level:=7;
        115..125:Level:=8;
        126..135:Level:=9;
        136..150:Level:=10;
        END;
        END;
    IF(Snake[0].X=0)OR(Snake[0].X=29)OR(Snake[0].Y=1)OR(Snake[0].Y=24)THEN
        BEGIN
        DrawColor(FALSE,ColRed);
        FOR DrawCounter:=0 TO SnakeGrowth DO
            BEGIN
            DrawPixel(Snake[DrawCounter].X,Snake[DrawCounter].Y);
            END;
        Pause(2000);
        DrawColor(FALSE,ColBlack);
        ClearInput;
        FOR Counter:=0 TO 29 DO
            BEGIN
            DrawPixel(Counter,0);
            END;
        Initial1:=1;
        Initial2:=1;
        Initial3:=1;
        CurrentInitial:=1;
        GameScreen:=InGameEnd;
        Exit;
        END;
    FOR SnakeCounter:=SnakeGrowth DOWNTO 1 DO
        BEGIN
        IF(Snake[0].X=Snake[SnakeCounter].X)AND(Snake[0].Y=Snake[SnakeCounter].Y)THEN
            BEGIN
            DrawColor(FALSE,ColRed);
            FOR DrawCounter:=0 TO SnakeGrowth DO
                BEGIN
                DrawPixel(Snake[DrawCounter].X,Snake[DrawCounter].Y);
                END;
            Pause(2000);
            DrawColor(FALSE,ColBlack);
            ClearInput;
            FOR Counter:=0 TO 29 DO
                BEGIN
                DrawPixel(Counter,0);
                END;
            Initial1:=1;
            Initial2:=1;
            Initial3:=1;
            CurrentInitial:=1;
            GameScreen:=InGameEnd;
            Exit;
            END;
        END;
    DrawColor(FALSE,ColCyan);
    DrawPixel(Snake[0].X,Snake[0].Y);
    DrawColor(FALSE,ColBlue);
    DrawPixel(Food.X,Food.Y);
    Timer:=Timer+1;
    SetXY(0,0);
    DrawColor(TRUE,ColGreen);
    Write('Score : ',Score:4,' | Level : ',Level:2);
    CASE Level OF
    1:Pause(250);
    2:Pause(230);
    3:Pause(210);
    4:Pause(190);
    5:Pause(170);
    6:Pause(150);
    7:Pause(130);
    8:Pause(110);
    9:Pause(90);
    10:Pause(70);
    END;
    END;

PROCEDURE DrawLevelBegin;
    VAR
    DrawCounter,SnakeCounter:Integer;
    BEGIN
    Snake[0].X:=15;
    Snake[0].Y:=12;
    SnakeDir:=Up;
    SnakeGrowth:=2;
    FoodCollisionDetection;
    FOR SnakeCounter:=1 TO 150 DO
        BEGIN
        Snake[SnakeCounter].X:=256;
        Snake[Snakecounter].Y:=256;
        END;
    DrawColor(FALSE,ColBlack);
    ClearScreen;
    DrawColor(FALSE,ColWhite);
    FOR DrawCounter:=0 TO 29 DO
        BEGIN
        DrawPixel(DrawCounter,1);
        DrawPixel(DrawCounter,24);
        END;
    FOR DrawCounter:=1 TO 24 DO
        BEGIN
        DrawPixel(0,DrawCounter);
        DrawPixel(29,DrawCounter);
        END;
    GameScreen:=InGame;
    END;

PROCEDURE DrawInGameOptions;
    BEGIN
    IF NOT(InGameGlobect=InGameSelect)THEN
        BEGIN
        IF(InGameSelect=1)THEN
            BEGIN
            SetXY(30,0);
            DrawColor(TRUE,ColGreen);
            Writeln('         >>>RESUME<<<        ');
            SetXY(30,1);
            DrawColor(TRUE,ColRed);
            Writeln('             QUIT            ');
            InGameGlobect:=InGameSelect;
            END;
        IF(InGameSelect=2)THEN
            BEGIN
            SetXY(30,0);
            DrawColor(TRUE,ColRed);
            Writeln('            RESUME           ');
            SetXY(30,1);
            DrawColor(TRUE,ColGreen);
            Writeln('          >>>QUIT<<<         ');
            InGameGlobect:=InGameSelect;
            END;
        END;
    END;

PROCEDURE DrawInGameEnd;
    BEGIN
    IF NOT(InitialChange=CurrentInitial)THEN
        BEGIN
        IF(CurrentInitial=1)THEN
            BEGIN
            SetXY(0,0);
            DrawColor(TRUE,ColGreen);
            Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
            SETXY(9,1);
            DrawColor(TRUE,ColCyan);
            Write('Name : ');
            DrawColor(TRUE,ColRed);
            Write(GetInitial(Initial1));
            DrawColor(TRUE,ColCyan);
            Write(GetInitial(Initial2),GetInitial(Initial3),' Score : ',Score);
            InitialChange:=CurrentInitial;
            END;
        IF(CurrentInitial=2)THEN
            BEGIN
            SetXY(0,0);
            DrawColor(TRUE,ColGreen);
            Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
            SETXY(9,1);
            DrawColor(TRUE,ColCyan);
            Write('Name : ',GetInitial(Initial1));
            DrawColor(TRUE,ColRed);
            Write(GetInitial(Initial2));
            DrawColor(TRUE,ColCyan);
            Write(GetInitial(Initial3),' Score : ',Score);
            InitialChange:=CurrentInitial;
            END;
        IF(CurrentInitial=3)THEN
            BEGIN
            SetXY(0,0);
            DrawColor(TRUE,ColGreen);
            Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
            SETXY(9,1);
            DrawColor(TRUE,ColCyan);
            Write('Name : ',GetInitial(Initial1),GetInitial(Initial2));
            DrawColor(TRUE,ColRed);
            Write(GetInitial(Initial3));
            DrawColor(TRUE,ColCyan);
            Write(' Score : ',Score);
            InitialChange:=CurrentInitial;
            END;
        END;
    CASE CurrentInitial OF
    1:BEGIN
      IF NOT(LetterChange=Initial1)THEN
        BEGIN
        SetXY(0,0);
        DrawColor(TRUE,ColGreen);
        Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
        SETXY(9,1);
        DrawColor(TRUE,ColCyan);
        Write('Name : ');
        DrawColor(TRUE,ColRed);
        Write(GetInitial(Initial1));
        DrawColor(TRUE,ColCyan);
        Write(GetInitial(Initial2),GetInitial(Initial3),' Score : ',Score);
        LetterChange:=Initial1;
        END;
      END;
    2:BEGIN
      IF NOT(LetterChange=Initial2)THEN
        BEGIN
        SetXY(0,0);
        DrawColor(TRUE,ColGreen);
        Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
        SETXY(9,1);
        DrawColor(TRUE,ColCyan);
        Write('Name : ',GetInitial(Initial1));
        DrawColor(TRUE,ColRed);
        Write(GetInitial(Initial2));
        DrawColor(TRUE,ColCyan);
        Write(GetInitial(Initial3),' Score : ',Score);
        LetterChange:=Initial2;
        END;
      END;
    3:BEGIN
      IF NOT(LetterChange=Initial3)THEN
        BEGIN
        SetXY(0,0);
        DrawColor(TRUE,ColGreen);
        Write('UP/DOWN : Choose letter | LEFT/RIGHT : Change initial');
        SETXY(9,1);
        DrawColor(TRUE,ColCyan);
        Write('Name : ',GetInitial(Initial1),GetInitial(Initial2));
        DrawColor(TRUE,ColRed);
        Write(GetInitial(Initial3));
        DrawColor(TRUE,ColCyan);
        Write(' Score : ',Score);
        LetterChange:=Initial3;
        END;
      END;
    END;
    END;
           

BEGIN
    InitiateYS;
    InitiateMenu;
    ClearInput;
    REPEAT
        IF(Key_Down=TRUE)THEN
            BEGIN
            Keypressed:=Get_Key;
            KeyboardMenu;
            KeyboardInGame;
            KeyboardInGameOptions;
            KeyboardMenuScore;
            KeyboardInGameEnd;
            END;
        CASE GameScreen OF
        Menu:DrawMenu;
        InGame:DrawInGame;
        LevelBegin:DrawLevelBegin;
        InGameOptions:DrawInGameOptions;
        MenuScore:DrawMenuScore;
        InGameEnd:DrawInGameEnd;
        END;
    UNTIL(QuitTrigger=TRUE);
END.


MENU DEMO in text mode.... v1.5
This is a complete menu programe that demonstrate how real shadows and popup can be build.
Statis Analogue Clock Face 1.0
There are many analogue clock components around - but they all move!! I needed one for inputting which didn't! Here it is.
MyDeveloper Tools for VS.NET 2.10
MyDeveloper Tools (formerly known as MySQL Developer Tools) is a powerful add-in designed to simplify the MySQL database application development process. It integrates into Visual Studio, making all ...
Download MENU DEMO in text mode.... v1.5 This is a complete menu programe that demonstrate how real  shadows and popup can be build. Download Statis Analogue Clock Face 1.0 There are many analogue clock components around - but they all  move!! I needed one for inputting which didn't! Here it is. Download MyDeveloper Tools for VS.NET 2.10 MyDeveloper Tools (formerly known as MySQL Developer Tools) is a powerful add-in designed to simplify the MySQL database application development process. It integrates into Visual Studio, making all ...







Sponsored links

Localize software in three simple steps
Localize .Net, C/C++ & Delphi apps visually. HTML, HTML Help, XML & databases. Try Sisulizer now!
Delphi Localization Tool Sisulizer (WYSIWYG)
Create multilingual Delphi apps in three simple steps. Localize XML, HTML Help ... Try Sisulizer now
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
Computer Professionals: Are you owed Overtime?
Federal and State Laws may allow computer professionals to collect overtime. Our law firm is experienced, and has initiated class action lawsuits against some of the largest computer companies to collect back pay and overtime. Strictly Confidential.
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |