Worms -- OOP Redo  2016-01
Worms-Redo Project as a learning vehicle.
display.cpp
Go to the documentation of this file.
1 
2 /* display.cpp */
3 
4 char msg[1024];
5 
6 void showMsg(int y)
7 {
8  msg[1023] = '\0';
9  mvCursor(y, 0);
10  putString(msg);
11  screenFlush();
12 }
13 
14 #define MAXrow 100
15 #define MAXcol 100
16 ASOG passive[MAXrow * MAXcol]; // for carrots and dead worms
17 ASOG screen[MAXrow * MAXcol]; // what gets displayed
18 int asogRows, asogCols; // the actual size of 'worm area'
19 #define asog(ptr, row, col) (ptr + row*asogCols + col)
20 
22 {
23  for(ASOG *p = asog(passive, asogRows, 1); p-- > passive;) {
24  p->attr = WA_DIM;
25  p->onec = CARROT;
26  }
27 }
28 
29 void showScreen()
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 }
39 
40 /* Show a single worm. pre: wp != 0. post: It is drawn on passive[]
41  if it is dead. If alive, it is drawn on screen[]. If eaten, not
42  drawn. ; */
43 
44 void showOneWorm(WORM * wp)
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 }
56 
57 /* Display the carrots, the dead worms, and the current positions of
58  one (pre: wp != 0) or all (pre: wp == 0) worms. globals: passive[]
59  read-only. pre: none; post: ... ; */
60 
61 void showWormsAndCarrots(WORM * wp)
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 }
71 
void showScreen()
Definition: display.cpp:29
#define putChar(c)
Definition: worms.h:26
int color
Definition: worm.hpp:64
#define CARROT
Definition: worm.hpp:14
int asogRows
Definition: display.cpp:18
int onec
Definition: worms.h:16
#define headSeg(wp)
Definition: worm.cpp:6
#define MAXrow
Definition: display.cpp:14
Definition: worm.hpp:77
void showWormsAndCarrots(WORM *wp)
Definition: display.cpp:61
#define MAXcol
Definition: display.cpp:15
#define putString(s)
Definition: worms.h:27
int asogCols
Definition: display.cpp:18
char msg[1024]
Definition: display.cpp:4
int hxWorms
void showMsg(int y)
Definition: display.cpp:6
ASOG passive[MAXrow *MAXcol]
Definition: display.cpp:16
void sprinkleCarrots()
Definition: display.cpp:21
void showOneWorm(WORM *wp)
Definition: display.cpp:44
ASOG screen[MAXrow *MAXcol]
Definition: display.cpp:17
WormInfo worm_info[]
Definition: worm.hpp:71
int attr
Definition: worms.h:17
#define screenFlush()
Definition: worms.h:29
#define mvCursor(y, x)
Definition: worms.h:25
#define asog(ptr, row, col)
Definition: display.cpp:19