-
Notifications
You must be signed in to change notification settings - Fork 0
/
movement.c
76 lines (54 loc) · 1.4 KB
/
movement.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* FILE NAME: movement.c
AUTHOR : Harshi Kasundi Bandaranayake
DATE : 02/10/2021
INCLUDES : movement.h, */
#include <stdio.h>
#include <stdlib.h>
#include "movement.h"
/* FUNCTION NAME: movement
PURPOSE: takes user input and determines the whether the player should be allowed to move or not and changes player co-ordinates accordingly
IMPORTS: maze, direction, pRow, pCol, row, col
EXPORTS: pSymbol
*/
char movement(char** maze, char direction,int* pRow, int* pCol, int row, int col)
{
/*DECLARING VARIABLES*/
char pSymbol = '^';
/*WHERE direction is 'w' = UP, 's' = DOWN, 'a' = LEFT and 'd' = RIGHT*/
switch(direction)
{
case 'w':
pSymbol = '^';
/*CHECKS IF THE PLAYER IS TRYING TO GO OUT OF THE MAP OR PASS THROUGH A WALL*/
if(maze[*pRow-1][*pCol] != 'o' && *pRow - 1 < row-1 && *pRow - 1 > 0)
{
--*pRow;
}
break;
case 's':
pSymbol = 'v';
if(maze[*pRow+1][*pCol] != 'o' && *pRow+1 < row-1 && *pRow + 1 > 0)
{
++*pRow;
}
break;
case 'a':
pSymbol = '<';
if(maze[*pRow][*pCol-1] != 'o' && *pCol-1 < col-1 && *pCol - 1 > 0)
{
--*pCol;
}
break;
case 'd':
pSymbol = '>';
if(maze[*pRow][*pCol+1] != 'o' && *pCol+1 < col-1 && *pCol + 1 > 0)
{
++*pCol;
}
break;
/*DO NOTHING TO PLAYER'S POSITION*/
default:
pSymbol = '^';
}
return pSymbol;
}