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

Go to the source code of this file.

Macros

#define asog(ptr, row, col)   (ptr + row*asogCols + col)
 
#define MAXcol   100
 
#define MAXrow   100
 

Functions

void showMsg (int y)
 
void showOneWorm (WORM *wp)
 
void showScreen ()
 
void showWormsAndCarrots (WORM *wp)
 
void sprinkleCarrots ()
 

Variables

int asogCols
 
int asogRows
 
char msg [1024]
 
ASOG passive [MAXrow *MAXcol]
 
ASOG screen [MAXrow *MAXcol]
 

Macro Definition Documentation

#define asog (   ptr,
  row,
  col 
)    (ptr + row*asogCols + col)
#define MAXcol   100

Definition at line 15 of file display.cpp.

Referenced by startCurses().

#define MAXrow   100

Definition at line 14 of file display.cpp.

Referenced by startCurses().

Function Documentation

void showMsg ( int  y)

Definition at line 6 of file display.cpp.

References msg, mvCursor, putString, and screenFlush.

Referenced by userControl().

7 {
8  msg[1023] = '\0';
9  mvCursor(y, 0);
10  putString(msg);
11  screenFlush();
12 }
#define putString(s)
Definition: worms.h:27
char msg[1024]
Definition: display.cpp:4
#define screenFlush()
Definition: worms.h:29
#define mvCursor(y, x)
Definition: worms.h:25
void showOneWorm ( WORM *  wp)

Definition at line 44 of file display.cpp.

References asog, ASOG::attr, WormInfo::color, headSeg, ASOG::onec, passive, and worm_info.

Referenced by showWormsAndCarrots().

45 {
46  if (wp->status != EATEN) {
47  ASOG *f = (wp->status == ALIVE ? screen : passive);
48  SEGMENT *bp, *hp = headSeg(wp);
49  for (bp = wp->body + 1; bp <= hp; bp++) {
50  ASOG *g = asog(f, bp->y, bp->x);
51  g->attr = worm_info[wp->type].color;
52  g->onec = bp->c;
53  }
54  }
55 }
int color
Definition: worm.hpp:64
int onec
Definition: worms.h:16
#define headSeg(wp)
Definition: worm.cpp:6
Definition: worm.hpp:77
ASOG passive[MAXrow *MAXcol]
Definition: display.cpp:16
ASOG screen[MAXrow *MAXcol]
Definition: display.cpp:17
WormInfo worm_info[]
Definition: worm.hpp:71
int attr
Definition: worms.h:17
#define asog(ptr, row, col)
Definition: display.cpp:19
void showScreen ( )

Definition at line 29 of file display.cpp.

References asogCols, asogRows, ASOG::attr, mvCursor, ASOG::onec, putChar, screen, and screenFlush.

Referenced by showWormsAndCarrots().

30 {
31  ASOG * sp = screen;
32  for (int y = 0; y < asogRows; y++) {
33  mvCursor(y, 0);
34  for (int x = 0; x < asogCols; x++, sp++)
35  putChar(sp->onec | sp->attr);
36  }
37  screenFlush();
38 }
#define putChar(c)
Definition: worms.h:26
int asogRows
Definition: display.cpp:18
int onec
Definition: worms.h:16
Definition: worm.hpp:77
int asogCols
Definition: display.cpp:18
ASOG screen[MAXrow *MAXcol]
Definition: display.cpp:17
int attr
Definition: worms.h:17
#define screenFlush()
Definition: worms.h:29
#define mvCursor(y, x)
Definition: worms.h:25
void showWormsAndCarrots ( WORM *  wp)

Definition at line 61 of file display.cpp.

References asog, asogRows, hxWorms, screen, showOneWorm(), and showScreen().

62 {
63  ASOG *sp = screen, *se = asog(screen, asogRows, 1);
64  for (ASOG *pp = passive; sp < se; )
65  *sp++ = *pp++; // copy the carrots + dead worms
66  WORM * headWorm = worm + (wp? 1 : hxWorms);
67  for (WORM * wp = worm; wp < headWorm; )
68  showOneWorm(wp++);
69  showScreen();
70 }
void showScreen()
Definition: display.cpp:29
int asogRows
Definition: display.cpp:18
Definition: worm.hpp:77
int hxWorms
ASOG passive[MAXrow *MAXcol]
Definition: display.cpp:16
void showOneWorm(WORM *wp)
Definition: display.cpp:44
ASOG screen[MAXrow *MAXcol]
Definition: display.cpp:17
#define asog(ptr, row, col)
Definition: display.cpp:19
void sprinkleCarrots ( )

Definition at line 21 of file display.cpp.

References asog, asogRows, CARROT, and passive.

22 {
23  for(ASOG *p = asog(passive, asogRows, 1); p-- > passive;) {
24  p->attr = WA_DIM;
25  p->onec = CARROT;
26  }
27 }
#define CARROT
Definition: worm.hpp:14
int asogRows
Definition: display.cpp:18
Definition: worm.hpp:77
ASOG passive[MAXrow *MAXcol]
Definition: display.cpp:16
#define asog(ptr, row, col)
Definition: display.cpp:19

Variable Documentation

int asogCols

Definition at line 18 of file display.cpp.

Referenced by Worm::createWorm(), Worm::live(), showScreen(), and startCurses().

int asogRows
char msg[1024]

Definition at line 4 of file display.cpp.

Referenced by showMsg(), and userControl().

ASOG passive[MAXrow *MAXcol]

Definition at line 16 of file display.cpp.

Referenced by Worm::eatACarrot(), showOneWorm(), Worm::showOneWorm(), and sprinkleCarrots().

ASOG screen[MAXrow *MAXcol]

Definition at line 17 of file display.cpp.

Referenced by Worm::showOneWorm(), showScreen(), and showWormsAndCarrots().