Worms -- OOP Redo
2016-01
Worms-Redo Project as a learning vehicle.
Main Page
Related Pages
Classes
Files
File List
File Members
worm.hpp
Go to the documentation of this file.
1
2
/* worm.cpp deals with a single worm */
3
4
#include <stdlib.h>
5
#include <string.h>
6
#include <unistd.h>
7
#include <time.h>
8
9
// temporary cure begin
10
#define random(x) (rand() % x)
11
#define isDigit(x) ('0' <= x && x <= '9')
12
#define min(a, b) ((a) < (b)? (a) : (b))
13
#define ESC '\033' // the ESCape char
14
#define CARROT '.' // a carrot is shown as a dot
15
#define NORTH 00 // TBD
16
#define asog(ptr, row, col) (ptr + row*asogCols + col)
17
#define MAXsegs 100 // max # segments per worm
18
// temporary cure end
19
20
class
Worm
{
21
22
public
:
23
typedef
enum
{
24
VEGETARIAN
,
CANNIBAL
,
SCISSORHEAD
25
}
WormKind
;
// 0, 1, 2
26
27
void
createWorm
(WormKind
type
,
const
char
* sy);
28
29
private
:
30
31
typedef
enum
{
32
EATEN
,
DEAD
,
ALIVE
33
}
LIFE
;
34
35
typedef
struct
{
36
int
x,
y
;
// coordinates of the segment
37
char
c
;
// the letter it carries
38
}
SEGMENT
;
39
40
private
:
// data members
41
WormKind
type
;
// once set, type does not change
42
int
direction
;
// its (head's) direction
43
int
stomach
;
// food value
44
LIFE
status
;
// EATEN, DEAD, or ALIVE; redundant
45
int
nsegs
;
// # of segs in this worm
46
SEGMENT
body
[
MAXsegs
];
// body parts
47
48
private
:
// methods
49
int
isHungry
();
50
void
gotEaten
();
51
void
checkStomach
();
52
void
eatACarrot
();
53
int
isAt
(
int
row,
int
col);
54
void
setVictimWorm
();
55
void
shiftBodyDown
(
Worm
* vp,
int
vsn);
56
Worm
*
sliceTheVictim
(
Worm
* vp,
int
vsn);
57
void
eat
();
58
void
live
();
59
void
showOneWorm
();
60
};
61
62
class
WormInfo
{
63
public
:
64
int
color
;
65
int
capacity
;
// stomach size
66
int
foodValue
;
67
};
68
69
#define COLOR_PAIR(x) (x) // dummy TBD
70
71
WormInfo
worm_info
[] = {
// indexed by WORM_KIND
72
{
COLOR_PAIR
(1), 3, 3},
// from <ncurses.h>
73
{
COLOR_PAIR
(2), 4, 5},
74
{
COLOR_PAIR
(3), 5, 4}
75
};
76
77
class
ASOG
{
78
};
79
80
81
extern
Worm
*
findSlot
();
82
extern
int
asogCols
,
asogRows
;
83
extern
int
xworms
[];
84
extern
int
hxWorms
;
85
extern
Worm
wormArray
[];
86
Worm::gotEaten
void gotEaten()
Definition:
worm.cpp:40
WormInfo::color
int color
Definition:
worm.hpp:64
Worm::eatACarrot
void eatACarrot()
Definition:
worm.cpp:63
WormInfo
Definition:
worm.hpp:62
Worm::ALIVE
Definition:
worm.hpp:32
Worm::sliceTheVictim
Worm * sliceTheVictim(Worm *vp, int vsn)
Definition:
worm.cpp:131
asogCols
int asogCols
Definition:
display.cpp:18
Worm::VEGETARIAN
Definition:
worm.hpp:24
Worm::EATEN
Definition:
worm.hpp:32
findSlot
Worm * findSlot()
Worm::DEAD
Definition:
worm.hpp:32
ASOG
Definition:
worm.hpp:77
Worm::body
SEGMENT body[MAXsegs]
Definition:
worm.hpp:46
Worm::nsegs
int nsegs
Definition:
worm.hpp:45
wormArray
Worm wormArray[]
Worm::direction
int direction
Definition:
worm.hpp:42
Worm::status
LIFE status
Definition:
worm.hpp:44
Worm::SEGMENT
Definition:
worm.hpp:35
Worm::shiftBodyDown
void shiftBodyDown(Worm *vp, int vsn)
Definition:
worm.cpp:114
hxWorms
int hxWorms
asogRows
int asogRows
Definition:
display.cpp:18
Worm::eat
void eat()
Definition:
worm.cpp:155
Worm::setVictimWorm
void setVictimWorm()
Definition:
worm.cpp:94
Worm::SCISSORHEAD
Definition:
worm.hpp:24
Worm::SEGMENT::y
int y
Definition:
worm.hpp:36
xworms
int xworms[]
Worm::checkStomach
void checkStomach()
Definition:
worm.cpp:51
MAXsegs
#define MAXsegs
Definition:
worm.hpp:17
Worm::isAt
int isAt(int row, int col)
Definition:
worm.cpp:76
Worm::createWorm
void createWorm(WormKind type, const char *sy)
Definition:
worm.cpp:208
Worm::live
void live()
Definition:
worm.cpp:184
Worm::stomach
int stomach
Definition:
worm.hpp:43
Worm::isHungry
int isHungry()
Definition:
worm.cpp:31
Worm::CANNIBAL
Definition:
worm.hpp:24
Worm::showOneWorm
void showOneWorm()
Definition:
worm.cpp:15
Worm::WormKind
WormKind
Definition:
worm.hpp:23
worm_info
WormInfo worm_info[]
Definition:
worm.hpp:71
Worm::SEGMENT::c
char c
Definition:
worm.hpp:37
WormInfo::foodValue
int foodValue
Definition:
worm.hpp:66
COLOR_PAIR
#define COLOR_PAIR(x)
Definition:
worm.hpp:69
WormInfo::capacity
int capacity
Definition:
worm.hpp:65
Worm
Definition:
worm.hpp:20
Worm::type
WormKind type
Definition:
worm.hpp:41
Worm::LIFE
LIFE
Definition:
worm.hpp:31
Generated on Thu May 19 2016 15:14:16 for Worms -- OOP Redo by
1.8.11