-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakeMovement.c
57 lines (37 loc) · 1.59 KB
/
snakeMovement.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* FILE NAME: snakeMovement.c
AUTHOR : Harshi Kasundi Bandaranayake
DATE : 02/10/2021
INCLUDES : snakeMovement.h */
#include <stdio.h>
#include <stdlib.h>
#include "snakeMovement.h"
/* FUNCTION NAME: snakeMovement
PURPOSE: moves the snake around the map to follow player
IMPORTS: maze, pRow, pCol, sRow, sCol, row, col
EXPORTS: NONE
*/
void snakeMovement(char** maze,int* pRow, int* pCol, int* sRow, int* sCol, int row, int col)
{
if(*sRow < *pRow && maze[*sRow+1][*sCol] != 'o' && *sRow + 1 < row && *sRow + 1 > 0 && *sCol < col && *sCol > 0)
{
++*sRow;
}else if(*sRow > *pRow && maze[*sRow-1][*sCol] != 'o' && *sRow - 1 < row && *sRow - 1 > 0 && *sCol < col && *sCol > 0){
--*sRow;
}else if(*sCol < *pCol && maze[*sRow][*sCol+1] != 'o' && *sCol + 1 < col && *sCol + 1 > 0 && *sRow < row && *sRow > 0){
++*sCol;
}else if(*sCol > *pCol && maze[*sRow][*sCol-1] != 'o' && *sCol - 1 < col && *sCol + 1 > 0 && *sRow < row && *sRow > 0){
--*sCol;
}/*else if(*sRow == *pRow){
if(*sCol < *pCol && maze[*sRow][*sCol+1] != 'o' && *sCol + 1 < col && *sCol + 1 > 0 && *sRow < row && *sRow > 0){
++*sCol;
}else if(*sCol > *pCol && maze[*sRow][*sCol-1] != 'o' && *sCol - 1 < col && *sCol - 1 > 0 && *sRow < row && *sRow > 0){
--*sCol;
}
}else if(*sCol == *pCol){
if(*sRow < *pRow && maze[*sRow+1][*sCol] != 'o' && *sCol + 1 < col && *sCol + 1 > 0 && *sRow < row && *sRow > 0){
++*sRow;
}else if(*sRow > *pRow && maze[*sRow-1][*sCol] != 'o' && *sRow - 1 < col && *sRow - 1 > 0 && *sRow < row && *sRow > 0){
--*sRow;
}
}*/
}