Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

Field Class Reference

Inheritance diagram for Field:

Inheritance graph
[legend]
Collaboration diagram for Field:

Collaboration graph
[legend]

Detailed Description

Two dimensional game field.

Definition at line 12 of file Field.h.

Public Member Functions

 Field (int w, int h)
 Two dimensional array of Cube pointers.
 ~Field ()
int getW () const
int getH () const
CubegetModel (const V2 &loc)
 Get model which occupied this location.
void setModel (const V2 &loc, Cube *model)
 Mark this location as occupied by model.


Constructor & Destructor Documentation

Field::Field int  w,
int  h
 

Two dimensional array of Cube pointers.

Definition at line 22 of file Field.cpp.

00023 {
00024     m_w = w;
00025     m_h = h;
00026 
00027     m_border = ModelFactory::createBorder();
00028     m_border->rules()->takeField(this);
00029 
00030     //NOTE: [y][x] indexes
00031     m_marks = new Cube**[m_h];
00032     for (int y = 0; y < m_h; ++y) {
00033         m_marks[y] = new Cube*[m_w];
00034         memset(m_marks[y], 0, sizeof(Cube *) * m_w);
00035     }
00036 }

Field::~Field  ) 
 

Definition at line 38 of file Field.cpp.

00039 {
00040     for (int y = 0; y < m_h; ++y) {
00041         delete [] m_marks[y];
00042     }
00043     delete [] m_marks;
00044     delete m_border;
00045 }


Member Function Documentation

int Field::getH  )  const [inline]
 

Definition at line 23 of file Field.h.

00023 { return m_h; }

Cube * Field::getModel const V2 loc  ) 
 

Get model which occupied this location.

Empty locations are NULL filled. Locations out of field are filled with border object.

Definition at line 53 of file Field.cpp.

00054 {
00055     int x = loc.getX();
00056     int y = loc.getY();
00057 
00058     //NOTE: hack border everywhere in outher space
00059     Cube *result = m_border;
00060     if ((0 <= x && x < m_w) && (0 <= y && y < m_h)) {
00061         result = m_marks[y][x];
00062     }
00063     return result;
00064 }

int Field::getW  )  const [inline]
 

Definition at line 22 of file Field.h.

00022 { return m_w; }

void Field::setModel const V2 loc,
Cube model
 

Mark this location as occupied by model.

Locations out of field will not be filled.

Definition at line 71 of file Field.cpp.

00072 {
00073     int x = loc.getX();
00074     int y = loc.getY();
00075 
00076     if ((0 <= x && x < m_w) && (0 <= y && y < m_h)) {
00077         m_marks[y][x] = model;
00078     }
00079 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:04 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2