Hi guys. I am beginner at developing and currently learning c#. I was asked for developing a console based snake game by my knowlage of c#. So i have to develop the game by using classes( not structs etc) arrays methods..

I can use any ideas on that matter.
Thanks.

Recommended Answers

All 3 Replies

First setup an array. 20x20 is a good size, but you can go bigger.
Create a set of snake object. Give the snakes locations on the array.
Give the snakes each initial directions. It might help if they were all set on a different side of a wall, and have them move inward away from the wall.

In your main loop
Check for user input.
Adjust player snake's direction.
Process a simple decision making function for the computer snakes:
Something in my way? Check which way is clear, and move in that direction.
Going to crash anyway? OK, snake dies.
Player snake dead? Game over.
Advance each living snake one space.
Clear the screen.
Draw the grid on the screen.
Put in small pause to make the game play-able. You'll be dead in milliseconds otherwise.
Loop.

Okay, i got a new problem. I can draw the snake and move it with arrow keys. But i cant figure out the constant moving part. Any thoughts?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.