-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacman.cpp
144 lines (129 loc) · 3 KB
/
pacman.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <ncurses.h>
#include <iostream>
#include <unistd.h>
#include <time.h>
#include "pac.h"
#include "ghost.h"
#include "angry.h"
#include "dreamer.h"
#include "confused.h"
#include "bored.h"
#include "stats.h"
#include "map.h"
using namespace std;
int main(int argc, char **argv) {
initscr();
cbreak();
noecho();
curs_set(0);
WINDOW *win = newwin(28, 28, 1, 1);
nodelay(win, true);
keypad(win, true);
int pointsCollected = 0;
bool huntState = true;
srand(time(NULL));
Pac *p = new Pac(3, win, 16, 11, pac, false);
Stats *s = new Stats(win, 25, 1, 0, 3, 12);
Bored *bored = new Bored(win, 10, 12, ghost, true);
Angry *dreamer = new Angry(win, 10, 9, ghost, true);
Angry *angry = new Angry(win, 10, 10, ghost, true);
Confused *confused = new Confused(win, 10, 13, ghost, true);
// Start screen
refresh();
mvwprintw(win, 11, 10, "PACMAN");
mvwprintw(win, 13, 3, "Press a key to start");
wrefresh(win);
getch();
// Initial display
Map *m = new Map(win);
p->display();
confused->display();
dreamer->display();
angry->display();
bored->display();
wrefresh(win);
usleep(1500000);
while(1) {
// Refresh
flushinp();
wrefresh(win);
usleep(frameDelay);
// Update and display
if (confused->decideAndUpdate(p->getY(), p->getX(), p->getDirection()))
pointsCollected++;
confused->display();
if (dreamer->decideAndUpdate(p->getY(), p->getX(), p->getDirection()))
pointsCollected++;
dreamer->display();
if (angry->decideAndUpdate(p->getY(), p->getX(), p->getDirection()))
pointsCollected++;
angry->display();
if (bored->decideAndUpdate(p->getY(), p->getX(), p->getDirection()))
pointsCollected++;
bored->display();
// Update lives and move all ghosts to spawn if pacman is dead
if(s->updateLives(p->getLives())) {
confused->revive();
dreamer->revive();
angry->revive();
bored->revive();
}
// Game over screen
if (p->getLives() == 0) {
s->display();
wrefresh(win);
usleep(1000000);
wclear(win);
refresh();
mvwprintw(win, 11, 10, "GAME OVER");
wrefresh(win);
getch();
break;
}
// Update pacman
s->display();
p->updateLocation();
switch(p->updateStats()) {
case 0:
pointsCollected++;
break;
case 1:
huntState = false;
p->setRole(!huntState);
confused->setRole(huntState);
dreamer->setRole(huntState);
angry->setRole(huntState);
bored->setRole(huntState);
break;
case 2:
usleep(1500000);
default:
break;
}
s->updateScore(p->getScore());
if (s->updatePowerUp(huntState)) {
huntState = true;
p->setRole(!huntState);
confused->setRole(huntState);
dreamer->setRole(huntState);
angry->setRole(huntState);
bored->setRole(huntState);
}
p->display();
// Win screen
if (pointsCollected == 181) {
s->display();
wrefresh(win);
usleep(1000000);
wclear(win);
refresh();
mvwprintw(win, 11, 10, "YOU WON");
mvwprintw(win, 13, 8, "Score: %d", p->getScore());
wrefresh(win);
getch();
break;
}
}
endwin();
return 0;
}