cfield.h 1.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#ifndef CFIELD_H
#define CFIELD_H

#include <inttypes.h>
#include <vector>
#include <QString>
class QIODevice;

namespace ActorRobot {

enum WallDir {
	LEFT_WALL = 1,
	RIGHT_WALL = 2,
	DOWN_WALL =  4,
	UP_WALL = 8
};

static const int MIN_TEMP = -273;

struct CFieldItem
{
	CFieldItem();
	void setWalls(int wallByte);
24 25
	int getWalls() const;
	bool isEmpty(int wMask = 0) const;
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

	bool isColored;
	bool mark;
	QChar upChar, downChar;
	float radiation;
	float temperature;

	bool upWall;
	bool downWall;
	bool rightWall;
	bool leftWall;
};

class ConsoleField
{
public:
	ConsoleField(uint32_t rows, uint32_t cols);
	void reset(uint32_t rows, uint32_t cols);

	const CFieldItem *getItem(uint32_t row, uint32_t col) const;
	CFieldItem *getItem(uint32_t row, uint32_t col);
	CFieldItem *getCurItem();
48
	static int createWallMask(uint32_t x, uint32_t y, uint32_t mx, uint32_t my);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

	bool goLeft();
	bool goRight();
	bool goUp();
	bool goDown();

	bool isUpWall() const;
	bool isDownWall() const;
	bool isLeftWall() const;
	bool isRightWall() const;

	uint32_t  robotCol() const { return roboCol; }
	uint32_t  robotRow() const { return roboRow; }
	uint32_t  Cols() const { return roboCols; }
	uint32_t  Rows() const { return roboRows; }

65 66
	int saveToFile(const QString &filename) const;
	int saveToDataStream(QIODevice &stream) const;
67 68 69 70 71 72 73 74 75 76 77
	int loadFromFile(const QString &filename);
	int loadFromDataStream(QIODevice *stream);

private:
	std::vector< std::vector<CFieldItem> > items;
	uint32_t roboRow, roboCol;
	uint32_t roboRows, roboCols;
};

} // ActorRobot namespace
#endif // CFIELD_H