C++ Tutorial 18 – Simple Snake Game (Part 3)

C++ Tutorial 18 – Simple Snake Game (Part 3)

Welcome to my simple game tutorial on C++. In this tutorial i will going to show you how to make a fun snake game.

We will finish our game, by adding a tail to the snake, and polishing the code up a bit.

Source code:
Finished game:
Mirror link:

Great C++ books that I recommend for beginners:
C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart (3rd Edition)

C++ Primer Plus (6th Edition) (Developer’s Library)

Programming: Principles and Practice Using C++ (2nd Edition)

Download link for visual studio 2012 express:

If you have any questions I’ll be glad to answer, please leave a comment on the video.

Thanks for watching and please subscribe.

Nguồn: https://blackdiamondskinserumsite.net/

Xem thêm bài viết khác: https://blackdiamondskinserumsite.net/game/

49 thoughts on “C++ Tutorial 18 – Simple Snake Game (Part 3)

  1. Loved it .! Really appreciated . I felt so good when the tail worked . Also , for a beginner programmer like me i understood everything . Thanks Mate. You've earned yourself a subscribe .

  2. when i pass over F it takes literally 10-20 seconds for my tail to grow, the score to increase and the F to respawn somewhere

  3. Even though you said that this game is simple, this was so hard to understand since I am still learning the fundamentals of C++. This was a cool project though!

  4. I have run the code but the code is only running the draw function repeatedly and I am not able to input anything.

  5. so i fixed some problems and did some quality upgrades:

    1)whenever he takes we fruit the "o" pops up at the top left corner of the map.
    to fix that go to logic() and change from:
    for(int i=1; i < nTail; i++)
    for(int i=1; i <= nTail; i++)

    2)also you move you can backtrack and instantly kill yourself.
    to change that go to input() and change it to:

    switch (_getch()){
    case 'a': if(dir != RIGHT){dir = LEFT;}
    case 'd': if(dir != LEFT){dir = RIGHT;}
    case 'w': if(dir != DOWN){dir = UP;}
    case 's': if(dir != UP){dir = DOWN;}
    case 'x': gameover = true;

    3) I also changed 'x' from gameover to pause by replacing:
    case 'x': gameover = true;
    case 'x': dir = STOP;
    and putting everything in logic() into: if(dir != STOP)

    there is also a problem with fruit spawning inside snakes tail but I am too lazy to fix it.

  6. I love this tutorial but is there a chance that you could make new snake game tutorial where u explain all the commands that you use?

  7. My PC is so fast, that I can't control the snake and for some reason Sleep() doesn't work. Does anybody know how i can fix that?

  8. incase people dont understand how to see the score before the console closes on gameover, try adding



    cout << "Enter your deathscreen text here" << score << endl;

    cout << "Press Enter To Quit";


    right above the return 0; line in main, this will give you an nice little deathscreen that shows your score when you die.

  9. When you run finally this project on the right i’ve seen letter ‘o’ which appears and disappers immediately. Why that happens???

  10. I was using visual studios and I ended up still messing up the "o"s in the corner even after watching your video and debugging a thousand times… plz help

  11. There is a little bug like if if it's going right and I press to go left then it's game over so how to fix it

  12. Why don't you just have a list of [x, y] for the tail? And just remove the segment at the end of the list and just add a new one on the start?

  13. Thanks. I learnt a lot , yet I could not run the game through code blocker and have a problem with visual studio 2019.

  14. Hi, Nvitanovic. Your tutorial is great and I used it but I have a problem. First of all the program flickers too much that I can't see anything. Second of all my snakes head moves so fast and vanishes after a second and I can't catch the fruits and the game instantly terminates. I was hoping if you or anyone could help me.(BTW will the sleep thing help any of those problems?)

  15. The fruit move all over the screen but I don’t see any issue with my programs
    Does someone else have the same issue

  16. I just can't seem to understand it
    int prevX = tailX[0];

    int prevY = tailY[0];

    int prev2X, prev2Y;

    tailX[0] = x;

    tailY[0] = y;

    for (int i = 1; i < nTail; i++)


    prev2X = tailX[i];

    prev2Y = tailY[i];

    tailX[i] = prevX;

    tailY[i] = prevY;

    prevX = prev2X;

    prevY = prev2Y;


Leave a Reply

Your email address will not be published. Required fields are marked *