Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 2 additions & 74 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,74 +1,2 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

/.idea/
/cmake-build-debug/
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.26)
project(match_three)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "D:/Code/C++/qt6/qt6-static/lib/cmake")

find_package(Qt6 COMPONENTS
Core
Gui
Widgets
REQUIRED)

include_directories(src)

add_executable(match_three main.cpp
src/match_three/match_three.cpp
src/match_three/match_three.ui
src/gamefield/table.cpp
src/gamefield/gamefield.cpp
src/figure/figure_generator.hpp
src/figure/figure.hpp
src/figure/figure.cpp)

target_link_libraries(match_three
Qt::Core
Qt::Gui
Qt::Widgets
)

file(COPY
src/gamefield/gamefield.h
src/gamefield/table.h
DESTINATION ${PROJECT_NAME}_autogen/include)
27 changes: 0 additions & 27 deletions MatchThreeTask.pro

This file was deleted.

9 changes: 0 additions & 9 deletions README.md

This file was deleted.

10 changes: 5 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <QApplication>

#include "widget.h"
#include "match_three/match_three.h"

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
widget w;
w.show();
return a.exec();
QApplication a(argc, argv);
MatchThree mt;
mt.show();
return QApplication::exec();
}
30 changes: 30 additions & 0 deletions src/figure/figure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "figure.hpp"

const QVarLengthArray<QVarLengthArray<Figure::pos_t, 4>, 5> Figure::presets_ = {
{
{{2, 0, 0}, {2, 1, 1}, {2, 2, 2}, {2, 3, 3}},
{{0, 1, 0}, {1, 1, 1}, {2, 1, 2}, {3, 1, 3}},
{{1, 0, 3}, {1, 1, 2}, {1, 2, 1}, {1, 3, 0}},
{{0, 2, 3}, {1, 2, 2}, {2, 2, 1}, {3, 2, 0}}
}, {
{{1, 0, 0}, {0, 1, 1}, {1, 1, 2}, {1, 2, 3}},
{{0, 1, 0}, {1, 1, 2}, {2, 1, 3}, {1, 2, 1}},
{{1, 0, 3}, {1, 1, 2}, {2, 1, 1}, {1, 2, 0}},
{{1, 0, 1}, {0, 1, 3}, {1, 1, 2}, {2, 1, 0}}
}, {
{{0, 1, 0}, {1, 1, 1}, {2, 1, 2}, {0, 2, 3}},
{{1, 0, 2}, {1, 1, 1}, {1, 2, 0}, {2, 2, 3}},
{{2, 0, 3}, {0, 1, 2}, {1, 1, 1}, {2, 1, 0}},
{{0, 0, 3}, {1, 0, 0}, {1, 1, 1}, {1, 2, 2}}
}, {
{{1, 1, 0}, {2, 1, 1}, {0, 2, 2}, {1, 2, 3}},
{{1, 0, 1}, {1, 1, 0}, {2, 1, 3}, {2, 2, 2}},
{{1, 0, 3}, {2, 0, 2}, {0, 1, 1}, {1, 1, 0}},
{{1, 0, 2}, {0, 1, 3}, {1, 1, 0}, {0, 2, 1}},
}, {
{{0, 0, 0}, {1, 0, 1}, {0, 1, 2}, {1, 1, 3}},
{{0, 0, 1}, {1, 0, 3}, {0, 1, 0}, {1, 1, 2}},
{{0, 0, 3}, {1, 0, 2}, {0, 1, 1}, {1, 1, 0}},
{{0, 0, 2}, {1, 0, 0}, {0, 1, 3}, {1, 1, 1}}
}
};
65 changes: 65 additions & 0 deletions src/figure/figure.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef FIGURE_HPP
#define FIGURE_HPP

#include <QObject>
#include <QColor>
#include <QVarLengthArray>

#include <random>
#include <concepts>
#include <ranges>

class Figure final {
public:
using pos_t = QVarLengthArray<QVarLengthArray<uint, 3>, 4>;
public:
Figure() = default;
Figure(uint preset, uint rotation, const QVarLengthArray<QColor, 4>& colors)
: preset_(preset), rotation_(rotation), colors_(colors) {};
public:
[[nodiscard]] Figure Rotated() const {
return { preset_, (rotation_ + 1) % 4, colors_ };
}
void Rotate() {
rotation_ = (rotation_ + 1) % 4;
}
[[nodiscard]] auto GetGeometry() const {
return presets_[preset_][rotation_];
}
[[nodiscard]] auto GetColors() const {
return colors_;
}
void SetColors(const QVarLengthArray<QColor, 4>& colors) {
colors_ = colors;
}
[[nodiscard]] uint GetLeft() const {
return std::ranges::min(
presets_[preset_][rotation_], {},
[](auto&& arg) { return std::forward<decltype(arg)>(arg)[1]; }
)[1];
}
[[nodiscard]] uint GetRight() const {
return std::ranges::max(
presets_[preset_][rotation_], {},
[](auto&& arg) { return std::forward<decltype(arg)>(arg)[1]; }
)[1];
}
[[nodiscard]] uint GetTop() const {
return std::ranges::min(
presets_[preset_][rotation_], {},
[](auto&& arg) { return std::forward<decltype(arg)>(arg)[0]; }
)[0];
}
[[nodiscard]] uint GetBottom() const {
return std::ranges::max(
presets_[preset_][rotation_], {},
[](auto&& arg) { return std::forward<decltype(arg)>(arg)[0]; }
)[0];
}
private:
static const QVarLengthArray<QVarLengthArray<pos_t, 4>, 5> presets_;
uint preset_ = 0, rotation_ = 0;
QVarLengthArray<QColor, 4> colors_;
};

#endif
49 changes: 49 additions & 0 deletions src/figure/figure_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef FIGURE_GENERATOR_HPP
#define FIGURE_GENERATOR_HPP

#include <QObject>
#include <QColor>
#include <QVarLengthArray>

#include <random>
#include <concepts>
#include <execution>

#include "figure.hpp"

template <std::uniform_random_bit_generator RandGen = std::mt19937, std::size_t c = 7>
class FigureGenerator final {
public:
explicit FigureGenerator(
RandGen&& randGen = std::mt19937{std::random_device{}()},
const QVarLengthArray<QColor, c>& colors = {
{236, 39, 51}, // Red
{246, 149, 34}, // Orange
{251, 224, 0}, // Yellow
{78, 182, 72}, // Green
{43, 171, 225}, // Light blue
{0, 90, 156}, // Dark blue
{145, 43, 139} // Purple
}
) : randGen_{std::forward<RandGen>(randGen)}, colors_(colors) {};
public:
[[nodiscard]] QVarLengthArray<QColor, 4> GenerateColors() {
return {
colors_[randGen_() % c],
colors_[randGen_() % c],
colors_[randGen_() % c],
colors_[randGen_() % c],
};
};
[[nodiscard]] Figure operator()() {
return { randGen_() % 5, randGen_() % 4, GenerateColors() };
};
private:
RandGen randGen_;
const QVarLengthArray<QColor, c> colors_;
};

template <std::uniform_random_bit_generator RandGen, std::size_t c>
FigureGenerator(RandGen&&, const QVarLengthArray<QColor, c>&) -> FigureGenerator<RandGen, c>;

#endif
Loading