Thread: Console ConSt Snake(It doesn't change it's size) ,Failing to create a normal snake :|

  1. #1
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17

    Console ConSt Snake(It doesn't change it's size) ,Failing to create a normal snake :|

    Hello,

    I'm creating a project FOXEFDE.Project's idea=You can play a lot of diffirent games,earn dollers,buy a strong pet,train him,win a tourneys ...At the moment project got 1500Lines, 3games have been added,as well choice of pet.I really want ,that fourth game would be snake,but i'm just failing to make it move,if she grows...Any suggestions?Really need some help :|

    The code is at:Foxefde C++ - Home
    Also all my little projects!

    Or just:

    insert
    Code:
    #include <cstdlib>
    #include <Windows.h>
    #include <iostream>
    #include <ctime>
    
    double Scoore=0;
    int a7,b7,c7=0,n7=0,jk8,Tempone,FakeBeard,kja145=0,rad,loasf=0,xd,FailRandm, nothing1=0, x=729,SnakeLength=2,TempSnakeLength,AnotherTempSnakeLength;
    char foxas [2800],l=205,kkas=186;
    void clearscreen();
    void ToGetRandomApple();
    void CheckRight();
    void CheckLeft();
    void ramu();
    using namespace std;
    
    int main() {
        cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      CoNsT SnaKe                    By Foxefde  2013 \n";
        Sleep(2800);
        system("cls");
    system("color 30");
    bool down=0,left=0,right=0,up=0,jkj=false;
        rad=rand()%2800;
        srand((unsigned)time(0));
    do{
            cout<<"Dollers="<<Scoore/125<<endl<<endl<<char(201);ramu();cout<<char(187)<<endl;
    for(a7=0;a7<2800;a7++)
    {
    TempSnakeLength=SnakeLength;
    AnotherTempSnakeLength=TempSnakeLength;
    if(xd==69       || xd==139 || xd==209 || xd==279 || xd==349 || xd==419 || xd==489 || xd==559 || xd==629 || xd==699 || xd==769 || xd==839
                    || xd==909 || xd==979 || xd==1049|| xd==1119 || xd==1189 || xd==1259 || xd==1329 || xd==1399 || xd==1469 || xd==1539 || xd==1609
                    || xd==1679 || xd==1749 || xd==1819 || xd==1889 || xd==1959 || xd==2029 || xd==2099|| xd==2169 || xd==2239 || xd==2309 || xd==2379
                    || xd==2449 || xd==2519 || xd==2589 || xd==2659 || xd==2729 || xd==2799 ){jkj=true;cout<<kkas;}
    
        if(x!=a7 && rad!=a7 && jkj==false){foxas[a7]=' ';cout<<foxas[a7];}
        else {foxas[x]='o';if(x==a7){
    
                if(right==true){do{cout<<foxas[x];TempSnakeLength--;}while(TempSnakeLength>0);}
                if(up==true)   {do{cout<<foxas[x];TempSnakeLength--;}while(TempSnakeLength>0);}
                if(down==true) {do{cout<<foxas[x];TempSnakeLength--;}while(TempSnakeLength>0);}
                if(left==true) {do{cout<<foxas[x];TempSnakeLength--;}while(TempSnakeLength>0);}
    
        };}
    
    
        if(rad==a7){foxas[rad]=char(3);cout<<foxas[rad];}
        c7++;
        xd++;
    
        jkj=false;
        if(c7==70+n7) {cout<<endl;n7=n7+70;}
          if(GetAsyncKeyState(VK_LEFT)) {
       if(right==false){down=false,up=false,right=false;left=true;}
      }
      else if(GetAsyncKeyState(VK_RIGHT)) {
       if(left==false){left=false,up=false,down=false;right=true;}
      }
      else if(GetAsyncKeyState(VK_UP)) {
       if(down==false){left=false,down=false,right=false;up=true;}
      }
      else if(GetAsyncKeyState(VK_DOWN)) {
       if(up==false){left=false,up=false,right=false;down=true;}
      }
        if(a7==2799)
                                   {
                                       cout<<char(200);ramu();cout<<char(188)<<endl;;
                                       if(right==true && up==false) {CheckRight();ToGetRandomApple();};
                                       if(up==true && right==false) {ToGetRandomApple() ;x=x-70;    ;Sleep(15);};
                                       if(down==true && up==false)  {ToGetRandomApple() ;x=x+70;    ;Sleep(15);};
                                       if(left==true && up==false)  {CheckLeft(); ToGetRandomApple();};
                                       clearscreen();
                                   }
        }
    
    }while(true);
    }
    void clearscreen()
    {
        HANDLE hOut;
        COORD Position;
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
        Position.X = 0;
        Position.Y = 0;
        SetConsoleCursorPosition(hOut, Position);
    }
    
    void ToGetRandomApple()
    {
        if(x<0 || x>2800){system("cls");cout<<endl<<"\n\nGame Over!";cout<<"You earned:"<<Scoore/125;cin.ignore();}
        if(foxas[rad]==foxas[x]){
        Scoore+=2;
        SnakeLength++;
        srand (time(NULL));
        rad=rand()%52;
        srand((unsigned)time(0));
        FailRandm=rand()%52;
        rad*=FailRandm;
        foxas[rad]=249;
        Beep(800,18);Beep(340,24);Beep(300,21);Beep(400,32);Beep(500,19);Beep(150,8);Beep(2890,10);Beep(255,8);Beep(102,4);
    
    }}
    
    void CheckRight()
    {
    if(x==69 || x==139 || x==209 || x==279 || x==349 || x==419 || x==489 || x==559 || x==629 ||
    x==699 || x==769 || x==839 || x==909 || x==979 || x==1049|| x==1119 || x==1189 || x==1259 ||
    x==1329 || x==1399 || x==1469 || x==1539 || x==1609 || x==1679 || x==1749 || x==1819 || x==1889
    || x==1959 || x==2029 || x==2099|| x==2169 || x==2239 || x==2309 || x==2379 || x==2449 || x==2519
    || x==2589 || x==2659 || x==2729)
    {x=-1;ToGetRandomApple();}
    else {x++;}
    }
    void CheckLeft()
    {
    if(x==70 || x==140 || x==210 || x==280 || x==350 || x==420 || x==490 || x==560 || x==630 ||
        x==700 || x==770 || x==840 || x==910 || x==980 || x==1050|| x==1120 || x==1190 || x==1260
         || x==1330 || x==1400 || x==1470 || x==1540 || x==1610 || x==1680 || x==1750 || x==1820 ||
          x==1890 || x==1960 || x==2030 || x==2100|| x==2170 || x==2240 || x==2310 || x==2380 ||
          x==2450 || x==2520 || x==2590 || x==2660 || x==2730)
    {x=-1;ToGetRandomApple();}
            else {x--;}
    }
    void ramu()
    {
        cout<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<
            l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<
            l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l<<l;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Your poor indentation makes it very difficult to read your code.

    Your use of magic numbers (the 3rd bullet point applies here) makes it nearly impossible to understand what's actually going on.

    In your ramu() function, you could easily use a loop, instead of explicitly printing dozens of times.

    Global variables are bad.

    You should only call srand() once in the entire program.

    Your reliance on system() calls to effect various bits of functionality is highly non-portable, and at best, it's an ugly hack.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17
    Oh,**** I copied the wrong code,My ramu function was OK :|

    Deleted 2srand times,as you suggested .What do you mean with namespace life? There's a real code :
    Code:
    #include <cstdlib>
    #include <Windows.h>
    #include <iostream>
    #include <ctime>
    
    
    double Scoore=0;
    int a7,b7,c7=0,n7=0,jk8,Tempone,FakeBeard,kja145=0,rad,loasf=0,xd,FailRandm, nothing1=0, x=729,yu=0;
    char foxas [2800],l=205,kkas=186;
    void clearscreen();
    void ToGetRandomApple();
    void CheckRight();
    void CheckLeft();
    void ramu();
    using namespace std;
    
    
    int main() {
        cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      CoNsT SnaKe                    By Foxefde  2013 \n";
        Sleep(2800);
        system("cls");
    system("color 30");
    bool down=0,left=0,right=0,up=0,jkj=false;
        rad=rand()%2800;
        srand((unsigned)time(0));
    do{
            cout<<"Dollers="<<Scoore/125<<endl<<endl<<char(201);ramu();cout<<char(187)<<endl;
    for(a7=0;a7<2800;a7++)
    {
    
    
    if(xd==69       || xd==139 || xd==209 || xd==279 || xd==349 || xd==419 || xd==489 || xd==559 || xd==629 || xd==699 || xd==769 || xd==839
                    || xd==909 || xd==979 || xd==1049|| xd==1119 || xd==1189 || xd==1259 || xd==1329 || xd==1399 || xd==1469 || xd==1539 || xd==1609
                    || xd==1679 || xd==1749 || xd==1819 || xd==1889 || xd==1959 || xd==2029 || xd==2099|| xd==2169 || xd==2239 || xd==2309 || xd==2379
                    || xd==2449 || xd==2519 || xd==2589 || xd==2659 || xd==2729 || xd==2799 ){jkj=true;cout<<kkas;}
    
    
        if(x!=a7 && rad!=a7 && jkj==false){foxas[a7]=' ';cout<<foxas[a7];}
        else {foxas[x]=kkas;if(rad!=a7){cout<<foxas[x];};}
        if(rad==a7){foxas[rad]=char(3);cout<<foxas[rad];}
        c7++;
        xd++;
    
    
        jkj=false;
        if(c7==70+n7) {cout<<endl;n7=n7+70;}
        if(GetAsyncKeyState(VK_LEFT)) {
    if(right==false){down=false,up=false,right=false;left=true;}
    }
    else if(GetAsyncKeyState(VK_RIGHT)) {
    if(left==false){left=false,up=false,down=false;right=true;}
    }
    else if(GetAsyncKeyState(VK_UP)) {
    if(down==false){left=false,down=false,right=false;up=true;}
    }
    else if(GetAsyncKeyState(VK_DOWN)) {
    if(up==false){left=false,up=false,right=false;down=true;}
    }
        if(a7==2799)
                                   {
                                       cout<<char(200);ramu();cout<<char(188)<<endl;;
                                       if(right==true && up==false) {CheckRight();ToGetRandomApple();};
                                       if(up==true && right==false) {ToGetRandomApple() ;x=x-70;    ;Sleep(15);};
                                       if(down==true && up==false)  {ToGetRandomApple() ;x=x+70;    ;Sleep(15);};
                                       if(left==true && up==false)  {CheckLeft(); ToGetRandomApple();};
                                       clearscreen();
                                   }
        }
    
    
    }while(true);
    }
    void clearscreen()
    {
        HANDLE hOut;
        COORD Position;
    
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    
        Position.X = 0;
        Position.Y = 0;
        SetConsoleCursorPosition(hOut, Position);
    }
    
    
    void ToGetRandomApple()
    {
        if(x<0 || x>2800){system("cls");cout<<endl<<"\n\nGame Over!";cout<<"You earned:"<<Scoore/125;cin.ignore();}
        if(foxas[rad]==foxas[x]){
        Scoore+=2;
        srand (time(NULL));
        rad=rand()%52;
        srand((unsigned)time(0));
        FailRandm=rand()%52;
        rad*=FailRandm;
        foxas[rad]=249;
        Beep(800,18);Beep(340,24);Beep(300,21);Beep(400,32);Beep(500,19);Beep(150,8);Beep(2890,10);Beep(255,8);Beep(102,4);
    
    
    }}
    
    
    void CheckRight()
    {
    if(x==69 || x==139 || x==209 || x==279 || x==349 || x==419 || x==489 || x==559 || x==629 ||
    x==699 || x==769 || x==839 || x==909 || x==979 || x==1049|| x==1119 || x==1189 || x==1259 ||
    x==1329 || x==1399 || x==1469 || x==1539 || x==1609 || x==1679 || x==1749 || x==1819 || x==1889
    || x==1959 || x==2029 || x==2099|| x==2169 || x==2239 || x==2309 || x==2379 || x==2449 || x==2519
    || x==2589 || x==2659 || x==2729)
    {x=-1;ToGetRandomApple();}
    else {x++;}
    }
    void CheckLeft()
    {
    if(x==70 || x==140 || x==210 || x==280 || x==350 || x==420 || x==490 || x==560 || x==630 ||
        x==700 || x==770 || x==840 || x==910 || x==980 || x==1050|| x==1120 || x==1190 || x==1260
         || x==1330 || x==1400 || x==1470 || x==1540 || x==1610 || x==1680 || x==1750 || x==1820 ||
          x==1890 || x==1960 || x==2030 || x==2100|| x==2170 || x==2240 || x==2310 || x==2380 ||
          x==2450 || x==2520 || x==2590 || x==2660 || x==2730)
    {x=-1;ToGetRandomApple();}
            else {x--;}
    }
    void ramu()
    {
        while(yu<69){cout<<l;yu++;};
        yu=0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Foxefde View Post
    What do you mean with namespace life?
    that's my signature.

    in any case, you're still using lots of magic numbers that have no obvious meaning, and you still call srand() over and over again. make srand() the first line of main() and remove every other call to it.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And you haven't fixed the indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    This is what people mean you to do, when they complain about indentation
    Code:
    #include <cstdlib>
    #include <Windows.h>
    #include <iostream>
    #include <ctime>
    
    
    double Scoore = 0;
    int a7, b7, c7 = 0, n7 = 0, jk8, Tempone, FakeBeard, kja145 = 0, rad, loasf =
        0, xd, FailRandm, nothing1 = 0, x = 729, yu = 0;
    char foxas[2800], l = 205, kkas = 186;
    void clearscreen();
    void ToGetRandomApple();
    void CheckRight();
    void CheckLeft();
    void ramu();
    using namespace std;
    
    
    int main()
    {
      cout <<
          "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      CoNsT SnaKe                    By Foxefde  2013 \n";
      Sleep(2800);
      system("cls");
      system("color 30");
      bool down = 0, left = 0, right = 0, up = 0, jkj = false;
      rad = rand() % 2800;
      srand((unsigned) time(0));
      do {
        cout << "Dollers=" << Scoore / 125 << endl << endl << char (201);
        ramu();
        cout << char (187) << endl;
        for (a7 = 0; a7 < 2800; a7++) {
          if (xd == 69 || xd == 139 || xd == 209 || xd == 279 || xd == 349 || xd == 419 || xd == 489
              || xd == 559 || xd == 629 || xd == 699 || xd == 769 || xd == 839 || xd == 909 || xd == 979
              || xd == 1049 || xd == 1119 || xd == 1189 || xd == 1259 || xd == 1329 || xd == 1399
              || xd == 1469 || xd == 1539 || xd == 1609 || xd == 1679 || xd == 1749 || xd == 1819
              || xd == 1889 || xd == 1959 || xd == 2029 || xd == 2099 || xd == 2169 || xd == 2239
              || xd == 2309 || xd == 2379 || xd == 2449 || xd == 2519 || xd == 2589 || xd == 2659
              || xd == 2729 || xd == 2799) {
            jkj = true;
            cout << kkas;
          }
    
          if (x != a7 && rad != a7 && jkj == false) {
            foxas[a7] = ' ';
            cout << foxas[a7];
          } else {
            foxas[x] = kkas;
            if (rad != a7) {
              cout << foxas[x];
            };
          }
          if (rad == a7) {
            foxas[rad] = char (3);
            cout << foxas[rad];
          }
    
          c7++;
          xd++;
          jkj = false;
          if (c7 == 70 + n7) {
            cout << endl;
            n7 = n7 + 70;
          }
          if (GetAsyncKeyState(VK_LEFT)) {
            if (right == false) {
              down = false, up = false, right = false;
              left = true;
            }
          } else if (GetAsyncKeyState(VK_RIGHT)) {
            if (left == false) {
              left = false, up = false, down = false;
              right = true;
            }
          } else if (GetAsyncKeyState(VK_UP)) {
            if (down == false) {
              left = false, down = false, right = false;
              up = true;
            }
          } else if (GetAsyncKeyState(VK_DOWN)) {
            if (up == false) {
              left = false, up = false, right = false;
              down = true;
            }
          }
    
          if (a7 == 2799) {
            cout << char (200);
            ramu();
            cout << char (188) << endl;;
            if (right == true && up == false) {
              CheckRight();
              ToGetRandomApple();
            };
            if (up == true && right == false) {
              ToGetRandomApple();
              x = x - 70;;
              Sleep(15);
            };
            if (down == true && up == false) {
              ToGetRandomApple();
              x = x + 70;;
              Sleep(15);
            };
            if (left == true && up == false) {
              CheckLeft();
              ToGetRandomApple();
            };
            clearscreen();
          }
        }
      } while (true);
    }
    
    void clearscreen()
    {
      HANDLE hOut;
      COORD Position;
    
      hOut = GetStdHandle(STD_OUTPUT_HANDLE);
      Position.X = 0;
      Position.Y = 0;
      SetConsoleCursorPosition(hOut, Position);
    }
    
    void ToGetRandomApple()
    {
      if (x < 0 || x > 2800) {
        system("cls");
        cout << endl << "\n\nGame Over!";
        cout << "You earned:" << Scoore / 125;
        cin.ignore();
      }
      if (foxas[rad] == foxas[x]) {
        Scoore += 2;
        srand(time(NULL));
        rad = rand() % 52;
        srand((unsigned) time(0));
        FailRandm = rand() % 52;
        rad *= FailRandm;
        foxas[rad] = 249;
        Beep(800, 18);
        Beep(340, 24);
        Beep(300, 21);
        Beep(400, 32);
        Beep(500, 19);
        Beep(150, 8);
        Beep(2890, 10);
        Beep(255, 8);
        Beep(102, 4);
      }
    }
    
    void CheckRight()
    {
      if (x == 69 || x == 139 || x == 209 || x == 279 || x == 349 || x == 419 || x == 489 || x == 559
          || x == 629 || x == 699 || x == 769 || x == 839 || x == 909 || x == 979 || x == 1049
          || x == 1119 || x == 1189 || x == 1259 || x == 1329 || x == 1399 || x == 1469 || x == 1539
          || x == 1609 || x == 1679 || x == 1749 || x == 1819 || x == 1889 || x == 1959 || x == 2029
          || x == 2099 || x == 2169 || x == 2239 || x == 2309 || x == 2379 || x == 2449 || x == 2519
          || x == 2589 || x == 2659 || x == 2729) {
        x = -1;
        ToGetRandomApple();
      } else {
        x++;
      }
    }
    
    void CheckLeft()
    {
      if (x == 70 || x == 140 || x == 210 || x == 280 || x == 350 || x == 420 || x == 490 || x == 560
          || x == 630 || x == 700 || x == 770 || x == 840 || x == 910 || x == 980 || x == 1050
          || x == 1120 || x == 1190 || x == 1260 || x == 1330 || x == 1400 || x == 1470 || x == 1540
          || x == 1610 || x == 1680 || x == 1750 || x == 1820 || x == 1890 || x == 1960 || x == 2030
          || x == 2100 || x == 2170 || x == 2240 || x == 2310 || x == 2380 || x == 2450 || x == 2520
          || x == 2590 || x == 2660 || x == 2730) {
        x = -1;
        ToGetRandomApple();
      } else {
        x--;
      }
    }
    
    void ramu()
    {
      while (yu < 69) {
        cout << l;
        yu++;
      };
      yu = 0;
    }
    > if (x == 70 || x == 140 || x == 210 || x == 280 || x == 350 || x == 420 || x == 490 || x == 560
    Notice anything in particular about these values?
    Like for example, all multiples of 70 perhaps?
    If you do, then perhaps you might be interested in
    if ( x % 70 == 0 )

    You could apply the same kind of test to your other long list of numbers as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17
    Ok.Edited code.Thanks,but still have no idea how can i make snake moving correctly,if she grows..Is that at least possible without using vectors and some strange function with x and y?Because all of the snake games were with funct or vectors =//

    Code:
    //BY FOXEFDE//2013
    #include <cstdlib>
    #include <Windows.h>
    #include <iostream>
    #include <ctime>
    
    
    void setcolor(unsigned char color)
    {
        HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hcon,color);
    }
    double Scoore=0;
    int a7,b7,c7=0,n7=0,jk8,Tempone,FakeBeard,kja145=0,rad,loasf=0,xd,FailRandm, nothing1=0, x=729,yu=0,SnakeLength,jojo,TemporarySnakeLength=5;
    char foxas [2800],kkas=2;
    void clearscreen();
    void ToGetRandomApple();
    void CheckRight();
    void CheckLeft();
    void ConstSnake();
    using namespace std;
    
    
    void clearscreen()
    {
        HANDLE hOut;
        COORD Position;
    
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    
        Position.X = 0;
        Position.Y = 0;
        SetConsoleCursorPosition(hOut, Position);
    }
    
    
    int main()
    {
        ConstSnake();
    }
    
    
    void ToGetRandomApple()
    {
        if(x < 0 || x > 2800 ){system("cls");cout << endl << "\n\nGame Over!";cout << "You earned:" << Scoore/125;cin.ignore();}
        if(foxas[rad] == foxas[x]){
        Scoore += 2;
        SnakeLength++;
        rad = rand()%52;
        FailRandm = rand()%52;
        rad*=FailRandm;
        foxas[rad]=249;
        Beep(800,18);
        Beep(340,24);
        Beep(300,21);
        Beep(400,32);
        Beep(500,19);
        Beep(150,8);
        Beep(2890,10);
        Beep(255,8);
        Beep(102,4);
    
    
    }}
    
    
    void CheckRight()
    {
     if(x % 70 == 69)
        {x=-1;ToGetRandomApple();}
    x++;
    }
    void CheckLeft()
    {
         if(x % 70 == 0)
            {x=-1;ToGetRandomApple();}
    x--;
    }
    void ConstSnake()
    {
        {
            srand((unsigned)time(0));
        cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      CoNsT SnaKe                    By Foxefde  2013 \n";
        Sleep(2800);
        system("cls");
    system("color 28");
    bool down = 0,left = 0,right = 0,up = 0,jkj = false,hej = false;
        rad=rand()%2800;
    do{
            cout<<"Dollers="<<Scoore/125<<endl<<endl;
    for(a7=0;a7<2800;a7++)
    {
    
    
        if(x!=a7 && rad!=a7 && jkj==false){
            foxas[a7]=' ';
            cout<<foxas[a7];
        }
        else {
            foxas[x] = kkas;
            setcolor(15);
            if (rad != a7) {
              cout << foxas[x];
            };
          }
          if (rad == a7) {
            foxas[rad] = char (3);
            cout << foxas[rad];
          }
    
    
          c7++;
          xd++;
          jkj = false;
          if (c7 == 70 + n7) {
            cout << endl;
            n7 = n7 + 70;
          }
          if (GetAsyncKeyState(VK_LEFT)) {
            if (right == false) {
              down = false, up = false, right = false;
              left = true;
            }
          } else if (GetAsyncKeyState(VK_RIGHT)) {
            if (left == false) {
              left = false, up = false, down = false;
              right = true;
            }
          } else if (GetAsyncKeyState(VK_UP)) {
            if (down == false) {
              left = false, down = false, right = false;
              up = true;
            }
          } else if (GetAsyncKeyState(VK_DOWN)) {
            if (up == false) {
              left = false, up = false, right = false;
              down = true;
            }
          }
        if(a7 == 2799)
                                   {
            if (right == true && up == false) {
              CheckRight();
              ToGetRandomApple();
            };
            if (up == true && right == false) {
              ToGetRandomApple();
              x = x - 70;;
              Sleep(15);
            };
            if (down == true && up == false) {
              ToGetRandomApple();
              x = x + 70;;
              Sleep(15);
            };
            if (left == true && up == false) {
              CheckLeft();
              ToGetRandomApple();
            };
            clearscreen();
    
    
                                  }
        }
    }
    while(true);
    }
    }

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well there's certainly no difficulty in identifying the lines of code you touched
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    76
    Quote Originally Posted by Foxefde View Post
    Ok.Edited code.Thanks,but still have no idea how can i make snake moving correctly,if she grows..Is that at least possible without using vectors and some strange function with x and y?Because all of the snake games were with funct or vectors =//
    You could do it with a list, with a definite start and end.

    You keep a const ref to your first node, and run through all your nodes til you reach the last one which you made to point to a NULL ref, and so you know it's the end?

  10. #10
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17
    Thanks again, edited the code ,but still couldn't ,just failed ,to make it grow...She was moving perfect only then,when she had only head and a tail =/

    And ,Salem, I know that's easy,especially for you

  11. #11
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    76
    Quote Originally Posted by Foxefde View Post
    Thanks again, edited the code ,but still couldn't ,just failed ,to make it grow...She was moving perfect only then,when she had only head and a tail =/

    And ,Salem, I know that's easy,especially for you
    Alright, I'll spoon feed you now;
    start with the second node of your snake, and make it's coords the same as the node before, go through the whole list that way, so each piece goes to where the one before was, then update the first node to move in the direction that it was facing. When you add a node the snake will become longer by one unit. In your drawing function, you just put the piece where they belong as you normally do, going through the list

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Snake game..
    By Marcus007 in forum C Programming
    Replies: 0
    Last Post: 12-05-2011, 06:58 PM
  2. C++ snake
    By nwasiq in forum C++ Programming
    Replies: 10
    Last Post: 11-20-2010, 11:35 AM
  3. Snake
    By Grantyt3 in forum Game Programming
    Replies: 2
    Last Post: 05-24-2006, 01:35 PM
  4. My old Snake evolved!
    By LogicError in forum Game Programming
    Replies: 4
    Last Post: 01-13-2005, 07:58 AM
  5. My snake
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-07-2002, 04:45 AM

Tags for this Thread