Skip to content
Snippets Groups Projects
Commit 8ff30778 authored by Kovács Tamás István's avatar Kovács Tamás István
Browse files

Finished binding of the game logic with a ver 1.0 UI. Fixed bug according...

Finished binding of the game logic with a ver 1.0 UI. Fixed bug according numeric range of the integer display. Framing needs to be dont, error checking, menu and some cool animations maybe.
parent 628108fd
No related branches found
No related tags found
No related merge requests found
Showing
with 281 additions and 41 deletions
......@@ -8,18 +8,14 @@ Application::Application(){
Application::~Application() = default; // desctructor
void Application::registerWidgets(Widget * w)
{
void Application::registerWidgets(Widget *w) {
allWidgets.push_back(w);
}
void Application::action(const std::string &id) {
if(id == "lr")
{
if (id == "lr") {
}
else if(id == "rl")
{
} else if (id == "rl") {
}
}
......@@ -28,6 +24,6 @@ void Application::setFocus(int f) {
focus = f;
}
int Application::getFocus() {
int Application::getFocus() const {
return focus;
}
......@@ -5,8 +5,8 @@
#include "Widget.h"
#include <vector>
const int mainPanelX = 1000; // width of main window
const int mainPanelY = 800; // height of main window
const int mainPanelX = 1200; // width of main window
const int mainPanelY = 700; // height of main window
class Widget;
......@@ -21,7 +21,7 @@ public:
void registerWidgets(Widget*); // adds a new widget to the allWidgets vector
void action(const std::string& id);
void setFocus(int f);
int getFocus();
int getFocus() const;
};
template<typename T> // function template to handle different datatypes
......
......@@ -11,5 +11,5 @@ link_directories(lib)
target_link_libraries(graphics SDL2 SDL2.dll SDL2main SDL2_ttf SDL2_ttf.dll)
add_executable(Sudoku main.cpp CurrentApplication.cpp CurrentApplication.hpp Application.cpp Application.h Widget.cpp Widget.h Colors.h Other.h Sudoku.cpp Sudoku.hpp)
add_executable(Sudoku main.cpp Application.cpp Application.h Widget.cpp Widget.h Colors.h Other.h Sudoku.cpp Sudoku.hpp SudokuApplication.cpp SudokuApplication.hpp IntegerDisplayIncDec.cpp IntegerDisplayIncDec.h StaticTextBox.cpp StaticTextBox.h SudokuTile.cpp SudokuTile.hpp)
target_link_libraries(Sudoku graphics)
......@@ -10,6 +10,10 @@
std::vector<int> isSelectedWidgetBg = {173, 185, 136};
std::vector<int> isSelectedWidgetFrame = {208, 227, 243};
std::vector<int> fontFaceColor = {0, 0, 0};
std::vector<int> fontBackgroundColor = {185, 185, 185};
};
const ColorPalette colors;
#endif //ASSIGNMENTII_COLORS_H
......@@ -61,7 +61,18 @@ void IntegerDisplayIncDec::handle(genv::event EventLoop) {
}
} else if (EventLoop.type == genv::ev_mouse) {
if (EventLoop.button == genv::btn_left) { // gets clicked button
displayValue += getClickValue(EventLoop.pos_x, EventLoop.pos_y);
int clickedValue = getClickValue(EventLoop.pos_x, EventLoop.pos_y);
if(clickedValue == -1){
if(displayValue + clickedValue >= minValue){
displayValue += clickedValue; // subtracts one from current value
}
}
else{
if(displayValue + clickedValue <= maxValue){
displayValue += clickedValue; // adds one from to value
}
}
}
}
......
......@@ -204,9 +204,9 @@ void Sudoku::createLevel() {
std::shuffle(guessNum, (guessNum) + 9, std::mt19937(std::random_device()()));
/// Initialising the grid
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
grid[i][j] = 0;
for (auto & i : grid) {
for (int & j : i) {
j = 0;
}
}
createSeed();
......@@ -215,4 +215,12 @@ void Sudoku::createLevel() {
}
int Sudoku::getPuzzleAtPosition(int x, int y) {
return grid[x][y];
}
int Sudoku::getSolutionAtPosition(int x, int y) {
return solnGrid[x][y];
}
Sudoku::~Sudoku() = default;
......@@ -23,6 +23,8 @@ public:
void countSoln(int &number);
void genPuzzle();
void createLevel();
int getPuzzleAtPosition(int x, int y);
int getSolutionAtPosition(int x, int y);
};
......
//
// Created by ktama on 2021. 05. 13..
//
#include "SudokuApplication.hpp"
#include "Colors.h"
#include "Sudoku.hpp"
SudokuApplication::SudokuApplication() {
puzzle = new Sudoku;
puzzle->createLevel();
std::vector<SudokuTile*>tmp;
for(int i = 0; i < 9; i++){
tmp.clear();
for(int j = 0; j < 9; j++){
tmp.push_back(new SudokuTile(i*80+10, j*70+10, 50, 50, "", this, puzzle->getPuzzleAtPosition(i, j), 0, 9, puzzle->getPuzzleAtPosition(i, j), puzzle->getSolutionAtPosition(i, j)));
}
displayGrid.push_back(tmp);
}
}
void SudokuApplication::EventLoop() // main event loop
{
genv::gout.open(mainPanelX, mainPanelY);
genv::gout.load_font(R"(../jingle-bells.regular.ttf)", 30, false);
genv::event EventHandler;
while (genv::gin >> EventHandler) {
genv::gout << genv::move_to(0, 0)
<< genv::color(colors.background[0], colors.background[1], colors.background[2])
<< genv::box(mainPanelX, mainPanelY);
if (EventHandler.type == genv::ev_mouse) {
if (EventHandler.button == genv::btn_left) {
for (size_t i = 0; i < allWidgets.size(); i++) {
if (allWidgets[i]->isSelected(EventHandler.pos_x, EventHandler.pos_y)) {
focus = i;
}
}
}
} else if (EventHandler.type == genv::ev_key) {
if (EventHandler.keycode == genv::key_enter) {
if (focus != -1) {
if (allWidgets[focus]->getRetrievableDataType() == "int") {
int numData = *(static_cast<int *>(allWidgets[focus]->dataGetter()));
writeResultsToFile(numData);
} else if (allWidgets[focus]->getRetrievableDataType() == "string") {
std::string stringData = *(static_cast<std::string *>(allWidgets[focus]->dataGetter()));
writeResultsToFile(stringData);
}
}
} else if (EventHandler.keycode == genv::key_right) {
if (getFocus() != -1) {
}
} else if (EventHandler.keycode == genv::key_right) {
if (getFocus() != -1) {
}
}
}
if (focus != -1) {
allWidgets[focus]->handle(EventHandler); // the selected widget will handle the event loop
}
for (Widget *w : allWidgets) {
w->drawSelf();
}
if (EventHandler.type == genv::ev_key &&
EventHandler.keycode == genv::key_escape) // on Esc, terminate execution
{
exit(0);
}
genv::gout << genv::refresh;
}
}
SudokuApplication::~SudokuApplication() = default;
\ No newline at end of file
//
// Created by ktama on 2021. 05. 13..
//
#ifndef SUDOKU_SUDOKUAPPLICATION_HPP
#define SUDOKU_SUDOKUAPPLICATION_HPP
#include "Application.h"
#include "SudokuTile.hpp"
#include "Sudoku.hpp"
class SudokuApplication: public Application {
protected:
std::vector<std::vector<SudokuTile*>> displayGrid;
Sudoku* puzzle;
public:
SudokuApplication();
~SudokuApplication();
void EventLoop() override;
};
#endif //SUDOKU_SUDOKUAPPLICATION_HPP
//
// Created by ktama on 2021. 05. 13..
//
#include "SudokuTile.hpp"
#include "Colors.h"
#include <cmath>
SudokuTile::SudokuTile(int pX, int pY, int sX, int sY, const std::string &txt, Application *parent, int val,
int minV, int maxV, int currentVal, int solutionVal) : IntegerDisplayIncDec(pX, pY, sX, sY, txt, parent, val, minV, maxV) {
currentValue = currentVal;
solutionValue = solutionVal;
}
void SudokuTile::drawSelf() {
StaticTextBox::Widget::drawBorderedRectangularWidget(); // draw display box
displayContentAsString(std::to_string(displayValue)); // put number
drawBorderedRectangularWidget(posXUp, posYUp, 20, sizeYUp, 5); // up box
drawBorderedRectangularWidget(posXDown, posYDown, 20, sizeYDown, 5); // down box
drawArrow('u');
drawArrow('d');
}
void SudokuTile::drawArrow(char direction) {
if(direction == 'u'){
genv::gout << genv::move_to(posXUp+9, posYUp+3) << genv::color(colors.fontFaceColor[0], colors.fontFaceColor[1], colors.fontFaceColor[2])
<< genv::line_to(posXUp+9, posYUp+sizeYUp-5) << genv::move_to(posXUp+9, posYUp+3) << genv::line(-5, 5) << genv::move_to(posXUp+9, posYUp+3) <<
genv::line(+5, 5);
}
else{
genv::gout << genv::move_to(posXDown+9, posYDown+3) << genv::color(colors.fontFaceColor[0], colors.fontFaceColor[1], colors.fontFaceColor[2])
<< genv::line_to(posXDown+9, posYDown+sizeYDown-5) << genv::line(-5, -5) << genv::move_to(posXDown+9, posYDown+sizeYDown-5) <<
genv::line(5, -5);
}
}
void SudokuTile::displayContentAsString(const std::string &outputData) const {
int xPos = (int)round(((2 * posX + sizeX) / 2)- (genv::gout.twidth(outputData) / 2)); // aligned to the middle, taken into account the length of the string
int yPos = (int)round((2 * posY + sizeY) / 2) - (genv::gout.cascent() - genv::gout.cdescent()); // same in y direction
if(outputData == "0"){
genv::gout << genv::move_to(xPos+3, yPos+3) << genv::color(colors.fontBackgroundColor[0], colors.fontBackgroundColor[1], colors.fontBackgroundColor[2]) << genv::text(""); // text
genv::gout << genv::move_to(xPos, yPos) << genv::color(colors.fontFaceColor[0], colors.fontFaceColor[1], colors.fontFaceColor[2]) << genv::text(""); // shadow
}else{
genv::gout << genv::move_to(xPos+3, yPos+3) << genv::color(colors.fontBackgroundColor[0], colors.fontBackgroundColor[1], colors.fontBackgroundColor[2]) << genv::text(outputData); // text
genv::gout << genv::move_to(xPos, yPos) << genv::color(colors.fontFaceColor[0], colors.fontFaceColor[1], colors.fontFaceColor[2]) << genv::text(outputData); // shadow
}
}
SudokuTile::~SudokuTile() = default;
//
// Created by ktama on 2021. 05. 13..
//
#ifndef SUDOKU_SUDOKUTILE_HPP
#define SUDOKU_SUDOKUTILE_HPP
#include "IntegerDisplayIncDec.h"
class SudokuTile: public IntegerDisplayIncDec {
protected:
int currentValue;
int solutionValue;
public:
SudokuTile(int pX, int pY, int sX, int sY, const std::string &txt, Application *parent, int val, int minV, int maxV, int currentVal, int solutionVal);
~SudokuTile();
void drawSelf() override;
void drawArrow(char direction);
void displayContentAsString(const std::string& outputData) const ;
};
#endif //SUDOKU_SUDOKUTILE_HPP
......@@ -34,8 +34,8 @@ void Widget::displayContentAsString(const std::string& outputData) const
{
int xPos = (int)round(((2 * posX + sizeX) / 2)- (genv::gout.twidth(outputData) / 2)); // aligned to the middle, taken into account the length of the string
int yPos = (int)round((2 * posY + sizeY) / 2) - (genv::gout.cascent() - genv::gout.cdescent()); // same in y direction
genv::gout << genv::move_to(xPos+3, yPos+3) << genv::color(180, 180, 180) << genv::text(outputData); // text
genv::gout << genv::move_to(xPos, yPos) << genv::color(255, 255, 255) << genv::text(outputData); // shadow
genv::gout << genv::move_to(xPos+3, yPos+3) << genv::color(colors.fontBackgroundColor[0], colors.fontBackgroundColor[1], colors.fontBackgroundColor[2]) << genv::text(outputData); // text
genv::gout << genv::move_to(xPos, yPos) << genv::color(colors.fontFaceColor[0], colors.fontFaceColor[1], colors.fontFaceColor[2]) << genv::text(outputData); // shadow
}
......
......@@ -94,12 +94,12 @@ clean: CMakeFiles/graphics.dir/clean
CMakeFiles/Sudoku.dir/all: CMakeFiles/graphics.dir/all
$(MAKE) $(MAKESILENT) -f CMakeFiles\Sudoku.dir\build.make CMakeFiles/Sudoku.dir/depend
$(MAKE) $(MAKESILENT) -f CMakeFiles\Sudoku.dir\build.make CMakeFiles/Sudoku.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir="C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" --progress-num=1,2,3,4,5,6 "Built target Sudoku"
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir="C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" --progress-num=1,2,3,4,5,6,7,8,9 "Built target Sudoku"
.PHONY : CMakeFiles/Sudoku.dir/all
# Build rule for subdir invocation for target.
CMakeFiles/Sudoku.dir/rule: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start "C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" 8
$(CMAKE_COMMAND) -E cmake_progress_start "C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" 11
$(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 CMakeFiles/Sudoku.dir/all
$(CMAKE_COMMAND) -E cmake_progress_start "C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" 0
.PHONY : CMakeFiles/Sudoku.dir/rule
......@@ -121,7 +121,7 @@ CMakeFiles/Sudoku.dir/clean:
CMakeFiles/graphics.dir/all:
$(MAKE) $(MAKESILENT) -f CMakeFiles\graphics.dir\build.make CMakeFiles/graphics.dir/depend
$(MAKE) $(MAKESILENT) -f CMakeFiles\graphics.dir\build.make CMakeFiles/graphics.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir="C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" --progress-num=7,8 "Built target graphics"
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir="C:\Users\ktama\OneDrive\Documents\MSc\3rd Semester\Prog\Bead3\cmake-build-debug\CMakeFiles" --progress-num=10,11 "Built target graphics"
.PHONY : CMakeFiles/graphics.dir/all
# Build rule for subdir invocation for target.
......
No preview for this file type
......@@ -6,29 +6,61 @@
#IncludeRegexTransform:
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Sudoku.cpp
iostream
-
algorithm
-
ctime
-
cstdlib
-
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.h
fstream
-
random
-
sstream
-
string
-
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/fstream
Widget.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Widget.h
vector
-
random
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Colors.h
vector
-
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/IntegerDisplayIncDec.h
Widget.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Widget.h
Application.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.h
StaticTextBox.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/StaticTextBox.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/StaticTextBox.h
Widget.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Widget.h
Application.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Sudoku.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuApplication.cpp
SudokuApplication.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuApplication.hpp
Colors.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Colors.h
Sudoku.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Sudoku.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuApplication.hpp
Application.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.h
SudokuTile.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuTile.hpp
Sudoku.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Sudoku.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuTile.hpp
IntegerDisplayIncDec.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/IntegerDisplayIncDec.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Widget.h
Application.h
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.h
graphics.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/graphics.hpp
C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/graphics.hpp
string
-
No preview for this file type
......@@ -5,8 +5,11 @@ set(CMAKE_DEPENDS_LANGUAGES
# The set of files for implicit dependencies of each language:
set(CMAKE_DEPENDS_CHECK_CXX
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Application.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/Application.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/CurrentApplication.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/CurrentApplication.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/IntegerDisplayIncDec.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/IntegerDisplayIncDec.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/StaticTextBox.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/StaticTextBox.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Sudoku.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/Sudoku.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuApplication.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/SudokuApplication.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/SudokuTile.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/SudokuTile.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/Widget.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/Widget.cpp.obj"
"C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/main.cpp" "C:/Users/ktama/OneDrive/Documents/MSc/3rd Semester/Prog/Bead3/cmake-build-debug/CMakeFiles/Sudoku.dir/main.cpp.obj"
)
......
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment