our_dick/include/ttt/board.hpp

99 lines
2.6 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_BOARD_HPP
#define OUR_DICK_BOARD_HPP
#include <rml/vec.hpp>
#include "config.hpp"
#include <memory> //unique_ptr, shared_ptr
#include "egn/object.hpp"
#include "wip/renderable.hpp"
#include "wip/renderer.hpp"
#include "wip/mesh.hpp"
#include "wip/material.hpp"
#include "wip/draw_command.hpp"
#include "wip/shader.hpp"
class new_tile : public egn::object
{
public:
enum class state{
BLANK = 0,
X,
O
};
private:
rml::vec4f m_color_filter;
public:
state value = state::BLANK;
new_tile(void);
new_tile(state start_value);
void set_color(const rml::vec4f& color);
const rml::vec4f& get_color(void)const;
};
class new_board : public wip::gfx::renderable, public egn::object
{
private:
static constexpr wip::gfx::vertex s_mesh_vertices[] = {
{{-1, 1, 0}, {0, 1}},
{{-1, -1, 0}, {0, 0}},
{{ 1, -1, 0}, {1, 0}},
{{ 1, -1, 0}, {1, 0}},
{{ 1, 1, 0}, {1, 1}},
{{-1, 1, 0}, {0, 1}}
};
private:
std::shared_ptr<wip::gfx::material> m_blank;
std::shared_ptr<wip::gfx::material> m_x;
std::shared_ptr<wip::gfx::material> m_o;
std::shared_ptr<wip::gfx::mesh> m_tile_mesh;
std::unique_ptr<new_tile[]> m_tiles;
public:
new_board(wip::gfx::renderer& r, const std::shared_ptr<wip::gfx::material>& blank, const std::shared_ptr<wip::gfx::material>& x, const std::shared_ptr<wip::gfx::material>& o);
new_tile::state check_winner(void)const;
bool is_full(void)const;
int click_collision_cheat(const rml::vec3f&)const;
void set_tile(int index, new_tile::state value);
new_tile& get_tile(int index);
const new_tile& get_tile(int index)const;
void reset(void);
void submit_render(wip::gfx::renderer& r)override;
void render(wip::gfx::renderer& r, wip::gfx::draw_command& c)override;
private:
new_tile::state check_rows_(void)const;
new_tile::state check_columns_(void)const;
new_tile::state check_diagonals_(void)const;
wip::gfx::material& get_material_for_(new_tile::state v);
};
#endif