Worms -- OOP Redo  2016-01
Worms-Redo Project as a learning vehicle.
Functions | Variables
control.cpp File Reference

Go to the source code of this file.

Functions

int userControl ()
 
int userKeyPress (int c)
 

Variables

int idelay = 10
 
int paused = 0
 
int slowness
 
int tdelay
 

Function Documentation

int userControl ( )

Definition at line 29 of file control.cpp.

References asogRows, EOLN, ESC, getChar, hxWorms, idelay, msg, paused, showMsg(), slowness, tdelay, and userKeyPress().

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 }
int paused
Definition: control.cpp:6
int userKeyPress(int c)
Definition: control.cpp:11
int idelay
Definition: control.cpp:7
int asogRows
Definition: display.cpp:18
#define EOLN
Definition: worms.h:31
char msg[1024]
Definition: display.cpp:4
int hxWorms
int tdelay
Definition: control.cpp:8
#define getChar()
Definition: worms.h:28
void showMsg(int y)
Definition: display.cpp:6
#define ESC
Definition: worm.hpp:13
int slowness
Definition: control.cpp:5
int userKeyPress ( int  c)

Definition at line 11 of file control.cpp.

References min, paused, random, and slowness.

Referenced by userControl().

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 }
int paused
Definition: control.cpp:6
#define random(x)
Definition: worm.hpp:10
#define min(a, b)
Definition: worm.hpp:12
int slowness
Definition: control.cpp:5

Variable Documentation

int idelay = 10

Definition at line 7 of file control.cpp.

Referenced by userControl().

int paused = 0

Definition at line 6 of file control.cpp.

Referenced by userControl(), and userKeyPress().

int slowness

Definition at line 5 of file control.cpp.

Referenced by userControl(), and userKeyPress().

int tdelay

Definition at line 8 of file control.cpp.

Referenced by userControl().