Thread: Snake game

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    69

    Snake game

    Hello, I would like to make a snake game. Here is what I have in mind:

    Code:
    struct dot    // snake position
    {
       int x;
       int y;
    }
    Any ideas how to do this are welcome. Could any of you tell what I need next? . I haven't done this before, thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > Could any of you tell what I need next?
    A pencil and some paper.

    Write some words.
    Draw some pictures.
    https://en.wikipedia.org/wiki/Flowchart
    https://en.wikipedia.org/wiki/Diagramming_software
    https://en.wikipedia.org/wiki/Pseudocode

    You think about such things
    - how do I represent
    -- the board
    -- the snake

    - how to draw the board
    - how to draw the snake

    - what happens when the snake eats a fruit, how to extend the snake.

    And so on.

    Any program larger than "hello world", or the average student assignment summarised in a handful of bullet points, needs planning.

    You're not going to write it all in one go.

    You might not get to finish your first attempt. The trick is to know when you've painted yourself into a corner and have the grace to abandon the code and start again.
    But the 2nd time around, you'll know a hell of a lot more about the problem, and can thus take necessary action.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    68
    If you played the snake game you have notice that it gets longer and longer but the tail is still moving so that dot needs to be removed too.
    So you need to keep the location of this dot is at when it's time to remove it, so you need a buffer that keep track where the head have been prior.
    How big does the buffer need to be?
    As you should implement a rolling-buffer, it does not need to be bigger than the size of the snake.
    As the snake can not be bigger than the screen, that will be the max buffer size.
    So if a 40*32 dot screen and that is the size you need as buffer just to sure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Snake Game help on it please...
    By LekhAsh in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2015, 01:45 AM
  2. Snake game in C.
    By RyRy in forum C Programming
    Replies: 15
    Last Post: 04-06-2014, 06:04 PM
  3. Snake game..
    By Marcus007 in forum C Programming
    Replies: 0
    Last Post: 12-05-2011, 06:58 PM
  4. Help with a snake game?
    By awr7126 in forum Game Programming
    Replies: 2
    Last Post: 12-06-2010, 06:39 PM
  5. Help with snake game in sdl/c
    By joellllmal in forum Game Programming
    Replies: 4
    Last Post: 08-22-2010, 12:14 AM