3 Replies - 6860 Views - Last Post: 13 November 2007 - 08:58 AM Rate Topic: -----

#1 avdonzzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-November 07

Basic structure of snake game in C

Post icon  Posted 13 November 2007 - 03:16 AM

HI, i need to create a basic snake game

this is how it will look like

initial state:

x0000 <- at a location in the map

x = head
0=body

0 increase when it eats #(food)

food is in rand position/color

when the snake eats #, it's head's color change to #'s color, and head's color shift down to body.. etc

can anyone help?
Is This A Good Question/Topic? 0
  • +

Replies To: Basic structure of snake game in C

#2 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Basic structure of snake game in C

Posted 13 November 2007 - 03:30 AM

Start by defining the various elements in your problem in software terms, for example, what is "the map"? and what is "the snake"? etc. - Try to define them in terms of their inputs, attributes, and outputs, as well as what they represent. Doing this should give you a starting point of the kind of data you need to store, and the functions to manipulate that data.

How you write the program is entirely up to you, and the structure of the program will depend largely on the design choices you make. You won't get it right at first, so just give it a go and improve your design as you go along. Build small bits at a time, then get them working - don't try to build the entire program at once

This post has been edited by Bench: 13 November 2007 - 03:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 avdonzzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-November 07

Re: Basic structure of snake game in C

Posted 13 November 2007 - 03:51 AM

doing it right now but i'm struck at this:

void clearBody (int row, int col)
{
write2screen (row, col, BLACK, " ");
}

void snakeBody (int row, int col)
{
write2screen (row, col, RED, "X");

}
void segment (int row, int col)
{
write2screen(row, col, YELLOW, "0");
}

this is the head and segment,

in main:

while (!gameEnd)
{
in = getAchar (); /* get user input */
if ((in==KUP) || (in==KLEFT) || (in==KRIGHT) || (in==KDOWN))
/* move up, left, right, or down */
{

clearBody(row, col);
clearsegment(row, col);
if (in==KUP)
row--;
else if (in == KLEFT)
col--;
else if (in == KDOWN)
row++;
else
col++;
segment(row, col);
snakeBody(row, col);


when i move the key, only the x follow, the 0 doesnt appear.
Was This Post Helpful? 0
  • +
  • -

#4 avdonzzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-November 07

Re: Basic structure of snake game in C

Posted 13 November 2007 - 08:58 AM

can anyone check my coding?
and point me out the errors? :(

Attached File(s)

  • Attached File  snake.txt (3.58K)
    Number of downloads: 357

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1