-
Notifications
You must be signed in to change notification settings - Fork 1
/
pacman.h
119 lines (113 loc) · 3.23 KB
/
pacman.h
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef PACMAN_H
#define PACMAN_H
#include <iostream>
#include "structs.h"
#include <cstdlib>
using namespace std;
struct Pacman{
Coords coords;
int lives;
char current_direction;
char input_direction;
void updatePacmanDirection(int **arr, Pacman &pacman, bool &pacmanCheck);
bool movePacman(int **&arr, Pacman &pacman);
};
void updatePacmanDirection(int **arr, Pacman &pacman){
if(!isThereWall(arr,pacman.coords,pacman.input_direction)){
pacman.current_direction = pacman.input_direction;
}
}
bool movePacman(int **&arr, Pacman &pacman, bool &pacmanCheck, bool &cherryCheck, int &cherryTime){
switch (pacman.current_direction)
{
case 'w':
if(!isThereWall(arr, pacman.coords, 'w')){
if(isThereCherry(arr, pacman.coords, 'w')){
cherryCheck = 1;
cherryTime = 72;
}
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = -1;
}
else{
pacmanCheck = 1;
}
pacman.coords.i--;
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = 2;
}
else{
pacmanCheck = 1;
}
return true;
}
break;
case 's':
if(!isThereWall(arr, pacman.coords, 's')){
if(isThereCherry(arr, pacman.coords, 's')){
cherryCheck = 1;
cherryTime = 72;
}
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = -1;
}
else{
pacmanCheck = 1;
}
pacman.coords.i++;
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = 2;
}
else{
pacmanCheck = 1;
}
return true;
}
break;
case 'd':
if(isThereCherry(arr, pacman.coords, 'd')){
cherryCheck = 1;
cherryTime = 72;
}
if(!isThereWall(arr, pacman.coords, 'd')){
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = -1;
}
else{
pacmanCheck = 1;
}
pacman.coords.j++;
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = 2;
}
else{
pacmanCheck = 1;
}
return true;
}
break;
case 'a':
if(!isThereWall(arr, pacman.coords, 'a')){
if(isThereCherry(arr, pacman.coords, 'a')){
cherryCheck = 1;
cherryTime = 72;
}
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = -1;
}
else{
pacmanCheck = 1;
}
pacman.coords.j--;
if(arr[pacman.coords.i][pacman.coords.j] != -2){
arr[pacman.coords.i][pacman.coords.j] = 2;
}
else{
pacmanCheck = 1;
}
return true;
}
break;
}
}
#endif