mirror of
https://github.com/Motschen/Adventura.git
synced 2025-12-18 12:45:10 +01:00
clean: restructuring
Got the best grade possible on this game :) - Re-introduce folder structure (folders were not permitted by the task for some reason)
This commit is contained in:
97
src/block.hpp
Normal file
97
src/block.hpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
#include "identifier.hpp"
|
||||
#include "color.hpp"
|
||||
#include "blockSettings.hpp"
|
||||
|
||||
class Block {
|
||||
private:
|
||||
Identifier id_ = Identifier("adventure", "missing");
|
||||
char encoding_;
|
||||
Color color_;
|
||||
BlockSettings settings_;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a block with the given identifier, encoding and settings.
|
||||
*
|
||||
* @param id The (unique) identifier of the block.
|
||||
* @param encoding The encoding of the block, which is the character used to represent it in the game world.
|
||||
* @param settings The settings of the block, which define how the block behaves in the game world.
|
||||
*/
|
||||
Block(Identifier id, char encoding, BlockSettings settings) : Block(id, encoding, Color::RESET, settings) {}
|
||||
/**
|
||||
* Constructs a block with the given identifier, encoding, color and settings.
|
||||
*
|
||||
* @param id The (unique) identifier of the block.
|
||||
* @param encoding The encoding of the block, which is the character used to represent it in the game world.
|
||||
* @param color The color of the block.
|
||||
* @param settings The settings of the block, which define how the block behaves in the game world.
|
||||
*/
|
||||
Block(Identifier id, char encoding, Color color, BlockSettings settings) {
|
||||
this->id_ = id;
|
||||
this->encoding_ = encoding;
|
||||
this->color_ = color;
|
||||
this->settings_ = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings associated with the block.
|
||||
*
|
||||
* @return The settings of the block, including solidity, pushability, and more.
|
||||
*/
|
||||
BlockSettings getSettings() {
|
||||
return settings_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier of the block.
|
||||
*
|
||||
* This identifier is used by the game to uniquely identify the block.
|
||||
*
|
||||
* @return The identifier of the block.
|
||||
*/
|
||||
Identifier getId() {
|
||||
return id_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color of the block.
|
||||
*
|
||||
* The color is used when drawing the block in the world.
|
||||
*
|
||||
* @return The color of the block.
|
||||
*/
|
||||
Color getColor() {
|
||||
return color_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character encoding of the block.
|
||||
*
|
||||
* This character is used in the text file as well as the terminal to represent the block.
|
||||
*
|
||||
* @return The character encoding of the block.
|
||||
*/
|
||||
char getEncoding() {
|
||||
return encoding_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character encoding for the block.
|
||||
*
|
||||
* This encoding is used to represent the block in text files and the terminal.
|
||||
*
|
||||
* @param encoding The character encoding to set for the block.
|
||||
*/
|
||||
void setEncoding(char encoding) {
|
||||
this->encoding_ = encoding;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out) {
|
||||
out << encoding_;
|
||||
return out;
|
||||
}
|
||||
bool operator==(Block otherBlock) {
|
||||
return this->getId() == otherBlock.getId();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user