- 10
Programming source code for c++ of snake game with 0 error
pls answer quickly
6 Réponses
+ 11
There are many examples of this online. Google or Bing will provide you the code you seek
+ 8
lol@Ace!
+ 5
If you will take a source from the internet, please don't copy paste the code without giving credit.
+ 3
Well I can get you started on how to implement it:
These are likely the things you will need to do:
* Firstly, you need to find out how to do UI in C++.
Such as a canvas, or drawing a rectangle.
* Then, choose the size of your snake.
* This is an approach which is not neccessary but something I did,
Turn the snake block into an object. With x and y coordinates. This is what every part of the snake will be.
* Each Snake object will be placed in an array
* Move the snake.
Always be moving the snake, the player will only be able to modify its direction. So, move the snake based on its direction.
* Randomly place an apple on the board, also do so if the user touches the apple.
Optional:
Make an apple an Object with a xPos and yPos.
When it is created (in the constructor) create the apple at the xPos/yPos. These should be random locations on the screen. This can just be a rectangle or circle, up to you.
* Optional:
If the snake size is greater than 1, touching the edges of the canvas will make you loose..
* Getting an apple will add a another, new snake object to the array. So, you will need to check if the user touches the apple.
* All snake objects in the array, except the first one, will modify their positions to be the previous sbake position.
array[i-1] = array[i],
Where i is an int that goes through the array, and is increasing.
* If one snake object touches another, gameOver.
You likely only need to check if the head (first one), touches any others in the array.
+ 1
actually I searched a lot on Google type on pc but every program has some mistake that's why I need a good guideline