Added project
This commit is contained in:
commit
6a3e1dc361
623
display.cpp
Normal file
623
display.cpp
Normal file
@ -0,0 +1,623 @@
|
||||
#include "display.h"
|
||||
|
||||
void setConsoleColor(int textColor, int bgColor)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hConsole, (bgColor << 4) | textColor);
|
||||
}
|
||||
void setCursorPosition(int x, int y) {
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
|
||||
SetConsoleCursorPosition(hConsole, position);
|
||||
}
|
||||
void hideCursor() {
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_CURSOR_INFO cursorInfo;
|
||||
GetConsoleCursorInfo(hConsole, &cursorInfo);
|
||||
cursorInfo.bVisible = FALSE;
|
||||
SetConsoleCursorInfo(hConsole, &cursorInfo);
|
||||
}
|
||||
void enableANSI() {
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwMode = 0;
|
||||
GetConsoleMode(hOut, &dwMode);
|
||||
SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
||||
}
|
||||
|
||||
void setConsoleColorRGB(int r, int g, int b, int type)
|
||||
{
|
||||
if (type == 0) {
|
||||
// Text color
|
||||
std::cout << "\033[38;2;" << r << ";" << g << ";" << b << "m";
|
||||
}
|
||||
else if (type == 1) {
|
||||
// Background color
|
||||
std::cout << "\033[48;2;" << r << ";" << g << ";" << b << "m";
|
||||
}
|
||||
}
|
||||
|
||||
void resetTextColor() {
|
||||
std::cout << "\033[0m";
|
||||
}
|
||||
|
||||
void refreshingScreen()
|
||||
{
|
||||
setCursorPosition(0, 0);
|
||||
int FPS = 60;
|
||||
Sleep(1000.f / FPS);
|
||||
}
|
||||
|
||||
void switching_xy_sudoku(XY_coord & xy_object, sudokuElement sudoku_array[9][9], int & score, bool & is_pause, bool & give_up)
|
||||
{
|
||||
if (_kbhit()) {
|
||||
char pressed_key = _getch();
|
||||
if (is_pause == false)
|
||||
{
|
||||
if (pressed_key == 'P' || pressed_key == 's') xy_object.x++; //arrow_down
|
||||
if (pressed_key == 'H' || pressed_key == 'w') xy_object.x--; //arow_up
|
||||
if (pressed_key == 'K' || pressed_key == 'a') xy_object.y--; //arrow_left
|
||||
if (pressed_key == 'M' || pressed_key == 'd') xy_object.y++; //arrow_right
|
||||
if (pressed_key >= '0' && pressed_key <= '9' &&
|
||||
sudoku_array[xy_object.x][xy_object.y].type == 0)
|
||||
{
|
||||
sudoku_array[xy_object.x][xy_object.y].value = pressed_key - '0';
|
||||
}
|
||||
if (pressed_key == 8) //backspace
|
||||
{
|
||||
sudoku_array[xy_object.x][xy_object.y].value = 0;
|
||||
}
|
||||
if (pressed_key == 'q')
|
||||
{
|
||||
give_up = true;
|
||||
is_pause = true;
|
||||
}
|
||||
if (xy_object.x == -1) xy_object.x = 8;
|
||||
if (xy_object.x == 9) xy_object.x = 0;
|
||||
|
||||
if (xy_object.y == -1) xy_object.y = 8;
|
||||
if (xy_object.y == 9) xy_object.y = 0;
|
||||
}
|
||||
if (pressed_key == 'p') is_pause = true;
|
||||
else if (pressed_key == 'r') is_pause = false;
|
||||
|
||||
|
||||
//cout << "You pressed: " << pressed_key << " (ASCII: " << int(pressed_key) << ")" << endl;
|
||||
}
|
||||
}
|
||||
void display(sudokuElement sudoku_array[9][9], sudokuElement sudoku_array_solved[9][9], int level_difficulty, int & score, int& score_multiplier, int& errors,
|
||||
XY_coord xy_object, bool options_elements_bool[], int options_size, chrono::microseconds duration,
|
||||
bool if_give_up_game, int& active_element_give_up, bool& if_give_up_enter ,bool if_winning, int & active_element_winning,
|
||||
bool & if_winning_enter, bool score_array[9][9], bool error_array[9][9], int previous_value_array[9][9], bool is_pause,
|
||||
bool & if_error_enter, int& active_element_error)
|
||||
{
|
||||
cout << endl;
|
||||
cout << " || LEVEL DIFFICULTY: ";
|
||||
setConsoleColor(10, 0);
|
||||
switch (level_difficulty)
|
||||
{
|
||||
case 0: cout << "EASY"; break;
|
||||
case 1: cout << "MEDIUM"; break;
|
||||
case 2: cout << "HARD"; break;
|
||||
case 3: cout << "IMPOSSIBLE"; break;
|
||||
}
|
||||
setConsoleColor(7, 0);
|
||||
cout << " ||" << endl;
|
||||
cout << endl;
|
||||
|
||||
setConsoleColor(8, 0);
|
||||
int array_i = 0, array_j = 0;
|
||||
|
||||
for (int i = 0; i < 19; i++) // 37 char height
|
||||
{
|
||||
cout << " ";
|
||||
for (int j = 0; j < 37; j++) // 37 char width
|
||||
{
|
||||
if (i % 6 == 0)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
if (j % 12 == 0 && j != 0 && j != 36)
|
||||
{
|
||||
cout << "╦";
|
||||
}
|
||||
else {
|
||||
switch (j)
|
||||
{
|
||||
case 0:
|
||||
cout << "╔";
|
||||
break;
|
||||
case 36:
|
||||
cout << "╗";
|
||||
break;
|
||||
default:
|
||||
cout << "═";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (i == 18)
|
||||
{
|
||||
if (j % 12 == 0 && j != 0 && j != 36)
|
||||
{
|
||||
cout << "╩";
|
||||
}
|
||||
else {
|
||||
switch (j)
|
||||
{
|
||||
case 0:
|
||||
cout << "╚";
|
||||
break;
|
||||
case 36:
|
||||
cout << "╝";
|
||||
break;
|
||||
default:
|
||||
cout << "═";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
cout << "╠";
|
||||
}
|
||||
else if (j == 36)
|
||||
{
|
||||
cout << "╣";
|
||||
}
|
||||
else if(j % 12 == 0)
|
||||
{
|
||||
cout << "╬";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "═";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j % 12 == 0)
|
||||
{
|
||||
cout << "║";
|
||||
}
|
||||
else if (j % 4 == 0 && i % 2 == 1)
|
||||
{
|
||||
cout << "|";
|
||||
}
|
||||
else if(i % 2 == 0)
|
||||
{
|
||||
if (j % 4 == 0)
|
||||
{
|
||||
cout << "+";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "-";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i % 2 == 1 && j % 4 == 2)
|
||||
{
|
||||
setConsoleColor(15, 0); //white
|
||||
if (sudoku_array[array_i][array_j].value != 0)
|
||||
{
|
||||
switch (sudoku_array[array_i][array_j].type)
|
||||
{
|
||||
case 1:
|
||||
setConsoleColor(15, 0); break;
|
||||
|
||||
case 0:
|
||||
|
||||
|
||||
bool isCorrectNumber;
|
||||
isCorrectNumber = isCorrect(sudoku_array_solved, array_i, array_j, sudoku_array[array_i][array_j].value);
|
||||
|
||||
switch (isCorrectNumber)
|
||||
{
|
||||
case true:
|
||||
if (options_elements_bool[2] == true) setConsoleColor(2, 0);
|
||||
|
||||
if (score_array[array_i][array_j] == false)
|
||||
{
|
||||
score_array[array_i][array_j] = true;
|
||||
|
||||
score += 10;
|
||||
if (score_multiplier > 0 && score_multiplier <= 3)
|
||||
{
|
||||
score = score + score_multiplier * 5 + level_difficulty * 10;
|
||||
|
||||
if (options_elements_bool[2] == false)
|
||||
{
|
||||
score = score + 20;
|
||||
}
|
||||
|
||||
if (options_elements_bool[3] == true)
|
||||
{
|
||||
score = score + 20;
|
||||
}
|
||||
}
|
||||
else if (score_multiplier > 3 && score_multiplier <= 7)
|
||||
{
|
||||
score = score + score_multiplier * 7 + level_difficulty * 15;
|
||||
|
||||
if (options_elements_bool[2] == false)
|
||||
{
|
||||
score = score + 30;
|
||||
}
|
||||
|
||||
if (options_elements_bool[3] == true)
|
||||
{
|
||||
score = score + 30;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
score = score + score_multiplier * 9 + level_difficulty * 20;
|
||||
|
||||
if (options_elements_bool[2] == false)
|
||||
{
|
||||
score = score + 30;
|
||||
}
|
||||
|
||||
if (options_elements_bool[3] == true)
|
||||
{
|
||||
score = score + 30;
|
||||
}
|
||||
}
|
||||
|
||||
score_multiplier++;
|
||||
}
|
||||
|
||||
if (error_array[array_i][array_j] == true)
|
||||
{
|
||||
error_array[array_i][array_j] = false;
|
||||
}
|
||||
|
||||
previous_value_array[array_i][array_j] = sudoku_array[array_i][array_j].value;
|
||||
|
||||
break;
|
||||
|
||||
case false:
|
||||
if (options_elements_bool[2] == true) setConsoleColor(4, 0);
|
||||
score_multiplier = 0;
|
||||
|
||||
if (sudoku_array[array_i][array_j].value != previous_value_array[array_i][array_j])
|
||||
{
|
||||
|
||||
error_array[array_i][array_j] = true;
|
||||
errors++;
|
||||
|
||||
if (options_elements_bool[3] == false)
|
||||
{
|
||||
score = score - 100;
|
||||
}
|
||||
|
||||
|
||||
previous_value_array[array_i][array_j] = sudoku_array[array_i][array_j].value;
|
||||
}
|
||||
|
||||
|
||||
if (sudoku_array[array_i][array_j].value == 0)
|
||||
{
|
||||
error_array[array_i][array_j] = false;
|
||||
previous_value_array[array_i][array_j] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (options_elements_bool[2] == false)
|
||||
{
|
||||
setConsoleColor(2, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
//setConsoleColor(sudoku_array[array_i][array_j], 0);
|
||||
if (xy_object.x == array_i && xy_object.y == array_j)
|
||||
{
|
||||
setConsoleColor(0, 10);
|
||||
cout << sudoku_array[array_i][array_j].value;
|
||||
//setConsoleColor(sudoku_array[array_i][array_j], 0);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bold = false;
|
||||
if (sudoku_array[array_i][array_j].value == sudoku_array[xy_object.x][xy_object.y].value)
|
||||
{
|
||||
if (options_elements_bool[1])
|
||||
{
|
||||
setConsoleColor(sudoku_array[array_i][array_j].value, 0);
|
||||
if (sudoku_array[array_i][array_j].value == 2) setConsoleColor(5, 0);
|
||||
if (sudoku_array[array_i][array_j].value == 5) setConsoleColor(13, 0);
|
||||
if (sudoku_array[array_i][array_j].value == 7) setConsoleColorRGB(240, 100, 0, 0); //orange
|
||||
if (sudoku_array[array_i][array_j].value == 8) setConsoleColor(12, 0);
|
||||
|
||||
bold = true;
|
||||
}
|
||||
}
|
||||
if (options_elements_bool[0] == true)
|
||||
if (j == (2 + 4 * xy_object.y)) setConsoleColorRGB(0, 43, 0, 1); //gray background
|
||||
if (i / 2 == xy_object.x)
|
||||
{
|
||||
if (options_elements_bool[0] == true) setConsoleColorRGB(0, 43, 0, 1); //gray background
|
||||
}
|
||||
if (bold == true)
|
||||
{
|
||||
cout << "\033[1;4m"<<sudoku_array[array_i][array_j].value << "\033[0m";
|
||||
bold = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << sudoku_array[array_i][array_j].value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xy_object.x == array_i && xy_object.y == array_j)
|
||||
{
|
||||
setConsoleColor(0, 10);
|
||||
}
|
||||
|
||||
else if (j == (2 + 4 * xy_object.y))
|
||||
{
|
||||
if (options_elements_bool[0] == true)
|
||||
setConsoleColorRGB(0, 43, 0, 1);
|
||||
}
|
||||
else if (i / 2 == xy_object.x)
|
||||
{
|
||||
if (options_elements_bool[0] == true)
|
||||
setConsoleColorRGB(0, 43, 0, 1);
|
||||
}
|
||||
cout << " ";
|
||||
}
|
||||
array_j++;
|
||||
if (array_j == 9)
|
||||
{
|
||||
array_i++;
|
||||
array_j = 0;
|
||||
}
|
||||
setConsoleColor(8, 0); //grey
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j == (3 + 4 * xy_object.y) || j == (1 + 4 * xy_object.y))
|
||||
{
|
||||
if(options_elements_bool[0] == true)
|
||||
setConsoleColorRGB(0, 43, 0, 1); //grey background
|
||||
}
|
||||
if (i / 2 == xy_object.x)
|
||||
{
|
||||
if (options_elements_bool[0] == true)
|
||||
setConsoleColorRGB(0, 43, 0, 1); //grey background
|
||||
}
|
||||
if (j == (1 + 4 * xy_object.y) && i / 2 == xy_object.x) //active_element
|
||||
{
|
||||
setConsoleColor(0, 10);
|
||||
}
|
||||
if (j == (3 + 4 * xy_object.y) && i / 2 == xy_object.x)
|
||||
{
|
||||
setConsoleColor(0, 10);
|
||||
}
|
||||
|
||||
cout << " ";
|
||||
setConsoleColor(8, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//cout << "║";
|
||||
if (i == 7 && options_elements_bool[3] == true)
|
||||
{
|
||||
setConsoleColor(15, 0);
|
||||
cout << " ERRORS: ";
|
||||
setConsoleColor(10, 0);
|
||||
cout << errors << "/3";
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
if (i == 9)
|
||||
{
|
||||
setConsoleColor(15, 0);
|
||||
cout << " SCORE: ";
|
||||
setConsoleColor(10, 0);
|
||||
cout << score;
|
||||
cout << " ";
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
if (i == 11)
|
||||
{
|
||||
setConsoleColor(15, 0);
|
||||
|
||||
int counter = 0;
|
||||
int counter_start_numers = 0;
|
||||
for (int i = 0; i < 9; i++) //calculating how many elments of the array are greater than 0 for the function
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
if (sudoku_array[i][j].value != 0 && sudoku_array[i][j].type == 0) counter++;
|
||||
if (sudoku_array[i][j].type == 1) counter_start_numers++;
|
||||
}
|
||||
}
|
||||
float a;
|
||||
a = (counter * 100) / (81 - counter_start_numers);
|
||||
cout << " PROGRESS: ";
|
||||
setConsoleColor(10, 0);
|
||||
cout << "[";
|
||||
|
||||
cout << a;
|
||||
cout << " %";
|
||||
|
||||
cout<<"]";
|
||||
setConsoleColor(15, 0);
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
if (i == 13)
|
||||
{
|
||||
setConsoleColor(15, 0);
|
||||
cout << " TIME: ";
|
||||
int hours = chrono::duration_cast<chrono::hours>(duration).count();
|
||||
int minutes = std::chrono::duration_cast<std::chrono::minutes>(duration).count() % 60;
|
||||
int seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count() % 60;
|
||||
int milliseconds = duration.count() % 1000;
|
||||
setConsoleColor(10, 0);
|
||||
// Format and print the time
|
||||
cout<< std::setfill('0') << std::setw(2) << hours << ":"
|
||||
<< std::setfill('0') << std::setw(2) << minutes << ":"
|
||||
<< std::setfill('0') << std::setw(2) << seconds << ":"
|
||||
<< std::setfill('0') << std::setw(3) << milliseconds;
|
||||
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
if (i == 15)
|
||||
{
|
||||
setConsoleColor(8, 0);
|
||||
if (if_give_up_game == false)
|
||||
{
|
||||
switch (is_pause)
|
||||
{
|
||||
case false:
|
||||
cout << " Press 'p' to pause the game "; break;
|
||||
case true:
|
||||
if (if_give_up_game == false) cout << " Press 'r' for resuming the game ";
|
||||
else cout << " Press 'p' to pause the game ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
if (i == 17)
|
||||
{
|
||||
setConsoleColor(8, 0);
|
||||
switch (is_pause)
|
||||
{
|
||||
case false:
|
||||
cout << " Press 'q' to quit the game "; break;
|
||||
case true:
|
||||
cout << " "; break;
|
||||
}
|
||||
|
||||
setConsoleColor(8, 0);
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
if (errors == 3 && options_elements_bool[3] == true)
|
||||
{
|
||||
string array_strings[2] = { "YES", "NO" };
|
||||
setConsoleColor(15, 0);
|
||||
cout << " Do you wanna get a second chance (-1000 points)?" << endl << endl;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (active_element_winning == i)
|
||||
{
|
||||
setConsoleColor(10, 0);
|
||||
cout << " >> " << array_strings[i] << " <<";
|
||||
setConsoleColor(15, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << " " << array_strings[i] << " ";
|
||||
}
|
||||
cout << endl << endl;
|
||||
}
|
||||
if_error_enter = switching_elements(active_element_winning, 1);
|
||||
}
|
||||
if (if_winning == true)
|
||||
{
|
||||
string array_strings[2] = { "YES", "NO" };
|
||||
setConsoleColor(15, 0);
|
||||
cout << " Do you wanna play again?" << endl << endl;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (active_element_winning == i)
|
||||
{
|
||||
setConsoleColor(10, 0);
|
||||
cout << " >> " << array_strings[i] << " <<";
|
||||
setConsoleColor(15, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << " " << array_strings[i] << " ";
|
||||
}
|
||||
cout << endl << endl;
|
||||
}
|
||||
if_winning_enter = switching_elements(active_element_winning, 1);
|
||||
|
||||
}
|
||||
if (if_give_up_game == true)
|
||||
{
|
||||
string array_strings[2] = { "YES", "NO" };
|
||||
setConsoleColor(15, 0);
|
||||
cout << " Do you wanna give up the game? ?" << endl << endl;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (active_element_give_up == i)
|
||||
{
|
||||
setConsoleColor(10, 0);
|
||||
cout << " >> " << array_strings[i] << " <<";
|
||||
setConsoleColor(15, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << " " << array_strings[i] << " ";
|
||||
}
|
||||
cout << endl << endl;
|
||||
}
|
||||
if_give_up_enter = switching_elements(active_element_give_up, 1);
|
||||
|
||||
}
|
||||
/*if (if_winning == false && if_give_up_game == false)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
cout << endl;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
setConsoleColor(15, 0);
|
||||
|
||||
}
|
||||
|
||||
bool ifWinning(sudokuElement sudoku_array[9][9], sudokuElement sudoku_array_solved[9][9])
|
||||
{
|
||||
int index_i = 0, index_j = 0;
|
||||
while (index_i < 9)
|
||||
{
|
||||
if (sudoku_array[index_i][index_j].value == sudoku_array_solved[index_i][index_j].value)
|
||||
{
|
||||
index_j++;
|
||||
if (index_j == 9)
|
||||
{
|
||||
index_j = 0;
|
||||
index_i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
56
display.h
Normal file
56
display.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class XY_coord
|
||||
{
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
XY_coord(int x_c, int y_c)
|
||||
{
|
||||
x = x_c; y = y_c;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class sudokuElement
|
||||
{
|
||||
public:
|
||||
int value = 0;
|
||||
int type = 0;
|
||||
sudokuElement(int value_c, int type_c)
|
||||
{
|
||||
value = value_c;
|
||||
type = type_c;
|
||||
}
|
||||
sudokuElement() {}
|
||||
|
||||
};
|
||||
bool switching_elements(int& active_element, int max_element); //here to be visible for display()
|
||||
void setConsoleColor(int textColor, int bgColor);
|
||||
void switching_xy_sudoku(XY_coord & xy_object, sudokuElement sudoku_array[9][9], int& score, bool& is_pause, bool& give_up);
|
||||
void setCursorPosition(int x, int y);
|
||||
void refreshingScreen();
|
||||
void hideCursor();
|
||||
void enableANSI();
|
||||
void setConsoleColorRGB(int r, int g, int b, int type);
|
||||
void resetTextColor();
|
||||
void display(sudokuElement sudoku_array[9][9], sudokuElement sudoku_array_solved[9][9],
|
||||
int level_difficulty, int & score, int & score_multiplier,int& errors, XY_coord xy_object, bool options_elements_bool[], int options_size,
|
||||
chrono::microseconds duration, bool if_give_up_game, int& active_element_give_up, bool& if_give_up_enter, bool if_winning,
|
||||
int & active_element_winning, bool& if_winning_enter, bool score_array[9][9], bool error_array[9][9], int previous_value_array[9][9],
|
||||
bool is_pause, bool & if_error_enter, int& active_element_error);
|
||||
|
||||
//should be in another header, but then doesn't work
|
||||
bool isCorrect(sudokuElement sudoku_array_solved[9][9], int x, int y, int number);
|
||||
bool ifWinning(sudokuElement sudoku_array[9][9], sudokuElement sudoku_array_solved[9][9]);
|
1
levels/easy.txt
Normal file
1
levels/easy.txt
Normal file
@ -0,0 +1 @@
|
||||
013270900090038050872940610906004000300809061058000020081090040460051030000002006
|
50
levels/hard.txt
Normal file
50
levels/hard.txt
Normal file
@ -0,0 +1,50 @@
|
||||
970060150000500690000008007150620009000000000002000800027000000380000006506090203
|
||||
060070100700000008014800005400100000937040001085009000600003850053007000800004300
|
||||
107000038000000102003000070000809000900200750501000000705000090029000400040700010
|
||||
070000000000000004020160000060024130010507086000010400002050000000400078006800000
|
||||
001007006800030400000008010040900080000400300907300050700090640000001597000000000
|
||||
700000801003000006000000400050076900906000087870905000040530000080007000600409008
|
||||
050400087000000600004030000080000000070000003000000046310040060060057001705120000
|
||||
000024000000390000050700408000910004320000091000802075030000000097200000008040007
|
||||
790008000001900047004000600053000000000000000079000030010700509600050300000013806
|
||||
003000008020980007040300529200000000037008004056000000000000075079000080002004090
|
||||
006005000000000008005706400040003100000074006700000002070010000100050030204680000
|
||||
006000000039042080000000002000890060000100000890700001920310800041006000300000000
|
||||
000500684600000500000003000080006000040070000060102700007000000450000103000015270
|
||||
800000073000001000000000980007500000210000000980020100009000340000039007040800005
|
||||
500000410000050000400600900900200080000906300001004000100000040003002090200309850
|
||||
009000342000080060700030950070004000094370000003020006000000084820700000040002000
|
||||
000090108100000000390408000540030000800100000907050036000309000000070400700605081
|
||||
000005400000040060000603000007060000854090600091704000510980003300400809008000500
|
||||
078001059009030007001050000200000081000070000000904703000007810000000092000320000
|
||||
090002080006000000100036050050200031009000200600000000500010078367000500000000000
|
||||
900600084005004070080027195000000600010000000807050029000090001000000000024000000
|
||||
000940080000037506000501070080000013000009700045000600030400800590100000000000030
|
||||
024693000800007000760402000200000003048706000300804007000000000400008020601040300
|
||||
207300010004709205000000000400600000000001030900425000030000000700050006160000702
|
||||
751403082003000950800000000000932000009500040075010000080300010030008000504000700
|
||||
030970000000200900000063000740009300060700000100040000052000600403006700670430002
|
||||
020010500000098007085300000000000002040700009010000450000049030000080001000030295
|
||||
000345870000070000300000009720009100800700050000020040050030000000008200000201390
|
||||
006009000000000200013006090001000003800090060052034900009000450040000012000001680
|
||||
008039050004008900000020000340005096500600802000000000060070203050000040200000000
|
||||
000010640006000000800000000500043070010065000069800000000400107090050000007008304
|
||||
000500030000300800090004005029006001506000000000020040000900420400080000005100083
|
||||
700589200020340070040700503003406089069820700070090000000000300090000008000000050
|
||||
080049000503086009600000040300000007020007000090002000000038000400000083700204500
|
||||
008600020000078350000409008000000002920060000045007030003000805000500060004000079
|
||||
640000090500030001809061504400785069000900000000000400900106000060000000100590000
|
||||
100000060040000301068000050009000005400000080035010692000040009500026000090503400
|
||||
000001009006030000040092100000004007070103025000020360000040000010700650000005090
|
||||
872310000000009000010208000063000000008400710040007000030100290004000007600003000
|
||||
200000850070000001100000070020000790080000503500091600960080030057020180800000000
|
||||
000000000800000000600035000301080560500000902060000300000807001190002600200360070
|
||||
060002080090000104048700000000800952050000060000100000601900000005070000000280009
|
||||
853000000709000500020800000400006092068000000300000040006003070000050604000702050
|
||||
023600051000095706000010000000030000032000068106008200017000080000001600005900000
|
||||
070008043050021900400009508900004000800090015004003000000040009005000800000030000
|
||||
300002980000350007090000040000020000704000006000080000000500000860000300042730500
|
||||
030081000000900800072050900000000402310000000000003005000079004008400059500010000
|
||||
000070060000000000010000342000000086800010000106300004408250000073008010620003000
|
||||
000058000000400500074260001640000000000030017000520600000070002100000040000006780
|
||||
060309080000060020370000540000008000000000600004023800000907035008500400090000000
|
50
levels/impossible.txt
Normal file
50
levels/impossible.txt
Normal file
@ -0,0 +1,50 @@
|
||||
005001000910000000063500000020000003000006001000705628602009750008000000570300010
|
||||
700210503506000200000004007000305040000000000000460700014039000270000390000700000
|
||||
080000090650028040000000006015000700008001000020000000000670009400950610000010004
|
||||
300700000090080100005906403008145009000600040000008600000000001070000930003000850
|
||||
050002000060000307000070000530709000080000002000380500300601070070090081120000000
|
||||
090200000300000790000005003000050001037040980050000070080000027509000100004302500
|
||||
700000010090000000250000000000009008000083120380205607930070581007000060060002300
|
||||
060004000090080150001060004008650009004001307006000000000300800050709000000000010
|
||||
000000020000046007020000400040608001000001200006009030063100008900060040082700093
|
||||
380000020070000000004600500806500007200040060700000810030060008000400000562708040
|
||||
070006030000075080900023000000000500000001070003200004564000002090000857000030600
|
||||
050008310000704082200300460000600000605030100030000020527000000000000000408001000
|
||||
800360000600900730001070060000109074900000000006000081090602400042008000000000020
|
||||
000704000500020010640005900000000053090030000160000000000900001400007000019003407
|
||||
000006200200000390063250070570000063000000054009007800095800000306000507020000040
|
||||
001002509340000000050100003400090360000001005000600700060705040700000600000004000
|
||||
063008470000000610000000000670003500042000060000500000037000000000300081001807002
|
||||
090000020020000000005000000000070001000260804000090060014600200789420100500980040
|
||||
084000300050060074200000000000000000090458000042703005730900050600507040000030000
|
||||
800050000000000400306008025000004000000700810000000734020100000703600002000302160
|
||||
100000870000010034000800600508000409410690005060000000340700908050000000906000000
|
||||
609000000170000000000100260000000000020005100400600000000090047007300026950007301
|
||||
090000700600800000004090600076042810000960000000008000000500002508000071760010009
|
||||
003000298000006050000003000000005060000070002800600900040060035305800400007050600
|
||||
065800000200000000089007001500000600006070018000301200003208106000005000007000090
|
||||
820106030000800000670020800000000008109003600700000010002080006040000000000090304
|
||||
020000004000067000057800001900270000000600000000050002006004020109080040700900010
|
||||
900005160605030000080000340400006000013700000760090000000000000100360790309000010
|
||||
030000720200008600070200085054080300007009000000400000340000008060000000805073000
|
||||
001700050009003000076021809600000000000000007050000200700500020800070600905608001
|
||||
000490200054010079009003000000720000000900000000000045030500000040000087200004100
|
||||
000009702700320400000007091012000060506040000000090000000005003075000000409010007
|
||||
000802590500009013000000000000300070009780100310420080400000001900200800081000320
|
||||
103000070007000200000000000600509780050602090000087001000005008032000500900060030
|
||||
620004000508060090009201080005040800030000009900080310000000950000020000400000130
|
||||
000000003402060500000400070070050000090000600000901034960000000000000245000003109
|
||||
001000000200700060759000000003009026000500900000640005072000500900030000040260000
|
||||
000205000100000003800000640005300008306508000200000000400120080620400070000000060
|
||||
040900150600200300120040090590002600000000500000309040000000973007000405000100000
|
||||
000000000020010903000209408917040000000908000000037000208006010000004300039800000
|
||||
780010065000009030009020007100000000096000000305000002007160000060050081000230070
|
||||
400000060000820500000006203500703900000480050000500006900000084002000000700058030
|
||||
300009000008000000094180000009023807060040000003000420080600700047001006002097000
|
||||
708003905062000000050840007005400800200000000000007009300069480800300002000000000
|
||||
400800000001703000000010005200000040000900030803002001705004002009030000040070500
|
||||
000000000300000784002400530020000007058093040400760000003005000000000079807009200
|
||||
007090000900000640068200705003000000700000450802704003300000074200000500000058000
|
||||
790060000023100050600300000000075900000000067900000020000000045006090001402006003
|
||||
370000500000000700000290080750102800001004200003000004000700100000300048805009070
|
||||
000080060410200500700005083030000805000002304000000000300050600006304700080670002
|
39
levels/medium.txt
Normal file
39
levels/medium.txt
Normal file
@ -0,0 +1,39 @@
|
||||
000830000000000103000402090006000800000000000018000932800306020000004710700208040
|
||||
800900760000000000164000080007601000425070900010000002700400000000000200000009807
|
||||
605290700002005690000740001703000000264000003090000000006000507000001000957000000
|
||||
000005003790080600200390000000000040030974000900630800450000000076000000820500070
|
||||
700930004509008000002014070007000020150080097900000000000000542000020130000801000
|
||||
050600000900005000400200007010002040800009006004010890570001060000580000000700200
|
||||
008700050500200046032000000005026010000000000000040028040010000010060380000307000
|
||||
000009005100003002246010000000000003000040000010050049600800020500120806003000500
|
||||
005000700038004002000700030300000501060100040504000203170000800800307020000000050
|
||||
000700016008001000030280000203607005010003000000050160000000000080000030090526000
|
||||
010000000008570906005090084070080010009000060300400000040009000160000005000060008
|
||||
000000208002000040090000003900000000060407389370100000008000462100008000030000007
|
||||
003007000076829030280040500000490000000005000609200000800034000090050078000700020
|
||||
063000004001204000000060000000070918020009406004030200000000007009001000418007002
|
||||
032000850704000006069070003000000000076900000050704900800030500000008000000005004
|
||||
000405000000000010090032584000309000100020869000800005901000600000060002008900400
|
||||
000000605000005900080010000400000200005700400100002089000078040600240050000506000
|
||||
200000000013045080405003070780010000000004000000080050030007100900050000002000047
|
||||
070015600000060081000007000002000090500000000003006000760020035300000007901300008
|
||||
000490036700000000020800000080970000000006082000030050007064000000000025045080090
|
||||
000005000704800001000007308000000800007090020000004590820073400009050200010009030
|
||||
054000000000300000086004003502090860000805040000100000400001200091060000020580000
|
||||
050100020100780906000420005500000608008000004724800000000040000045000000007009000
|
||||
000050000705000028020307600800000970000000062400005003050000086986020007304000000
|
||||
910054200200000000436107000050000100600930002720406090000009000000000700000200005
|
||||
200000850600800000000040036000091000500060090900000210100530060000420000003006008
|
||||
000280000000406300009003000070908000000000006040017800300021609090000047200000080
|
||||
000102070007004280000030009000850742000009000300020005000501000000000900049008030
|
||||
003000501000500900009008002601003480000084005000050020004201009000040000100009600
|
||||
009500801000300700608007050000000000405000000010004300006705019500098400000010070
|
||||
900000051678000000010000400000800500487000000006000079000209000064000010500001060
|
||||
000010009006200000000007240609700302012600070030009050004000100000065007000002400
|
||||
034000280000200600007000000709000800040050007005920000600080090000000300008490500
|
||||
000043500070600000006005000000309045009002070010700023302000000600900050000000304
|
||||
410000709508000006000800040090008000100600000000003000800001605900034000030000001
|
||||
010785000008900000006000000003500067105300900047090800000860090000430000090000004
|
||||
000010000000097050007000040040709100083060000071008060400006038000000510058004700
|
||||
000500037006800000000070001380760004060020010007030605000287000520301000000000000
|
||||
036000040509100000000805006000004200900010300061900008000000004040000890300000001
|
4
levels/settings.txt
Normal file
4
levels/settings.txt
Normal file
@ -0,0 +1,4 @@
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
285
main.cpp
Normal file
285
main.cpp
Normal file
@ -0,0 +1,285 @@
|
||||
// sudoku.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
|
||||
//
|
||||
#include "display.h"
|
||||
#include "main_menu.h"
|
||||
#include "sudokusolving.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
system("chcp 65001");
|
||||
|
||||
|
||||
hideCursor();
|
||||
system("cls"); //bez tego dziwne rzeczy zaczynaja sie dziac
|
||||
|
||||
bool if_conitnue = true;
|
||||
while (if_conitnue == true)
|
||||
{
|
||||
int menu_option = 1, level_diff = 0;
|
||||
int score = 0, errors = 0;
|
||||
int score_multiplier = 0;
|
||||
|
||||
string menu_elements[4] = { "START GAME", "LEVEL DIFFICULTY", "OPTIONS", "EXIT" };
|
||||
string diff_menu_elements[4] = { "EASY", "MEDIUM", "HARD", "IMPOSSIBLE" };
|
||||
string continue_strings[2] = { "YES", "NO" };
|
||||
|
||||
string options_elelemns[4] = { "HIGHLIGHTING ROWS/COLUMNS", "HIGLIGHTING NUMBERS","HIGLIGHTING ERRORS","MAX NUMBER OF ERRORS (3)"};
|
||||
bool options_elements_bool[4];
|
||||
|
||||
/*for (int i = 0; i < 4; i++)
|
||||
{
|
||||
options_elements_bool[i] = true;
|
||||
|
||||
}
|
||||
options_elements_bool[0] = false;*/
|
||||
|
||||
settingsRead(options_elements_bool, 4);
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
menu_option = start_menu(menu_elements, "SUDOKU", 4);
|
||||
system("cls");
|
||||
if (menu_option == 0 || menu_option == 3) break;
|
||||
switch (menu_option)
|
||||
{
|
||||
case 1:
|
||||
level_diff = start_menu(diff_menu_elements, "DIFFICULTY", 4);
|
||||
break;
|
||||
case 2:
|
||||
menu_options(options_elelemns, "OPTIONS", 4, options_elements_bool);
|
||||
settingsSave(options_elements_bool, 4);
|
||||
break;
|
||||
}
|
||||
|
||||
system("cls");
|
||||
}
|
||||
int sudoku[9][9] = {
|
||||
{ 3, 4, 5, 0, 7, 1, 0, 0, 9 },
|
||||
{ 0, 0, 0, 3, 4, 0, 0, 0, 0 },
|
||||
{ 8, 9, 0, 2, 0, 0, 0, 0, 0 },
|
||||
{ 0, 3, 0, 0, 0, 4, 0, 0, 0 },
|
||||
{ 0, 6, 0, 0, 0, 0, 0, 0, 7 },
|
||||
{ 0, 0, 0, 0, 0, 2, 8, 5, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 8, 0 },
|
||||
{ 0, 5, 4, 0, 0, 0, 9, 0, 1 },
|
||||
{ 0, 0, 7, 0, 0, 0, 4, 0, 0 }
|
||||
};
|
||||
sudokuElement sudoku_array[9][9];
|
||||
sudokuElement sudoku_array_solved[9][9];
|
||||
|
||||
bool score_array[9][9] = { {false} };
|
||||
bool error_array[9][9] = { {false} };
|
||||
int previous_value_array[9][9] = { { 0 } };
|
||||
|
||||
sudokuElement hidden_array_pause[9][9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
hidden_array_pause[i][j].value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
string sudoku_string = sudokuFromFile(level_diff);
|
||||
stringToSudoku(sudoku_string, sudoku);
|
||||
int active_element_winning = 0;
|
||||
int active_element_give_up = 0;
|
||||
int active_element_error = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
sudoku_array[i][j].value = sudoku[i][j];
|
||||
sudoku_array[i][j].type = 0;
|
||||
if (sudoku[i][j] > 0) sudoku_array[i][j].type = 1;
|
||||
|
||||
sudoku_array_solved[i][j].value = sudoku[i][j];
|
||||
sudoku_array_solved[i][j].type = 0;
|
||||
if (sudoku[i][j] > 0) sudoku_array_solved[i][j].type = 1;
|
||||
|
||||
}
|
||||
}
|
||||
sudokuSolvable(sudoku_array_solved, 0, 0);
|
||||
|
||||
system("cls");
|
||||
XY_coord xy_object(0, 0);
|
||||
bool if_winning_bool = false;
|
||||
bool if_giveup_bool = false;
|
||||
|
||||
bool if_winning_enter = false;
|
||||
bool if_give_up_enter = false;
|
||||
|
||||
bool if_error_enter = false;
|
||||
|
||||
bool winning_exit = false;
|
||||
bool is_pause = false;
|
||||
chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now();
|
||||
chrono::high_resolution_clock::time_point now = chrono::high_resolution_clock::now();
|
||||
chrono::microseconds duration;
|
||||
chrono::microseconds elapsed_duration(0);
|
||||
|
||||
switch (menu_option)
|
||||
{
|
||||
case 0:
|
||||
while (if_winning_bool == false && winning_exit == false)
|
||||
{
|
||||
refreshingScreen();
|
||||
if (is_pause == false)
|
||||
{
|
||||
chrono::high_resolution_clock::time_point now = chrono::high_resolution_clock::now();
|
||||
duration = std::chrono::duration_cast<chrono::microseconds>(now - start) + elapsed_duration;
|
||||
|
||||
display(sudoku_array, sudoku_array_solved, level_diff, score, score_multiplier, errors, xy_object, options_elements_bool, 2,
|
||||
duration, if_giveup_bool, active_element_give_up, if_give_up_enter,
|
||||
if_winning_bool, active_element_winning, if_winning_enter,
|
||||
score_array, error_array, previous_value_array, is_pause, if_error_enter, active_element_error);
|
||||
switching_xy_sudoku(xy_object, sudoku_array, score, is_pause, if_giveup_bool);
|
||||
if_winning_bool = ifWinning(sudoku_array, sudoku_array_solved);
|
||||
}
|
||||
if (is_pause == true && if_giveup_bool == false)
|
||||
{
|
||||
if (elapsed_duration == chrono::microseconds(0))
|
||||
{
|
||||
chrono::high_resolution_clock::time_point pause_time = chrono::high_resolution_clock::now();
|
||||
elapsed_duration = std::chrono::duration_cast<chrono::microseconds>(pause_time - start);
|
||||
}
|
||||
refreshingScreen();
|
||||
display(hidden_array_pause, sudoku_array_solved, level_diff, score, score_multiplier, errors, xy_object, options_elements_bool, 2,
|
||||
duration, if_giveup_bool, active_element_give_up, if_give_up_enter, if_winning_bool,
|
||||
active_element_winning, if_winning_enter, score_array, error_array, previous_value_array, is_pause, if_error_enter, active_element_error);
|
||||
|
||||
switching_xy_sudoku(xy_object, sudoku_array, score, is_pause, if_giveup_bool);
|
||||
}
|
||||
|
||||
|
||||
if (if_giveup_bool == true)
|
||||
{
|
||||
if (elapsed_duration == chrono::microseconds(0))
|
||||
{
|
||||
chrono::high_resolution_clock::time_point pause_time = chrono::high_resolution_clock::now();
|
||||
elapsed_duration = std::chrono::duration_cast<chrono::microseconds>(pause_time - start);
|
||||
}
|
||||
bool is_enter_2 = false;
|
||||
while (is_enter_2 == false)
|
||||
{
|
||||
refreshingScreen();
|
||||
display(hidden_array_pause, sudoku_array_solved, level_diff, score, score_multiplier, errors, xy_object, options_elements_bool, 2,
|
||||
duration, if_giveup_bool, active_element_give_up, is_enter_2, if_winning_bool, active_element_winning,
|
||||
if_winning_enter, score_array, error_array, previous_value_array, is_pause, if_error_enter, active_element_error);
|
||||
//switching_xy_sudoku(xy_object, sudoku_array, score, is_pause, if_giveup_bool);
|
||||
}
|
||||
|
||||
if (is_enter_2 == true)
|
||||
{
|
||||
switch (active_element_give_up)
|
||||
{
|
||||
case 0:
|
||||
if_conitnue = true;
|
||||
if_winning_bool = false;
|
||||
winning_exit = true;
|
||||
system("cls");
|
||||
break;
|
||||
case 1:
|
||||
if_giveup_bool = false;
|
||||
is_pause = false;
|
||||
system("cls");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_pause && elapsed_duration != chrono::microseconds(0))
|
||||
{
|
||||
start = chrono::high_resolution_clock::now() - elapsed_duration;
|
||||
elapsed_duration = chrono::microseconds(0);
|
||||
|
||||
}
|
||||
|
||||
if (if_winning_bool == true)
|
||||
{
|
||||
|
||||
bool is_enter = false;
|
||||
while (is_enter == false)
|
||||
{
|
||||
refreshingScreen();
|
||||
|
||||
display(sudoku_array, sudoku_array_solved, level_diff, score, score_multiplier, errors, xy_object, options_elements_bool,
|
||||
2, duration, if_giveup_bool, active_element_give_up, if_give_up_enter, if_winning_bool,
|
||||
active_element_winning, is_enter, score_array, error_array, previous_value_array, is_pause, if_error_enter, active_element_error);
|
||||
|
||||
}
|
||||
if (is_enter == true)
|
||||
{
|
||||
switch (active_element_winning)
|
||||
{
|
||||
case 0:
|
||||
if_conitnue = true;
|
||||
if_winning_bool = false;
|
||||
winning_exit = true;
|
||||
system("cls");
|
||||
break;
|
||||
case 1:
|
||||
if_conitnue = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors == 3 && options_elements_bool[3] == true)
|
||||
{
|
||||
bool errors_enter = false;
|
||||
while (errors_enter == false)
|
||||
{
|
||||
refreshingScreen();
|
||||
|
||||
display(sudoku_array, sudoku_array_solved, level_diff, score, score_multiplier, errors, xy_object, options_elements_bool,
|
||||
2, duration, if_giveup_bool, active_element_give_up, if_give_up_enter, if_winning_bool,
|
||||
active_element_winning, if_winning_enter, score_array, error_array, previous_value_array, is_pause, errors_enter, active_element_error);
|
||||
|
||||
}
|
||||
if (errors_enter == true)
|
||||
{
|
||||
switch (active_element_error)
|
||||
{
|
||||
case 0:
|
||||
errors--;
|
||||
score = score - 1000;
|
||||
system("cls");
|
||||
break;
|
||||
case 1:
|
||||
if_conitnue = true;
|
||||
if_winning_bool = false;
|
||||
winning_exit = true;
|
||||
system("cls");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
if_conitnue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
system("cls");
|
||||
cout << "Program has been successfully closed!\n";
|
||||
cout << endl;
|
||||
system("pause");
|
||||
//cout << "Hello World!\n";
|
||||
return 2137;
|
||||
}
|
||||
|
||||
// Uruchomienie programu: Ctrl + F5 lub menu Debugowanie > Uruchom bez debugowania
|
||||
// Debugowanie programu: F5 lub menu Debugowanie > Rozpocznij debugowanie
|
||||
|
||||
// Porady dotyczące rozpoczynania pracy:
|
||||
// 1. Użyj okna Eksploratora rozwiązań, aby dodać pliki i zarządzać nimi
|
||||
// 2. Użyj okna programu Team Explorer, aby nawiązać połączenie z kontrolą źródła
|
||||
// 3. Użyj okna Dane wyjściowe, aby sprawdzić dane wyjściowe kompilacji i inne komunikaty
|
||||
// 4. Użyj okna Lista błędów, aby zobaczyć błędy
|
||||
// 5. Wybierz pozycję Projekt > Dodaj nowy element, aby utworzyć nowe pliki kodu, lub wybierz pozycję Projekt > Dodaj istniejący element, aby dodać istniejące pliku kodu do projektu
|
||||
// 6. Aby w przyszłości ponownie otworzyć ten projekt, przejdź do pozycji Plik > Otwórz > Projekt i wybierz plik sln
|
194
main_menu.cpp
Normal file
194
main_menu.cpp
Normal file
@ -0,0 +1,194 @@
|
||||
#include "main_menu.h"
|
||||
|
||||
bool switching_elements(int & active_element, int max_element)
|
||||
{
|
||||
if (_kbhit()) {
|
||||
char pressed_key = _getch();
|
||||
if (pressed_key == 'P' || pressed_key == 's') active_element++; //arrow_down
|
||||
if (pressed_key == 'H' || pressed_key == 'w') active_element--; //arow_up
|
||||
if (pressed_key == 13) return true;//enter
|
||||
|
||||
if (active_element == -1) active_element = max_element;
|
||||
if (active_element == max_element + 1) active_element = 0;
|
||||
|
||||
|
||||
//cout << "You pressed: " << pressed_key << " (ASCII: " << int(pressed_key) << ")" << endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int start_menu(string menu_elements[], string title, int array_size)
|
||||
{
|
||||
|
||||
int active_element = 0;
|
||||
string tab_display = "\t ";
|
||||
bool is_enter = false;
|
||||
while (is_enter == false)
|
||||
{
|
||||
cout << endl;
|
||||
cout << tab_display << " " << title << endl;
|
||||
cout << tab_display;
|
||||
for (int i = 0; i < title.size() + 2; i++)
|
||||
{
|
||||
cout << "-";
|
||||
}
|
||||
cout << endl;
|
||||
cout << endl << endl;
|
||||
for (int i = 0; i < array_size; i++)
|
||||
{
|
||||
if (active_element == i)
|
||||
{
|
||||
setConsoleColor(10, 0);
|
||||
cout << "\t >> " << menu_elements[i] << " <<" << endl << endl;
|
||||
setConsoleColor(15, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << tab_display <<menu_elements[i] <<" " << endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
is_enter = switching_elements(active_element, array_size - 1);
|
||||
refreshingScreen();
|
||||
}
|
||||
return active_element;
|
||||
}
|
||||
|
||||
bool switching_elements_option(int& active_element, int max_element, bool * bool_array, int array_size)
|
||||
{
|
||||
if (_kbhit()) {
|
||||
char pressed_key = _getch();
|
||||
if (pressed_key == 'P' || pressed_key == 's') active_element++; //arrow_down
|
||||
if (pressed_key == 'H' || pressed_key == 'w') active_element--; //arow_up
|
||||
|
||||
if (active_element == -1) active_element = max_element;
|
||||
if (active_element == max_element + 1) active_element = 0;
|
||||
|
||||
if (pressed_key == 13 || pressed_key == 27) return true;//enter
|
||||
|
||||
if (pressed_key == 'K' || pressed_key == 'a' || pressed_key == 'M' || pressed_key == 'd') //arrow_left and right
|
||||
{
|
||||
switch (bool_array[active_element])
|
||||
{
|
||||
case true: bool_array[active_element] = false; break;
|
||||
case false: bool_array[active_element] = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//cout << "You pressed: " << pressed_key << " (ASCII: " << int(pressed_key) << ")" << endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void menu_options(string options_elelemns[], string title, int array_size, bool options_elelemns_bool[])
|
||||
{
|
||||
int active_element = 0;
|
||||
string tab_display = "\t ";
|
||||
bool is_enter = false;
|
||||
|
||||
while (is_enter == false)
|
||||
{
|
||||
cout << endl;
|
||||
cout << tab_display << " " << title << endl;
|
||||
cout << tab_display;
|
||||
for (int i = 0; i < title.size() + 2; i++)
|
||||
{
|
||||
cout << "-";
|
||||
}
|
||||
cout << endl;
|
||||
cout << endl << endl;
|
||||
|
||||
for (int i = 0; i < array_size; i++)
|
||||
{
|
||||
if (active_element == i)
|
||||
{
|
||||
//switching_elements_option(options_elelemns_bool[i]);
|
||||
setConsoleColor(10, 0);
|
||||
cout << "\t >> " << options_elelemns[i];
|
||||
switch (options_elelemns_bool[i])
|
||||
{
|
||||
case true:
|
||||
cout << ": ON ";
|
||||
break;
|
||||
|
||||
case false:
|
||||
cout << ": OFF";
|
||||
break;
|
||||
}
|
||||
cout << " <<" << endl << endl;
|
||||
setConsoleColor(15, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << tab_display << options_elelemns[i];
|
||||
switch (options_elelemns_bool[i])
|
||||
{
|
||||
case true:
|
||||
cout << ": ON";
|
||||
break;
|
||||
|
||||
case false:
|
||||
cout << ": OFF";
|
||||
break;
|
||||
}
|
||||
cout << " " << endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
is_enter = switching_elements_option(active_element, array_size - 1, options_elelemns_bool, 2);
|
||||
refreshingScreen();
|
||||
}
|
||||
}
|
||||
void settingsRead(bool options_elements_bool[], int array_size)
|
||||
{
|
||||
string file_name = "levels/settings.txt";
|
||||
ifstream file;
|
||||
file.open(file_name.c_str(), ios::in);
|
||||
|
||||
vector <string> file_lines;
|
||||
int line_counter = 0;
|
||||
string line_buffor="";
|
||||
|
||||
if (file.good())
|
||||
{
|
||||
while (getline(file, line_buffor))
|
||||
{
|
||||
file_lines.push_back(line_buffor);
|
||||
line_counter++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (file_lines.at(i) == "0")
|
||||
{
|
||||
options_elements_bool[i] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
options_elements_bool[i] = true;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void settingsSave(bool options_elements_bool[], int array_size)
|
||||
{
|
||||
string file_name = "levels/settings.txt";
|
||||
ofstream file;
|
||||
file.open(file_name.c_str(), ios::out);
|
||||
|
||||
for (int i = 0; i < array_size; i++)
|
||||
{
|
||||
if (options_elements_bool[i] == false)
|
||||
{
|
||||
file << "0" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << "1" << endl;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
7
main_menu.h
Normal file
7
main_menu.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "display.h"
|
||||
|
||||
int start_menu(string menu_elements[], string title, int array_size);
|
||||
void menu_options(string options_elelemns[], string title, int array_size, bool options_elelemns_bool[]);
|
||||
void settingsRead(bool options_elelemns_bool[], int array_size);
|
||||
void settingsSave(bool options_elements_bool[], int array_size);
|
115
sudokusolving.cpp
Normal file
115
sudokusolving.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
#include "sudokusolving.h"
|
||||
//i j
|
||||
bool isValid(sudokuElement sudoku_array[9][9], int x, int y, int number)
|
||||
{
|
||||
//column
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
if (sudoku_array[i][y].value == number)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//rows
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
if (sudoku_array[x][j].value == number)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int start_row = x - x % 3;
|
||||
int start_column = y - y % 3;
|
||||
|
||||
//square 3x3
|
||||
for (int i = start_row; i < start_row + 3; i++)
|
||||
{
|
||||
for (int j = start_column; j < start_column + 3; j++)
|
||||
{
|
||||
if (number == sudoku_array[i][j].value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool sudokuSolvable(sudokuElement sudoku_array[9][9], int x , int y)
|
||||
{
|
||||
if (x == 9) return true;
|
||||
else if (y == 9) return sudokuSolvable(sudoku_array, x + 1, 0);
|
||||
else if (sudoku_array[x][y].value != 0) return sudokuSolvable(sudoku_array, x, y + 1);
|
||||
else
|
||||
{
|
||||
for (int i = 1; i <= 9; i++)
|
||||
{
|
||||
if (isValid(sudoku_array, x, y, i) == true)
|
||||
{
|
||||
sudoku_array[x][y].value = i;
|
||||
if (sudokuSolvable(sudoku_array, x, y + 1) == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
sudoku_array[x][y].value = 0;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isCorrect(sudokuElement sudoku_array_solved[9][9], int x, int y, int number)
|
||||
{
|
||||
if (sudoku_array_solved[x][y].value == number) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
string sudokuFromFile(int level)
|
||||
{
|
||||
string file_name = "levels/";
|
||||
switch (level)
|
||||
{
|
||||
case 0: file_name += "easy.txt"; break;
|
||||
case 1: file_name += "medium.txt"; break;
|
||||
case 2: file_name += "hard.txt"; break;
|
||||
case 3: file_name += "impossible.txt"; break;
|
||||
}
|
||||
ifstream file;
|
||||
file.open(file_name.c_str(), ios::in);
|
||||
|
||||
vector <string> file_lines;
|
||||
int line_counter = 0;
|
||||
string line_buffor;
|
||||
|
||||
if (file.good())
|
||||
{
|
||||
while (getline(file, line_buffor))
|
||||
{
|
||||
file_lines.push_back(line_buffor);
|
||||
line_counter++;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
srand(time(NULL));
|
||||
int chosen_sudoku = rand() % line_counter;
|
||||
return file_lines.at(chosen_sudoku);
|
||||
}
|
||||
|
||||
void stringToSudoku(string sudoku_text, int sudoku_array[9][9])
|
||||
{
|
||||
int index_i = 0, index_j = 0;
|
||||
|
||||
for (int i = 0; i < sudoku_text.size(); i++)
|
||||
{
|
||||
sudoku_array[index_i][index_j] = sudoku_text[i] - '0';
|
||||
index_j++;
|
||||
if (index_j == 9)
|
||||
{
|
||||
index_j = 0;
|
||||
index_i++;
|
||||
}
|
||||
}
|
||||
}
|
10
sudokusolving.h
Normal file
10
sudokusolving.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "display.h"
|
||||
|
||||
bool isValid(sudokuElement sudoku_array[9][9], int x, int y, int number);
|
||||
bool sudokuSolvable(sudokuElement sudoku_array[9][9], int x, int y);
|
||||
|
||||
// Other funtion for checking whether written number is correct
|
||||
|
||||
string sudokuFromFile(int level);
|
||||
void stringToSudoku(string sudoku_text, int sudoku_array[9][9]);
|
Loading…
Reference in New Issue
Block a user