Hello, I would like to make a snake game. Here is what I have in mind:
Any ideas how to do this are welcome. Could any of you tell what I need next? . I haven't done this before, thanks.Code:struct dot // snake position { int x; int y; }
Hello, I would like to make a snake game. Here is what I have in mind:
Any ideas how to do this are welcome. Could any of you tell what I need next? . I haven't done this before, thanks.Code:struct dot // snake position { int x; int y; }
> 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.
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.