From 43d8434bbc47a94f1505374398698b199a34fa08 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 12 Jan 2017 18:01:01 +0100 Subject: first commit Signed-off-by: Olivier Gayot --- cube.h | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 cube.h (limited to 'cube.h') diff --git a/cube.h b/cube.h new file mode 100644 index 0000000..690fe86 --- /dev/null +++ b/cube.h @@ -0,0 +1,129 @@ +#pragma once + +#include +#include +#include + +enum class color { + none, + + white, + yellow, + orange, + red, + blue, + green, +}; + +std::string to_string(color c); + +class abstract_cube; + +class abstract_face { +public: + abstract_face(const abstract_cube &); + + virtual std::string to_string() const = 0; + +private: + const abstract_cube &_parent_cube; +}; + +class cube1; + +class face1 final: public abstract_face { +public: + face1(const cube1 &parent, color); + + std::string to_string() const; + +private: + const color _color; +}; + +class cube3; + +class face3 final: public abstract_face { +public: + face3(const cube3 &parent); + + std::string to_string() const; + +private: + std::array, 9> _faces; +}; + +class abstract_cube { +public: + void flip_right(); + void flip_left(); + void flip_up(); + void flip_down(); + + /* Return a new face. */ + const std::shared_ptr front() const; + const std::shared_ptr back() const; + const std::shared_ptr left() const; + const std::shared_ptr right() const; + const std::shared_ptr up() const; + const std::shared_ptr down() const; + + std::string to_string() const; + +protected: + abstract_cube() = default; + + std::array, 6> _faces; +}; + +class cube1 final: public abstract_cube { +}; + +class cube3 final: public abstract_cube { +public: + cube3(color, color, color, color, color, color); + + cube3(const cube3 &) = default; + cube3(cube3 &&) = default; + + /* Front face 90 deg clockwise. */ + void f(); + /* Front face 90 deg counter-clockwise. */ + void F(); + + /* Back face 90 deg clockwise. */ + void b(); + /* Back face 90 deg counter-clockwise. */ + void B(); + + /* Left face 90 deg clockwise. */ + void l(); + /* Left face 90 deg counter-clockwise. */ + void L(); + + /* Right face 90 deg clockwise. */ + void r(); + /* Right face 90 deg counter-clockwise. */ + void R(); + + /* Up face 90 deg clockwise. */ + void u(); + /* Up face 90 deg counter-clockwise. */ + void U(); + + /* Down face 90 deg clockwise. */ + void d(); + /* Down face 90 deg counter-clockwise. */ + void D(); + + /* + * +---+---+---+ + * | 0 | 1 | 2 | + * +---+---+---+ + * | 3 | 4 | 5 | + * +---+---+---+ + * | 6 | 7 | 8 | + * +---+---+---+ + */ +}; + -- cgit v1.2.3