Initial commit
This commit is contained in:
48
src/model/Level.cpp
Normal file
48
src/model/Level.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Level.cpp
|
||||
*
|
||||
* Created on: Nov 11, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include "Level.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
Level::Level(size_t layerCount, size_t rowCount, size_t columnCount)
|
||||
: m_cells(new Cell[layerCount * rowCount * columnCount]),
|
||||
m_layers(layerCount),
|
||||
m_rows(rowCount),
|
||||
m_columns(columnCount)
|
||||
{
|
||||
}
|
||||
|
||||
Level::~Level()
|
||||
{
|
||||
delete[] m_cells;
|
||||
}
|
||||
|
||||
|
||||
Cell Level::cell(size_t layer, size_t row, size_t col) const
|
||||
{
|
||||
assert(layer < m_layers);
|
||||
assert(row < m_rows);
|
||||
assert(col < m_columns);
|
||||
|
||||
return m_cells[layer * m_rows * m_columns + row * m_columns + col];
|
||||
}
|
||||
|
||||
void Level::setCell(size_t layer, size_t row, size_t col, Cell value)
|
||||
{
|
||||
assert(layer < m_layers);
|
||||
assert(row < m_rows);
|
||||
assert(col < m_columns);
|
||||
|
||||
m_cells[layer * m_rows * m_columns + row * m_columns + col] = value;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace model */
|
||||
} /* namespace farmlands */
|
45
src/model/Level.h
Normal file
45
src/model/Level.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Level.h
|
||||
*
|
||||
* Created on: Nov 11, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef MODEL_LEVEL_H_
|
||||
#define MODEL_LEVEL_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
typedef int16_t Cell;
|
||||
|
||||
class Level
|
||||
{
|
||||
public:
|
||||
Level(size_t layerCount, size_t rowCount, size_t columnCount);
|
||||
Level(const Level&) = delete;
|
||||
Level& operator= (const Level&) = delete;
|
||||
|
||||
virtual ~Level();
|
||||
|
||||
inline size_t layerCount() const { return m_layers; }
|
||||
inline size_t rowCount() const { return m_rows; }
|
||||
inline size_t columnCount() const { return m_columns; }
|
||||
|
||||
Cell cell(size_t layer, size_t row, size_t col) const;
|
||||
void setCell(size_t layer, size_t row, size_t col, Cell value);
|
||||
|
||||
private:
|
||||
Cell* m_cells;
|
||||
size_t m_layers;
|
||||
size_t m_rows;
|
||||
size_t m_columns;
|
||||
};
|
||||
|
||||
} /* namespace model */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* MODEL_LEVEL_H_ */
|
Reference in New Issue
Block a user