Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Snake


/* Snake Snake Snake Snake Snake Snake Snake Snake */

#include
#include
#include
#include
#include

Comments

  • rohitprohitp Member Posts: 6
    Good program man. you should try it in graphics mode.
    Here is the one I have written. But it is in c and not in c++


    #include
    #include
    #include

    int arr_s[20][15],x,y,d,n,one_s[300][2],rx,ry;
    /////////////////////////////////////////////
    void initialise_s()
    {
    int i,j;
    for (i=0;i<20;i++)
    for (j=0;j<15;j++)
    arr_s[i][j]=0;
    for (i=0;i<300;i++)
    {
    one_s[i][1]=-1;
    one_s[i][0]=-1;
    }
    for (i=0;i<5;i++)
    {
    arr_s[i][0]=1;
    one_s[i][0]=4-i;
    one_s[i][1]=0;
    }
    rx=5;ry=5;
    arr_s[rx][ry]=2;
    x=4;y=0;d='r';n=5;
    }
    /////////////////////////////////////////////
    void square_s(int i,int j,int k)
    {
    setcolor(k);
    for (k=0;k<16;k++)
    rectangle ( 22+i*30+k , 17+j*30+k , 48+i*30-k , 43+j*30-k );
    }
    /////////////////////////////////////////////
    void display_s ()
    {
    int i,j,k;
    setcolor(3);
    for (j=0;j<20;j++)
    for (k=0;k<15;k++)
    {
    if (arr_s[j][k]==1)
    square_s(j,k,3);
    else
    if (arr_s[j][k]==2)
    square_s(j,k,4);
    else
    if (arr_s[j][k]==0)
    square_s(j,k,0);
    }
    }
    /////////////////////////////////////////////
    int check_s()
    {
    int i,j,flag;
    if ((x==rx)&&(y==ry))
    {
    for (i=n;i>0;i--)
    {
    one_s[i][0]=one_s[i-1][0];
    one_s[i][1]=one_s[i-1][1];
    }
    one_s[0][0]=rx;
    one_s[0][1]=ry;
    n++;
    do
    {
    rx=rand()%20;
    ry=rand()%15;
    if (rx<0) rx*=-1;
    if (ry<0) ry*=-1;
    flag=1;
    for (i=0;i<n;i++)
    if ((one_s[i][0]==rx)&&(one_s[i][1]==ry))
    {
    flag=0;
    break;
    }
    } while(flag==0);
    arr_s[rx][ry]=2;
    return(1);
    }
    if ((y<0)||(x<0)||(y>15)||(x>20))
    return(2);
    for (i=0;i=0;i--)
    {
    one_s[i][0]=one_s[i-1][0];
    one_s[i][1]=one_s[i-1][1];
    }
    one_s[0][0]=x;
    one_s[0][1]=y;
    }
    if (i==2) end_s();
    arr_s[x][y]=1;
    }
    /////////////////////////////////////////////
    void main()
    {
    int i;
    char c;
    int gd=0,gm;
    initgraph(&gd,&gm,"d:\programs\tcc\program");
    setcolor(15);
    rectangle(0,0,639,479);
    rectangle(18,13,622,467);
    setcolor(1);
    line (1,12,638,12);
    line (17,12,17,467);
    for (i=1;i<12;i++)
    {
    line (1,i,638,i);
    line (1,479-i,638,479-i);
    }
    for (i=1;i<17;i++)
    {
    line (i,12,i,467);
    line (639-i,12,639-i,467);
    }
    initialise_s();
    do
    {
    if (kbhit())
    {
    c=getch();
    if (c==0)
    {
    c=getch();
    if (c==75) // Left.
    if ((d!='l')&&(d!='r')) d='l';
    if (c==77) // Right
    if ((d!='r')&&(d!='l')) d='r';
    if (c==72) // Up.
    if ((d!='u')&&(d!='d')) d='u';
    if (c==80) // Down.
    if ((d!='u')&&(d!='d')) d='d';
    }
    }
    change_s();
    display_s();
    delay(500);
    }while (c!=27);
    getch();
    }
  • EinEin Member Posts: 2
    Did you compile Snake in Borland or MSVC++6.0?

    .:.:.:.:.:.:.:.

    [NS]Ein[CoFounder]

    Co-Founder of Nuclear Storm

    Go to http://nuclearstorm.cjb.net and visit us!

    .:.:.:.:.:.:.:.

  • markian84markian84 Member Posts: 18
    : Did you compile Snake in Borland or MSVC++6.0?

    I think he did it in Borland; the graphics library he uses doesn't come with and doesn't work with MSVC++6.0 (at least not the version I have).
    :
    : .:.:.:.:.:.:.:.
    :
    : [NS]Ein[CoFounder]
    :
    : Co-Founder of Nuclear Storm
    :
    : Go to http://nuclearstorm.cjb.net and visit us!
    :
    : .:.:.:.:.:.:.:.
    :
    :

Sign In or Register to comment.