Originally Posted by
Salem
> my main probles is how to make the snake move and eat
So you've done all of these things?
- initialise the board
- place the food
- create the initial snakes for % and @ players.
How are you representing the snakes?
You need some kind of data structure to represent 'N' segment coordinates of the snake.
As the snake moves, the 'head' occupies the new position and the 'tail' is removed.
Something like say
Code:
void moveSnake(Snake snake, int direction) {
// code
}
You can then do this to put the snake on the board.
Code:
void drawSnake(Snake snake, Board board) {
// code
}
ok so to print the board i used 2 functions
void help_print_board(int size)
Code:
{
int i=0;
printf("%c",BOARD_ELEMENT);
for(i=0;i<size;i++)
{
printf("%c",BOARD_ELEMENT);
}
printf("%c\n",BOARD_ELEMENT);
}
void print_board(char board[N][N], int size)
{
int i=0,j=0;
help_print_board(size);
for(i=0;i<size;i++)
{
printf("%c",BOARD_ELEMENT);
for(j=0;j<size;j++)
{
printf("%c",board[i][j]);
}
printf("%c\n",BOARD_ELEMENT);
}
help_print_board(size);
printf("\n\n");
}
and this array (char board[N][N]) is representing the coordinates on the board
so what i did to print the board initial board is:
void start_board(char board[N][N], int size)
Code:
{
int i=0,j=0;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
board[i][j]=' ';
board[0][0]='%';
board[0][1]='*';
board[0][2]='*';
board[size-1][0]='@';
board[size-1][1]='+';
board[size-1][2]='+';
}
}
food_loc_in(board);
print_board(board,size);
}
and this is the problem how can i represent the snakes?