90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2021 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 "graphics/mesh.hpp"
|
|
#include "graphics/model.hpp"
|
|
#include "graphics/shader_program.hpp"
|
|
#include "graphics/material.hpp"
|
|
|
|
#include "engine/object.hpp"
|
|
#include "renderable.hpp"
|
|
#include "engine/resource_manager.hpp"
|
|
#include "math/vec.hpp"
|
|
#include "config.hpp"
|
|
|
|
#include <memory> //unique_ptr
|
|
|
|
gfx::unified_mesh square_mesh(const gfx::material& blank, const gfx::material& o, const gfx::material& x);
|
|
|
|
class tile : public renderable_iface, public egn::object_base
|
|
{
|
|
public:
|
|
enum class value{
|
|
BLANK,
|
|
O,
|
|
X,
|
|
};
|
|
|
|
private:
|
|
gfx::model* m_model;
|
|
value m_active_value = value::BLANK;
|
|
math::vec4<float> m_color_filter = {};
|
|
|
|
public:
|
|
tile(gfx::model* model);
|
|
|
|
void set_value(value v);
|
|
value get_value()const;
|
|
|
|
void set_color(const math::vec4<float>& color);
|
|
|
|
void render(gfx::shader_program&)override;
|
|
|
|
|
|
};
|
|
class board : public renderable_iface, public egn::object_base
|
|
{
|
|
private:
|
|
std::unique_ptr<tile[]> m_tiles;
|
|
public:
|
|
board(egn::resource_manager& r);
|
|
~board(void) = default;
|
|
|
|
tile::value check_winner(void)const;
|
|
|
|
bool is_full(void)const;
|
|
|
|
void render(gfx::shader_program& shader);
|
|
|
|
int click_collision_cheat(const math::vec3<GLfloat>&)const;
|
|
|
|
void set_tile(int index, tile::value value);
|
|
tile::value get_tile(int index)const;
|
|
|
|
private:
|
|
tile::value check_rows_(void)const;
|
|
tile::value check_columns_(void)const;
|
|
tile::value check_diagonals_(void)const;
|
|
};
|
|
|
|
|
|
#endif
|