Beaucoup de choses. (Fin du TP1 si pas d'épiphanie)
This commit is contained in:
parent
48d35dcf7c
commit
4deb7418c3
@ -151,6 +151,9 @@
|
||||
<ClCompile Include="chunk.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\Users\Mark_\Downloads\tp01.pdf" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -45,4 +45,7 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\Users\Mark_\Downloads\tp01.pdf" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1 +1,26 @@
|
||||
#include "blockarray3d.h"
|
||||
|
||||
BlockArray3d::BlockArray3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) {
|
||||
m_blocks = new BlockType[x * y * z];
|
||||
Reset(BTYPE_AIR);
|
||||
}
|
||||
|
||||
BlockArray3d::BlockArray3d(BlockArray3d& ba) : m_x(ba.m_x), m_y(ba.m_y), m_z(ba.m_z) {
|
||||
m_blocks = new BlockType[ba.m_x*ba.m_y*ba.m_z];
|
||||
|
||||
for (int index = 0; index < (m_x * m_y * m_z); ++index)
|
||||
m_blocks[index] = ba.m_blocks[index];
|
||||
}
|
||||
|
||||
BlockArray3d::~BlockArray3d() { delete[] m_blocks; }
|
||||
|
||||
void BlockArray3d::Set(int x, int y, int z, BlockType type) { m_blocks[GetPosition(x, y, z)] = type; }
|
||||
|
||||
BlockType BlockArray3d::Get(int x, int y, int z) const { return m_blocks[GetPosition(x, y, z)]; }
|
||||
|
||||
void BlockArray3d::Reset(BlockType type) {
|
||||
for (int index = 0; index < (m_x * m_y * m_z); ++index)
|
||||
m_blocks[index] = type;
|
||||
}
|
||||
|
||||
int BlockArray3d::GetPosition(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); }
|
||||
|
@ -5,16 +5,20 @@
|
||||
|
||||
class BlockArray3d {
|
||||
public:
|
||||
BlockArray3d();
|
||||
BlockArray3d(int x, int y, int z);
|
||||
BlockArray3d(BlockArray3d& ba);
|
||||
~BlockArray3d();
|
||||
virtual ~BlockArray3d();
|
||||
|
||||
protected:
|
||||
void Set(int x, int y, int z, BlockType type);
|
||||
BlockType Get(int x, int y, int z) const;
|
||||
void Reset(BlockType type);
|
||||
|
||||
private:
|
||||
int* arr;
|
||||
BlockType* m_blocks;
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_z;
|
||||
|
||||
int GetPosition(int x, int y, int z) const;
|
||||
};
|
||||
#endif
|
@ -1 +1,13 @@
|
||||
#include "blockinfo.h"
|
||||
|
||||
BlockInfo::BlockInfo(BlockType type, const std::string& name): m_name(name), m_type(type) { m_durability = 0; }
|
||||
|
||||
BlockInfo::~BlockInfo() { }
|
||||
|
||||
BlockType BlockInfo::GetType() const { return m_type; }
|
||||
|
||||
void BlockInfo::SetDurability(int durability) { m_durability = durability; }
|
||||
|
||||
int BlockInfo::GetDurability() const { return m_durability; }
|
||||
|
||||
void BlockInfo::Show() const { std::cout << "Name: " << m_name << "; Type " << m_type << "; Durability: " << m_durability << std::endl; }
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define BLOCKINFO_H__
|
||||
|
||||
#include "define.h"
|
||||
#include <iostream>
|
||||
|
||||
class BlockInfo {
|
||||
public:
|
||||
@ -13,6 +14,11 @@ public:
|
||||
void SetDurability(int durability);
|
||||
int GetDurability() const;
|
||||
void Show() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
int m_durability;
|
||||
BlockType m_type;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1 +1,13 @@
|
||||
#include "chunk.h"
|
||||
|
||||
Chunk::Chunk(): BlockArray3d(CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z) {}
|
||||
|
||||
Chunk::Chunk(Chunk& chk) : BlockArray3d(chk) {}
|
||||
|
||||
Chunk::~Chunk() {}
|
||||
|
||||
void Chunk::RemoveBlock(int x, int y, int z) { Set(x, y, z, BTYPE_AIR); }
|
||||
|
||||
void Chunk::SetBlock(int x, int y, int z, BlockType type) { Set(x, y, z, type); }
|
||||
|
||||
BlockType Chunk::GetBlock(int x, int y, int z) const { return Get(x, y, z); }
|
||||
|
@ -7,7 +7,8 @@
|
||||
class Chunk : public BlockArray3d {
|
||||
public:
|
||||
Chunk();
|
||||
~Chunk();
|
||||
Chunk(Chunk& chk);
|
||||
virtual ~Chunk();
|
||||
|
||||
void RemoveBlock(int x, int y, int z);
|
||||
void SetBlock(int x, int y, int z, BlockType type);
|
||||
|
@ -1,5 +1,59 @@
|
||||
#include "main.h"
|
||||
|
||||
int main() {
|
||||
|
||||
Chunk* testchunk = new Chunk();
|
||||
std::vector<BlockInfo*> testblock;
|
||||
|
||||
std::cout << "-Test 1-------BlockInfo----------" << std::endl;
|
||||
|
||||
testblock.push_back(new BlockInfo(BTYPE_AIR, "The air in the sky"));
|
||||
testblock.push_back(new BlockInfo(BTYPE_DIRT, "The dirt on the ground"));
|
||||
testblock.push_back(new BlockInfo(BTYPE_GRASS, "The grass on the dirt"));
|
||||
|
||||
testblock[1]->SetDurability(5);
|
||||
testblock[2]->SetDurability(6);
|
||||
|
||||
for (int index = 0; index < testblock.size(); ++index)
|
||||
testblock[index]->Show();
|
||||
|
||||
std::cout << "GetDurability: " << testblock[0]->GetDurability() << " and " << testblock[1]->GetDurability() << " and " << testblock[2]->GetDurability() << std::endl;
|
||||
std::cout << "GetType: " << testblock[0]->GetType() << " and " << testblock[1]->GetType() << " and " << testblock[2]->GetType() << std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "-Test 2--------Chunk/BlockArray3D---------" << std::endl;
|
||||
testchunk->SetBlock(1, 0, 0, BTYPE_DIRT);
|
||||
testchunk->SetBlock(2, 0, 0, BTYPE_GRASS);
|
||||
testblock.push_back(new BlockInfo(testchunk->GetBlock(0, 0, 0), "A new block in the chunk"));
|
||||
testblock.push_back(new BlockInfo(testchunk->GetBlock(1, 0, 0), "A dirty block in the chunk"));
|
||||
testblock.push_back(new BlockInfo(testchunk->GetBlock(2, 0, 0), "A grassy block in the chunk"));
|
||||
|
||||
for (int index = 3; index < testblock.size(); ++index)
|
||||
testblock[index]->Show();
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "-Test 3--------Chunk Copy---------------" << std::endl;
|
||||
Chunk testchunkcopy(*testchunk);
|
||||
delete testchunk;
|
||||
testblock.push_back(new BlockInfo(testchunkcopy.GetBlock(0, 0, 0), "A block in a copied chunk"));
|
||||
testblock.push_back(new BlockInfo(testchunkcopy.GetBlock(1, 0, 0), "A dirty block in a copied chunk"));
|
||||
testblock.push_back(new BlockInfo(testchunkcopy.GetBlock(1, 0, 0), "A grassy block in a copied chunk"));
|
||||
|
||||
for (int index = 6; index < testblock.size(); ++index)
|
||||
testblock[index]->Show();
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "-Test 3--------Chunk Reset/Remove Block-----------" << std::endl;
|
||||
testchunkcopy.Reset(BTYPE_GRASS);
|
||||
testchunkcopy.RemoveBlock(3, 0, 0);
|
||||
|
||||
testblock.empty();
|
||||
|
||||
for (int index = 0; index < 10; ++index)
|
||||
testblock.push_back(new BlockInfo(testchunkcopy.GetBlock(index, 0, 0), "A block in a reset chunk containing lots of grass"));
|
||||
|
||||
for (int index = 0; index < testblock.size(); ++index)
|
||||
testblock[index]->Show();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
#ifndef MAIN_H__
|
||||
#define MAIN_H__
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "define.h"
|
||||
#include "chunk.h"
|
||||
#include "blockinfo.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user