Worms -- OOP Redo
2016-01
Worms-Redo Project as a learning vehicle.
Main Page
Related Pages
Classes
Files
File List
File Members
control.cpp
Go to the documentation of this file.
1
2
/* control.cpp game control */
3
4
/* parameters for the 'graphical' (such as it is) display */
5
int
slowness
;
// slowness number
6
int
paused
= 0;
// == 1 iff paused
7
int
idelay
= 10;
// delay increment
8
int
tdelay
;
// total delay yet to do
9
10
11
int
userKeyPress
(
int
c)
12
{
13
switch
(c) {
14
case
'+'
:
slowness
-=
min
(
slowness
, 100);
break
;
15
case
'-'
:
slowness
+= 100;
break
;
16
case
'f'
:
slowness
= 0;
break
;
17
case
's'
:
/* for you todo: highlight a worm */
break
;
18
case
'k'
:
/* for you todo: kill the highlighted worm */
break
;
19
case
'w'
: createWorm((WORM_KIND)
random
(3), say[
random
(Nsay)]);
break
;
20
case
' '
:
paused
^= 1;
break
;
21
}
22
return
c;
23
}
24
25
/* User can control the speed, etc. The total delay required, tdelay,
26
is doled out in increments of idelay so that keyboard interaction
27
is more responsive. pre: none; post: returns ESC or '\0';; */
28
29
int
userControl
()
30
{
31
sprintf
32
(
msg
,
33
"SPC %s, ESC terminates, k kills-, w creates-, s shows-a-worm"
EOLN
34
"%2d Vegetarians,%2d Cannibals,%2d Scissor-heads,%2d hi-water-mark"
EOLN
35
"%04d slowness, - increases, + reduces, f full-speed"
EOLN
,
36
(
paused
?
"resumes"
:
"pauses "
),
37
nVegetarians, nCannibals, nScissors,
hxWorms
,
slowness
);
38
showMsg
(
asogRows
+ 1);
39
for
(
tdelay
=
slowness
+1;
tdelay
> 0;
tdelay
-=
idelay
) {
40
char
c =
userKeyPress
(
getChar
());
// no-delay
41
if
(c ==
ESC
)
return
ESC
;
42
if
(
paused
)
tdelay
+=
idelay
;
43
if
(
idelay
> 0)
44
usleep(1000 *
idelay
);
45
}
46
return
'\0'
;
47
}
48
paused
int paused
Definition:
control.cpp:6
userControl
int userControl()
Definition:
control.cpp:29
userKeyPress
int userKeyPress(int c)
Definition:
control.cpp:11
idelay
int idelay
Definition:
control.cpp:7
asogRows
int asogRows
Definition:
display.cpp:18
EOLN
#define EOLN
Definition:
worms.h:31
msg
char msg[1024]
Definition:
display.cpp:4
hxWorms
int hxWorms
tdelay
int tdelay
Definition:
control.cpp:8
getChar
#define getChar()
Definition:
worms.h:28
showMsg
void showMsg(int y)
Definition:
display.cpp:6
random
#define random(x)
Definition:
worm.hpp:10
ESC
#define ESC
Definition:
worm.hpp:13
min
#define min(a, b)
Definition:
worm.hpp:12
slowness
int slowness
Definition:
control.cpp:5
Generated on Thu May 19 2016 15:14:16 for Worms -- OOP Redo by
1.8.11