├── .cpp ├── .gitattributes ├── .gitignore ├── AboutForm.cpp ├── AboutForm.h ├── AboutForm.resx ├── GameForm.cpp ├── GameForm.h ├── GameForm.resx ├── GameLogic.cpp ├── GameLogic.h ├── GameStats.cpp ├── GameStats.h ├── GameUser.cpp ├── GameUser.h ├── MainForm.cpp ├── MainForm.h ├── MainForm.resx ├── README.md ├── aboutIMG.png ├── background.png ├── cpp.hint ├── icon.ico ├── logo.png ├── main.cpp ├── resource.h ├── szablon.rc ├── szablon.sln ├── szablon.vcxproj └── szablon.vcxproj.filters /.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/.cpp -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /AboutForm.cpp: -------------------------------------------------------------------------------- 1 | #include "AboutForm.h" 2 | namespace szablon { 3 | AboutForm::AboutForm(void) { 4 | InitializeComponent(); 5 | } 6 | void AboutForm::form_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { 7 | if (e->KeyChar == 'P' || e->KeyChar == 'p') { 8 | this->Close(); 9 | } 10 | 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /AboutForm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/AboutForm.h -------------------------------------------------------------------------------- /GameForm.cpp: -------------------------------------------------------------------------------- 1 | #include "GameForm.h" 2 | #include "GameUser.h" 3 | #include "GameLogic.h" 4 | #include "GameStats.h" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace szablon { 10 | GameForm::GameForm(GameUser* gameuser, std::string difficulty, int difficultyRemoveDigits, GameStats* gameStats) 11 | { 12 | InitializeComponent(); 13 | this->gameUser = gameuser; 14 | this->gameStats = gameStats; 15 | this->difficulty = difficultyRemoveDigits; 16 | this->createGame(); 17 | } 18 | void GameForm::createGame() { 19 | this->entries = 0; 20 | this->entries_wrong = 0; 21 | this->hint = 0; 22 | 23 | this->gameLogic = new GameLogic(); 24 | this->gameLogic->fillArrays(); 25 | this->gameLogic->GenerateSudoku(); 26 | this->gameLogic->removeDigits(this->difficulty); 27 | this->CreateTextBoxes(); 28 | this->unFocusBox(); 29 | this->UpdateUserName(); 30 | this->UpdatePoints(); 31 | this->UpdateDifficulty(); 32 | this->UpdateHighScore(); 33 | } 34 | void GameForm::UpdateDifficulty() { 35 | this->label_difficulty->Text = "Trudność: " + gcnew System::String(this->gameUser->getDifficulty().c_str()); 36 | } 37 | void GameForm::UpdateUserName() { 38 | this->label_username->Text = "Nazwa: " + gcnew System::String(this->gameUser->getName().c_str()); 39 | } 40 | void GameForm::UpdatePoints() { 41 | this->label_points->Text = "Punkty: " + this->gameUser->getPoints(); 42 | this->label_total->Text = "Total: " + this->gameUser->getTotal(); 43 | } 44 | void GameForm::UpdateHighScore() { 45 | this->high_score_name->Text = "Nazwa: "+gcnew System::String(this->gameStats->getHighScoreUser()->getName().c_str()); 46 | this->high_score_points->Text = "Punkty: " + this->gameStats->getHighScore(); 47 | } 48 | void GameForm::CreateTextBoxes() { 49 | for (int blockRow = 0; blockRow < 3; blockRow++) 50 | for (int blockCol = 0; blockCol < 3; blockCol++) { 51 | auto tb = dynamic_cast(this->table->GetControlFromPosition(blockCol, blockRow)); 52 | if (!tb) continue; 53 | for (int rowOffset = 0; rowOffset < 3; rowOffset++) 54 | for (int colOffset = 0; colOffset < 3; colOffset++) { 55 | int globalRow = blockRow * 3 + rowOffset; 56 | int globalCol = blockCol * 3 + colOffset; 57 | CreateTextBox(tb, globalRow, globalCol); 58 | } 59 | } 60 | label1->Text += this->gameLogic->getGenerateTime() + "ms"; 61 | label2->Text += this->gameLogic->getSamples(); 62 | } 63 | void GameForm::CreateTextBox(TableLayoutPanel^ parentTable, int row, int col) { 64 | TextBox^ text = gcnew TextBox(); 65 | text->BackColor = System::Drawing::Color::FromArgb(13, 50, 50); 66 | text->Padding = System::Windows::Forms::Padding(0); 67 | text->Margin = System::Windows::Forms::Padding(0); 68 | text->Width = 57; 69 | text->Height = 57; 70 | text->AutoSize = false; 71 | text->MaxLength = 1; 72 | text->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 73 | static_cast(238))); 74 | text->ForeColor = ForeColor.White; 75 | text->TextAlign = HorizontalAlignment::Center; 76 | text->KeyPress += gcnew KeyPressEventHandler(this, &GameForm::TextBox_KeyPress); 77 | 78 | int value = gameLogic->getBoard(row, col); 79 | text->Name = L"text_" + row + "_" + col; 80 | text->Tag = gcnew array{ row, col }; 81 | 82 | if (value != 0) { 83 | text->Text = value.ToString(); 84 | text->ReadOnly = true; 85 | text->BackColor = System::Drawing::Color::FromArgb(20, 170, 20); 86 | text->Click += gcnew EventHandler(this, &GameForm::LockedTextBox_Click); 87 | } 88 | 89 | parentTable->Controls->Add(text, col % 3, row % 3); 90 | } 91 | void GameForm::TextBox_KeyPress(Object^ sender, KeyPressEventArgs^ e) 92 | { 93 | if ((!Char::IsDigit(e->KeyChar) || e->KeyChar == '0') && e->KeyChar != (char)Keys::Back) { 94 | e->Handled = true; 95 | return; 96 | } 97 | TextBox^ textBox = dynamic_cast(sender); 98 | if (!textBox || textBox->ReadOnly) { 99 | this->unFocusBox(); 100 | return; 101 | } 102 | if (e->KeyChar == (char)Keys::Back) { 103 | return; 104 | } 105 | int value = e->KeyChar - '0'; 106 | auto coordinates = dynamic_cast^>(textBox->Tag); 107 | if (!coordinates) return; 108 | 109 | int row = coordinates[0]; 110 | int col = coordinates[1]; 111 | 112 | gameLogic->setBoard(row, col, value); 113 | if (value == gameLogic->getCopyBoard(row, col)) { 114 | this->unFocusBox(); 115 | textBox->BackColor = System::Drawing::Color::FromArgb(255, 170, 20); 116 | textBox->Text = value.ToString(); 117 | textBox->ReadOnly = true; 118 | textBox->Click += gcnew EventHandler(this, &GameForm::LockedTextBox_Click); 119 | this->gameLogic->setCopyBoard(row, col, 0); 120 | this->entries++; 121 | this->gameUser->addPoints(5); 122 | } 123 | else { 124 | this->entries_wrong++; 125 | this->gameUser->removePoints(1); 126 | } 127 | this->UpdatePoints(); 128 | this->label_wrong_guess->Text = "Błędne: " + this->entries_wrong; 129 | this->label_right_guess->Text = "Poprawne: " + this->entries; 130 | } 131 | void GameForm::LockedTextBox_Click(Object^ sender, EventArgs^ e) { 132 | this->unFocusBox(); 133 | } 134 | void GameForm::unFocusBox() 135 | { 136 | this->table->Focus(); 137 | this->table->Select(); 138 | } 139 | void GameForm::verify_button_Click(System::Object^ sender, System::EventArgs^ e) { 140 | if (this->gameLogic->checkSudoku()) { 141 | System::String^ userName = gcnew System::String(this->gameUser->getName().c_str()); 142 | System::String^ message = "Gratulacje " + userName + "!\nUdało Ci się poprawnie rozwiązać sudoku!\n\nUzyskując " + 143 | this->gameUser->getPoints().ToString() + " Punktów \n"; 144 | 145 | MessageBox::Show( 146 | message, 147 | "Wygrana", 148 | MessageBoxButtons::OK, 149 | MessageBoxIcon::Information 150 | ); 151 | this->gameStats->saveUser(this->gameUser); 152 | this->Close(); 153 | return; 154 | } 155 | MessageBox::Show( 156 | "Niestety, rozwiązanie jest błędne. Spróbuj jeszcze raz!", 157 | "Błąd", 158 | MessageBoxButtons::OK, 159 | MessageBoxIcon::Error 160 | ); 161 | } 162 | 163 | void GameForm::help_button_Click(System::Object^ sender, System::EventArgs^ e) 164 | { 165 | for (int blockRow = 0; blockRow < 3; blockRow++) { 166 | for (int blockCol = 0; blockCol < 3; blockCol++) { 167 | TableLayoutPanel^ tb = dynamic_cast(this->table->GetControlFromPosition(blockCol, blockRow)); 168 | if (tb != nullptr && ProcessBlock(tb, blockRow, blockCol)) { 169 | return; 170 | } 171 | } 172 | } 173 | } 174 | void GameForm::reset_button_Click(System::Object^ sender, System::EventArgs^ e) 175 | { 176 | for (int blockRow = 0; blockRow < 3; blockRow++) 177 | for (int blockCol = 0; blockCol < 3; blockCol++) { 178 | auto tb = dynamic_cast(this->table->GetControlFromPosition(blockCol, blockRow)); 179 | if (tb == nullptr) continue; 180 | for (int rowOffset = 0; rowOffset < 3; rowOffset++) 181 | for (int colOffset = 0; colOffset < 3; colOffset++) { 182 | auto textBox = dynamic_cast(tb->GetControlFromPosition(colOffset, rowOffset)); 183 | if (textBox)tb->Controls->Remove(textBox); 184 | } 185 | } 186 | this->label_wrong_guess->Text = "Błędne: 0"; 187 | this->label_right_guess->Text = "Poprawne: 0"; 188 | this->label_hint->Text = "Wskazówki: 0"; 189 | this->label1->Text = "Generowanie: "; 190 | this->label2->Text = "Kroki: "; 191 | 192 | this->entries = 0; 193 | this->entries_wrong = 0; 194 | this->hint = 0; 195 | this->gameUser->setPoints(0); 196 | 197 | this->createGame(); 198 | this->unFocusBox(); 199 | 200 | } 201 | bool GameForm::ProcessBlock(TableLayoutPanel^ tb, int blockRow, int blockCol) { 202 | for (int rowOffset = 0; rowOffset < 3; rowOffset++) { 203 | for (int colOffset = 0; colOffset < 3; colOffset++) { 204 | int globalRow = blockRow * 3 + rowOffset; 205 | int globalCol = blockCol * 3 + colOffset; 206 | int value = this->gameLogic->getCopyBoard(globalRow, globalCol); 207 | 208 | if (value != 0) { 209 | UpdateTextBox(tb, rowOffset, colOffset, value); 210 | this->gameLogic->setBoard(globalRow, globalCol, value); 211 | this->gameLogic->setCopyBoard(globalRow, globalCol, 0); 212 | this->gameUser->removePoints(5); 213 | this->UpdatePoints(); 214 | return true; 215 | } 216 | } 217 | } 218 | return false; 219 | } 220 | void GameForm::UpdateTextBox(TableLayoutPanel^ tb, int rowOffset, int colOffset, int value) { 221 | TextBox^ textBox = dynamic_cast(tb->GetControlFromPosition(colOffset, rowOffset)); 222 | if (textBox != nullptr) { 223 | //HELP ACTION 224 | textBox->BackColor = System::Drawing::Color::FromArgb(170, 20, 20); 225 | textBox->Text = value.ToString(); 226 | textBox->ReadOnly = true; 227 | textBox->Click += gcnew EventHandler(this, &GameForm::LockedTextBox_Click); 228 | this->label_hint->Text = "Wskazówki: " + (++this->hint); 229 | } 230 | } 231 | GameUser* GameForm::getGameUser() 232 | { 233 | return this->gameUser; 234 | } 235 | GameStats* GameForm::getGameStats() { 236 | return this->gameStats; 237 | } 238 | int GameForm::getEntriesRight() 239 | { 240 | return this->entries; 241 | } 242 | int GameForm::getEntriesWrong() 243 | { 244 | return this->entries_wrong; 245 | } 246 | int GameForm::getHint() 247 | { 248 | return this->hint; 249 | } 250 | void GameForm::setGameUser(GameUser* gameuser) 251 | { 252 | this->gameUser = gameuser; 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /GameForm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/GameForm.h -------------------------------------------------------------------------------- /GameLogic.cpp: -------------------------------------------------------------------------------- 1 | #include "GameLogic.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace szablon { 7 | GameLogic::GameLogic() { 8 | unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); 9 | this->rand = std::mt19937(seed); 10 | this->generate_time = 0; 11 | this->samples = 0; 12 | } 13 | void GameLogic::GenerateSudoku() 14 | { 15 | auto start = std::chrono::high_resolution_clock::now(); 16 | while (fillValues()) {} 17 | auto end = std::chrono::high_resolution_clock::now(); 18 | auto duration = std::chrono::duration_cast(end - start); 19 | this->generate_time = static_cast(duration.count()) / 1000000; //nano -> ms 20 | } 21 | void GameLogic::fillArrays() 22 | { 23 | for (int row = 0; row < 9; row++) 24 | { 25 | for (int col = 0; col < 9; col++) 26 | { 27 | board[row][col] = 0; 28 | copy_board[row][col] = 0; 29 | } 30 | } 31 | } 32 | bool GameLogic::solveSudoku() { 33 | int row, col; 34 | if (!hasEmptyCell()) 35 | { 36 | return true; 37 | } 38 | for (int value = 1; value <= 9; value++) 39 | { 40 | if (!CheckIfSafe(row, col, value)) 41 | { 42 | continue; 43 | } 44 | board[row][col] = value; 45 | if (solveSudoku()) 46 | { 47 | return true; 48 | } 49 | board[row][col] = 0; 50 | } 51 | return false; 52 | } 53 | 54 | bool GameLogic::fillValues() 55 | { 56 | this->samples++; 57 | int values[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 58 | std::shuffle(values, values + 9, rand); 59 | for (int i = 0; i < 9; i++) 60 | { 61 | for (int j = 0; j < 9; j++) 62 | { 63 | if (board[i][j] != 0) 64 | { 65 | continue; 66 | } 67 | for (int value : values) 68 | { 69 | if (!CheckIfSafe(i, j, value)) 70 | { 71 | continue; 72 | } 73 | board[i][j] = value; 74 | if (!hasEmptyCell() || fillValues()) 75 | { 76 | return true; 77 | } 78 | board[i][j] = 0; 79 | } 80 | return false; 81 | } 82 | } 83 | return false; 84 | } 85 | bool GameLogic::hasEmptyCell() 86 | { 87 | for (int r = 0; r < 9; r++) 88 | { 89 | for (int c = 0; c < 9; c++) 90 | { 91 | if (board[r][c] == 0) 92 | { 93 | return true; 94 | } 95 | } 96 | } 97 | return false; 98 | } 99 | 100 | bool GameLogic::CheckIfSafe(int& row, int& col, int num) 101 | { 102 | for (int c = 0; c < 9; c++) 103 | { 104 | if (board[row][c] == num) 105 | { 106 | return false; 107 | } 108 | } 109 | 110 | for (int r = 0; r < 9; r++) 111 | { 112 | if (board[r][col] == num) 113 | { 114 | return false; 115 | } 116 | } 117 | 118 | int startRow = (row / 3) * 3; 119 | int startCol = (col / 3) * 3; 120 | for (int r = startRow; r < startRow + 3; r++) 121 | { 122 | for (int c = startCol; c < startCol + 3; c++) 123 | { 124 | if (board[r][c] == num) 125 | { 126 | return false; 127 | } 128 | } 129 | } 130 | return true; 131 | } 132 | 133 | bool GameLogic::checkSudoku() { 134 | for (int r = 0; r < 9; r++) 135 | { 136 | for (int c = 0; c < 9; c++) 137 | { 138 | if (copy_board[r][c] != 0) 139 | { 140 | return false; 141 | } 142 | } 143 | } 144 | return true; 145 | } 146 | 147 | void GameLogic::removeDigits(int count) 148 | { 149 | while (count > 0) { 150 | int cellId = rand() % 81; 151 | int row = cellId / 9; 152 | int col = cellId % 9; 153 | 154 | if (board[row][col] != 0) 155 | { 156 | copy_board[row][col] = board[row][col]; 157 | board[row][col] = 0; 158 | count--; 159 | } 160 | } 161 | } 162 | double GameLogic::getGenerateTime() 163 | { 164 | return this->generate_time; 165 | } 166 | int GameLogic::getSamples() 167 | { 168 | return this->samples; 169 | } 170 | int GameLogic::getBoard(int x, int y) 171 | { 172 | return this->board[x][y]; 173 | } 174 | int GameLogic::getCopyBoard(int x, int y) 175 | { 176 | return this->copy_board[x][y]; 177 | } 178 | void GameLogic::setBoard(int x, int y, int value) 179 | { 180 | this->board[x][y] = value; 181 | } 182 | void GameLogic::setCopyBoard(int x, int y, int value) 183 | { 184 | this->copy_board[x][y] = value; 185 | } 186 | GameLogic::~GameLogic() { 187 | delete copy_board; 188 | delete board; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /GameLogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace szablon { 4 | 5 | class GameLogic { 6 | public: 7 | GameLogic(); 8 | double getGenerateTime(); 9 | 10 | int getSamples(); 11 | int getBoard(int x, int y); 12 | int getCopyBoard(int x, int y); 13 | 14 | void setBoard(int x, int y, int value); 15 | void setCopyBoard(int x, int y, int value); 16 | 17 | void GenerateSudoku(); 18 | void fillArrays(); 19 | void removeDigits(int count); 20 | 21 | bool solveSudoku(); 22 | bool checkSudoku(); 23 | bool CheckIfSafe(int& row, int& col, int num); 24 | bool fillValues(); 25 | bool hasEmptyCell(); 26 | private: 27 | std::mt19937 rand; 28 | int board[9][9]; 29 | int copy_board[9][9]; 30 | int samples; 31 | double generate_time; 32 | protected: 33 | ~GameLogic(); 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /GameStats.cpp: -------------------------------------------------------------------------------- 1 | #include "GameStats.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | namespace szablon { 8 | GameStats::GameStats(): gameuser(nullptr) {} 9 | 10 | void GameStats::loadUser(std::string split) { 11 | std::vector lines; 12 | std::istringstream stream(split); 13 | std::string segment; 14 | while (std::getline(stream, segment, ';')) { 15 | lines.push_back(segment); 16 | } 17 | 18 | if (lines.empty()) { 19 | return; 20 | } 21 | std::string userName = lines[0]; 22 | GameUser* gameuser = new GameUser(userName, 0, 0, "-", true); 23 | int pointSum = 0; 24 | for (size_t i = 1; i < lines.size(); ++i) { 25 | try { 26 | int points = std::stoi(lines[i]); 27 | pointSum += points; 28 | 29 | if (!highScore || highScore < points) { 30 | highScore = points; 31 | this->gameuser = gameuser; 32 | } 33 | } 34 | catch (const std::exception& e) { 35 | continue; 36 | } 37 | } 38 | 39 | if (!highScoreSum || highScoreSum < pointSum) { 40 | highScoreSum = pointSum; 41 | } 42 | 43 | gameuser->setTotal(pointSum); 44 | this->vectorGameUsers.push_back(gameuser); 45 | } 46 | 47 | GameUser* GameStats::getGameUser(std::string name) 48 | { 49 | for (GameUser* user : vectorGameUsers) { 50 | if (user->getName() == name) { 51 | return user; 52 | } 53 | } 54 | return nullptr; 55 | } 56 | void GameStats::saveUser(GameUser* gu) 57 | { 58 | if (!gu) { 59 | System::Windows::Forms::MessageBox::Show("Invalid user!", 60 | "Error", 61 | System::Windows::Forms::MessageBoxButtons::OK, 62 | System::Windows::Forms::MessageBoxIcon::Error); 63 | return; 64 | } 65 | 66 | std::ifstream inputFile(filePathNative); 67 | if (!inputFile.is_open()) { 68 | System::Windows::Forms::MessageBox::Show("Could not open file for saving user data!", 69 | "Error", 70 | System::Windows::Forms::MessageBoxButtons::OK, 71 | System::Windows::Forms::MessageBoxIcon::Error); 72 | return; 73 | } 74 | 75 | std::vector lines; 76 | std::string line; 77 | bool updated = false; 78 | 79 | while (std::getline(inputFile, line)) { 80 | std::vector parts; 81 | std::istringstream stream(line); 82 | std::string part; 83 | while (std::getline(stream, part, ';')) { 84 | parts.push_back(part); 85 | } 86 | 87 | if (!parts.empty() && parts[0] == gu->getName()) { 88 | line += ";" + std::to_string(gu->getPoints()); 89 | updated = true; 90 | } 91 | lines.push_back(line); 92 | } 93 | 94 | inputFile.close(); 95 | 96 | if (!updated) { 97 | lines.push_back(gu->getName() + ";" + std::to_string(gu->getPoints())); 98 | } 99 | 100 | gu->setTotal(gu->getTotalPoints()); 101 | gu->setFromBase(true); 102 | 103 | std::ofstream outputFile(filePathNative); 104 | if (!outputFile.is_open()) { 105 | System::Windows::Forms::MessageBox::Show("Could not write to file!", 106 | "Error", 107 | System::Windows::Forms::MessageBoxButtons::OK, 108 | System::Windows::Forms::MessageBoxIcon::Error); 109 | return; 110 | } 111 | 112 | for (const auto& updatedLine : lines) { 113 | outputFile << updatedLine << std::endl; 114 | } 115 | 116 | outputFile.close(); 117 | System::Windows::Forms::MessageBox::Show("User data saved successfully!", 118 | "Info", 119 | System::Windows::Forms::MessageBoxButtons::OK, 120 | System::Windows::Forms::MessageBoxIcon::Information); 121 | } 122 | bool GameStats::openDialogFile() { 123 | System::Windows::Forms::OpenFileDialog^ openFileDialog = gcnew System::Windows::Forms::OpenFileDialog(); 124 | openFileDialog->Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; 125 | openFileDialog->Title = "Select a Statistics File"; 126 | 127 | if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) { 128 | filePathNative = msclr::interop::marshal_as(openFileDialog->FileName); 129 | 130 | std::ifstream inputFile(filePathNative); 131 | if (!inputFile.is_open()) { 132 | System::Windows::Forms::MessageBox::Show("Failed to load the file!", 133 | "Error", 134 | System::Windows::Forms::MessageBoxButtons::OK, 135 | System::Windows::Forms::MessageBoxIcon::Error); 136 | return false; 137 | } 138 | 139 | std::string line; 140 | while (std::getline(inputFile, line)) { 141 | loadUser(line); 142 | } 143 | 144 | inputFile.close(); 145 | 146 | System::Windows::Forms::MessageBox::Show("Statistics successfully loaded!", 147 | "Info", 148 | System::Windows::Forms::MessageBoxButtons::OK, 149 | System::Windows::Forms::MessageBoxIcon::Information); 150 | 151 | return true; 152 | } 153 | 154 | System::Windows::Forms::MessageBox::Show("No file selected!", 155 | "Info", 156 | System::Windows::Forms::MessageBoxButtons::OK, 157 | System::Windows::Forms::MessageBoxIcon::Information); 158 | return false; 159 | } 160 | GameUser* GameStats::getHighScoreUser() { 161 | return this->gameuser; 162 | } 163 | int GameStats::getHighScore() 164 | { 165 | return this->highScore; 166 | } 167 | int GameStats::getHighScoreSum() 168 | { 169 | return this->highScoreSum; 170 | } 171 | GameStats::~GameStats() 172 | { 173 | for (auto user : vectorGameUsers) { 174 | delete user; 175 | } 176 | vectorGameUsers.clear(); 177 | } 178 | 179 | } -------------------------------------------------------------------------------- /GameStats.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "GameUser.h" 4 | #include 5 | namespace szablon { 6 | class GameStats { 7 | public: 8 | GameStats(); 9 | GameUser* getGameUser(std::string name); 10 | GameUser* getHighScoreUser(); 11 | 12 | bool openDialogFile(); 13 | void loadUser(std::string value); 14 | void saveUser(GameUser* gameuser); 15 | void setGameUser(GameUser* gameuser); 16 | 17 | int getHighScore(); 18 | int getHighScoreSum(); 19 | private: 20 | GameUser* gameuser; 21 | 22 | int highScore; 23 | int highScoreSum; 24 | std::string filePathNative; 25 | std::vector vectorGameUsers; 26 | protected: 27 | ~GameStats(); 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /GameUser.cpp: -------------------------------------------------------------------------------- 1 | #include "GameUser.h" 2 | GameUser::GameUser(std::string name, int points, int total, std::string difficulty, bool base) : 3 | name(name), points(points), total(total), difficulty(difficulty), fromBase(base) {} 4 | std::string GameUser::getName() 5 | { 6 | return this->name; 7 | } 8 | int GameUser::getPoints() 9 | { 10 | return this->points; 11 | } 12 | std::string GameUser::getDifficulty() 13 | { 14 | return this->difficulty; 15 | } 16 | 17 | void GameUser::addPoints(int points) 18 | { 19 | this->points += points; 20 | } 21 | 22 | void GameUser::removePoints(int points) 23 | { 24 | this->points -= points; 25 | } 26 | 27 | void GameUser::setPoints(int points) 28 | { 29 | this->points = points; 30 | } 31 | void GameUser::setDifficulty(std::string difficulty) { 32 | this->difficulty = difficulty; 33 | } 34 | bool GameUser::getFromBase() { 35 | return this->fromBase; 36 | } 37 | void GameUser::setFromBase(bool base) { 38 | this->fromBase = base; 39 | } 40 | int GameUser::getTotalPoints() { 41 | return this->total + this->points; 42 | } 43 | int GameUser::getTotal() { 44 | return this->total; 45 | } 46 | void GameUser::setTotal(int total) { 47 | this->total = total; 48 | } 49 | -------------------------------------------------------------------------------- /GameUser.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEUSER_H 2 | #define GAMEUSER_H 3 | 4 | #include 5 | 6 | class GameUser { 7 | private: 8 | std::string name; 9 | int points; 10 | int total; 11 | std::string difficulty; 12 | bool fromBase; 13 | public: 14 | GameUser(std::string name, int points, int total, std::string difficulty, bool base); 15 | 16 | std::string getName(); 17 | int getPoints(); 18 | std::string getDifficulty(); 19 | bool getFromBase(); 20 | 21 | int getTotalPoints(); 22 | int getTotal(); 23 | 24 | void addPoints(int points); 25 | void removePoints(int points); 26 | void setPoints(int points); 27 | void setDifficulty(std::string difficulty); 28 | void setFromBase(bool base); 29 | void setTotal(int points); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /MainForm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/MainForm.cpp -------------------------------------------------------------------------------- /MainForm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "GameStats.h" 4 | namespace szablon { 5 | using namespace System; 6 | using namespace System::ComponentModel; 7 | using namespace System::Collections; 8 | using namespace System::Windows::Forms; 9 | using namespace System::Data; 10 | using namespace System::Drawing; 11 | public ref class MainForm : public System::Windows::Forms::Form { 12 | public: 13 | MainForm(void); 14 | void setReadyToPlay(bool value); 15 | bool getReadyToPlay(); 16 | 17 | void setGameStats(GameStats* gamestats); 18 | GameStats* getGameStats(); 19 | private: 20 | GameStats* gameStats; 21 | System::Windows::Forms::Form^ gameform; 22 | 23 | bool readyToPlay; 24 | 25 | void statsToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e); 26 | void difficultyBar_Scroll(System::Object^ sender, System::EventArgs^ e); 27 | void start_button_Click(System::Object^ sender, System::EventArgs^ e); 28 | void clearToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e); 29 | void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e); 30 | void aboutToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e); 31 | protected: 32 | ~MainForm() { 33 | if (components) { 34 | delete components; 35 | } 36 | if (gameform) { 37 | delete gameform; 38 | } 39 | } 40 | private: System::Windows::Forms::MenuStrip^ menuStrip1; 41 | protected: 42 | private: System::Windows::Forms::ToolStripMenuItem^ statsToolStripMenuItem; 43 | private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem; 44 | private: System::Windows::Forms::ToolStripMenuItem^ clearToolStripMenuItem; 45 | private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem; 46 | private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem; 47 | private: System::Windows::Forms::PictureBox^ pictureBox1; 48 | private: System::Windows::Forms::GroupBox^ groupBox1; 49 | private: System::Windows::Forms::TextBox^ textBox1; 50 | private: System::Windows::Forms::GroupBox^ groupBox2; 51 | private: System::Windows::Forms::TrackBar^ trackBar1; 52 | private: System::Windows::Forms::Button^ button1; 53 | 54 | 55 | protected: 56 | private: 57 | System::ComponentModel::Container^ components; 58 | #pragma region Windows Form Designer generated code 59 | void InitializeComponent(void) 60 | { 61 | System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid)); 62 | this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip()); 63 | this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 64 | this->clearToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 65 | this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 66 | this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 67 | this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); 68 | this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); 69 | this->textBox1 = (gcnew System::Windows::Forms::TextBox()); 70 | this->groupBox2 = (gcnew System::Windows::Forms::GroupBox()); 71 | this->trackBar1 = (gcnew System::Windows::Forms::TrackBar()); 72 | this->button1 = (gcnew System::Windows::Forms::Button()); 73 | this->statsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 74 | this->menuStrip1->SuspendLayout(); 75 | (cli::safe_cast(this->pictureBox1))->BeginInit(); 76 | this->groupBox1->SuspendLayout(); 77 | this->groupBox2->SuspendLayout(); 78 | (cli::safe_cast(this->trackBar1))->BeginInit(); 79 | this->SuspendLayout(); 80 | // 81 | // menuStrip1 82 | // 83 | this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) { 84 | this->fileToolStripMenuItem, 85 | this->aboutToolStripMenuItem, this->statsToolStripMenuItem 86 | }); 87 | this->menuStrip1->Location = System::Drawing::Point(0, 0); 88 | this->menuStrip1->Name = L"menuStrip1"; 89 | this->menuStrip1->Size = System::Drawing::Size(444, 24); 90 | this->menuStrip1->TabIndex = 0; 91 | this->menuStrip1->Text = L"menuStrip1"; 92 | // 93 | // fileToolStripMenuItem 94 | // 95 | this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) { 96 | this->clearToolStripMenuItem, 97 | this->exitToolStripMenuItem 98 | }); 99 | this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem"; 100 | this->fileToolStripMenuItem->Size = System::Drawing::Size(44, 20); 101 | this->fileToolStripMenuItem->Text = L"Help"; 102 | // 103 | // clearToolStripMenuItem 104 | // 105 | this->clearToolStripMenuItem->Name = L"clearToolStripMenuItem"; 106 | this->clearToolStripMenuItem->Size = System::Drawing::Size(101, 22); 107 | this->clearToolStripMenuItem->Text = L"Clear"; 108 | this->clearToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::clearToolStripMenuItem_Click); 109 | // 110 | // exitToolStripMenuItem 111 | // 112 | this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem"; 113 | this->exitToolStripMenuItem->Size = System::Drawing::Size(101, 22); 114 | this->exitToolStripMenuItem->Text = L"Exit"; 115 | this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::exitToolStripMenuItem_Click); 116 | // 117 | // aboutToolStripMenuItem 118 | // 119 | this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem"; 120 | this->aboutToolStripMenuItem->Size = System::Drawing::Size(52, 20); 121 | this->aboutToolStripMenuItem->Text = L"About"; 122 | this->aboutToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::aboutToolStripMenuItem_Click); 123 | // 124 | // pictureBox1 125 | // 126 | this->pictureBox1->BackColor = System::Drawing::Color::Transparent; 127 | this->pictureBox1->Image = (cli::safe_cast(resources->GetObject(L"pictureBox1.Image"))); 128 | this->pictureBox1->Location = System::Drawing::Point(136, 49); 129 | this->pictureBox1->Name = L"pictureBox1"; 130 | this->pictureBox1->Size = System::Drawing::Size(172, 152); 131 | this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom; 132 | this->pictureBox1->TabIndex = 1; 133 | this->pictureBox1->TabStop = false; 134 | // 135 | // groupBox1 136 | // 137 | this->groupBox1->Controls->Add(this->textBox1); 138 | this->groupBox1->Font = (gcnew System::Drawing::Font(L"Oswald", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 139 | static_cast(238))); 140 | this->groupBox1->ForeColor = System::Drawing::Color::White; 141 | this->groupBox1->Location = System::Drawing::Point(54, 218); 142 | this->groupBox1->Name = L"groupBox1"; 143 | this->groupBox1->Size = System::Drawing::Size(335, 100); 144 | this->groupBox1->TabIndex = 4; 145 | this->groupBox1->TabStop = false; 146 | this->groupBox1->Text = L"Username:"; 147 | // 148 | // textBox1 149 | // 150 | this->textBox1->Location = System::Drawing::Point(6, 42); 151 | this->textBox1->Name = L"textBox1"; 152 | this->textBox1->Size = System::Drawing::Size(323, 43); 153 | this->textBox1->TabIndex = 0; 154 | this->textBox1->Text = L"Patryk Pszeniczny"; 155 | // 156 | // groupBox2 157 | // 158 | this->groupBox2->Controls->Add(this->trackBar1); 159 | this->groupBox2->Font = (gcnew System::Drawing::Font(L"Oswald", 18, System::Drawing::FontStyle::Bold)); 160 | this->groupBox2->ForeColor = System::Drawing::SystemColors::Window; 161 | this->groupBox2->Location = System::Drawing::Point(54, 324); 162 | this->groupBox2->Name = L"groupBox2"; 163 | this->groupBox2->Size = System::Drawing::Size(335, 111); 164 | this->groupBox2->TabIndex = 10; 165 | this->groupBox2->TabStop = false; 166 | this->groupBox2->Text = L"Peaceful"; 167 | // 168 | // trackBar1 169 | // 170 | this->trackBar1->BackColor = System::Drawing::Color::DimGray; 171 | this->trackBar1->Cursor = System::Windows::Forms::Cursors::Hand; 172 | this->trackBar1->LargeChange = 10; 173 | this->trackBar1->Location = System::Drawing::Point(6, 52); 174 | this->trackBar1->Maximum = 80; 175 | this->trackBar1->Minimum = 1; 176 | this->trackBar1->Name = L"trackBar1"; 177 | this->trackBar1->Size = System::Drawing::Size(307, 45); 178 | this->trackBar1->SmallChange = 10; 179 | this->trackBar1->TabIndex = 10; 180 | this->trackBar1->TickFrequency = 5; 181 | this->trackBar1->TickStyle = System::Windows::Forms::TickStyle::Both; 182 | this->trackBar1->Value = 1; 183 | this->trackBar1->Scroll += gcnew System::EventHandler(this, &MainForm::difficultyBar_Scroll); 184 | // 185 | // button1 186 | // 187 | this->button1->BackColor = System::Drawing::Color::FromArgb(static_cast(static_cast(20)), static_cast(static_cast(170)), 188 | static_cast(static_cast(20))); 189 | this->button1->FlatStyle = System::Windows::Forms::FlatStyle::System; 190 | this->button1->Font = (gcnew System::Drawing::Font(L"Oswald", 24, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 191 | static_cast(238))); 192 | this->button1->ForeColor = System::Drawing::Color::White; 193 | this->button1->Location = System::Drawing::Point(54, 456); 194 | this->button1->Name = L"button1"; 195 | this->button1->Size = System::Drawing::Size(335, 61); 196 | this->button1->TabIndex = 11; 197 | this->button1->Text = L"ROZPOCZNIJ GRE"; 198 | this->button1->UseVisualStyleBackColor = false; 199 | this->button1->Click += gcnew System::EventHandler(this, &MainForm::start_button_Click); 200 | // 201 | // statsToolStripMenuItem 202 | // 203 | this->statsToolStripMenuItem->Name = L"statsToolStripMenuItem"; 204 | this->statsToolStripMenuItem->Size = System::Drawing::Size(43, 20); 205 | this->statsToolStripMenuItem->Text = L"stats"; 206 | this->statsToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::statsToolStripMenuItem_Click); 207 | // 208 | // MainForm 209 | // 210 | this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 211 | this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 212 | this->BackColor = System::Drawing::Color::Teal; 213 | this->BackgroundImage = (cli::safe_cast(resources->GetObject(L"$this.BackgroundImage"))); 214 | this->ClientSize = System::Drawing::Size(444, 542); 215 | this->Controls->Add(this->button1); 216 | this->Controls->Add(this->groupBox2); 217 | this->Controls->Add(this->groupBox1); 218 | this->Controls->Add(this->pictureBox1); 219 | this->Controls->Add(this->menuStrip1); 220 | this->DoubleBuffered = true; 221 | this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; 222 | this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); 223 | this->MainMenuStrip = this->menuStrip1; 224 | this->Margin = System::Windows::Forms::Padding(2); 225 | this->Name = L"MainForm"; 226 | this->Text = L"Sudoku - Patryk Pszeniczny :: v1.0"; 227 | this->menuStrip1->ResumeLayout(false); 228 | this->menuStrip1->PerformLayout(); 229 | (cli::safe_cast(this->pictureBox1))->EndInit(); 230 | this->groupBox1->ResumeLayout(false); 231 | this->groupBox1->PerformLayout(); 232 | this->groupBox2->ResumeLayout(false); 233 | this->groupBox2->PerformLayout(); 234 | (cli::safe_cast(this->trackBar1))->EndInit(); 235 | this->ResumeLayout(false); 236 | this->PerformLayout(); 237 | 238 | } 239 | #pragma endregion 240 | }; 241 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 5 | Logo 6 | 7 | 8 |

🎉 Welcome to the Most Legendary Sudoku Project Ever! 🎉

9 | 10 |

11 | 🖥️ A small yet mighty project built for *serious academic purposes* 🧐
12 | (Okay, it was for university, but still!) 🧩
13 | Made with **C++ CLI** and a whole lotta coffee ☕.
14 |
15 | 🚀 View Demo 16 | · 17 | 🐛 Report Bugs We Missed (Oops) 18 | · 19 | 🌟 Request Useless Features 20 |

21 |
22 | 23 | --- 24 | 25 | ## About The Project 💡 26 | ### "The best way to learn is to suffer through coding assignments!" – Every Professor Ever 27 | 28 | This project was developed for the **Zastosowanie Programowania Obiektowego (ZPO)** course. 🏫 It’s a simple Sudoku app made in **C++ CLI**. Let’s be real: it’s not gonna win any awards, but hey, it works! 🎉 29 | 30 | --- 31 | 32 | ### Features You Didn’t Ask For 🤷‍♂️ 33 | - **3 Amazing Windows** (Yes, THREE!): 34 | - 🎮 **Game Panel View**: Where you flex your Sudoku-solving skills. 35 | - 🔒 **Login View**: Totally unnecessary, but professors love login screens. 36 | - ℹ️ **About View**: Tells you how awesome this app is. 37 | 38 | - **User-Friendly**: By "user-friendly," we mean it won't crash (probably). 💥 39 | - **C++ CLI**: Because who doesn’t love mixing C++ and .NET? 🧙‍♂️ 40 | 41 | > **Why is it so simple?** 42 | > Because complicated stuff is for people with free time. We had deadlines. 😅 43 | 44 | --- 45 | 46 | ## Screenshots 📸 (Because What’s a README Without Them?) 47 | 48 | #### Game Panel View 49 | ![sudoku-game] 50 | *👀 Ooooooh, fancy game interface!* 51 | 52 | #### Game Login View 53 | ![sudoku-login] 54 | *🔐 "Let me in!" – Every user ever.* 55 | 56 | #### Game About Info 57 | ![sudoku-about] 58 | *ℹ️ This window exists because… reasons.* 59 | 60 | --- 61 | 62 | ## Why This README? ✍️ 63 | Because life is short, and boring READMEs suck. 🤷‍♂️ Here’s why this one’s cool: 64 | - **Entertaining**: Admit it, you smiled at least once. 😏 65 | - **Straight to the Point**: Ain’t nobody got time for fluff. 66 | - **Memorable**: You’ll remember this README longer than your professor will remember your grade. 67 | 68 | --- 69 | 70 | ## Behind the Code 🧑‍💻 71 | This app is a testament to: 72 | - **Teamwork** (aka trying to merge everyone’s spaghetti code). 73 | - **The Magic of Copy-Paste**: "If Stack Overflow approves, so do we!" 74 | - **SOLID Principles**: Because "Solidne Oprogramowanie" is a vibe. 💪 75 | 76 | --- 77 | 78 |

✨ Now go fork this project and make it even more legendary! ✨

79 | 80 |

(⬆️ Back to top)

81 | 82 | --- 83 | 84 | [sudoku-login]: https://i.imgur.com/JW3qW4t.png 85 | [sudoku-game]: https://i.imgur.com/4jRAB60.png 86 | [sudoku-about]: https://i.imgur.com/MfnpeMh.png 87 | -------------------------------------------------------------------------------- /aboutIMG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/aboutIMG.png -------------------------------------------------------------------------------- /background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/background.png -------------------------------------------------------------------------------- /cpp.hint: -------------------------------------------------------------------------------- 1 | // Pliki wskazówek ułatwiają interpretowanie identyfikatorów programu Visual C++ w środowisku Visual Studio IDE 2 | // takich jak nazwy funkcji i makr. 3 | // Aby uzyskać więcej informacji, zobacz https://go.microsoft.com/fwlink/?linkid=865984 4 | #define _NODISCARD_FRIEND 5 | // Pliki wskazówek ułatwiają interpretowanie identyfikatorów programu Visual C++ w środowisku Visual Studio IDE 6 | // takich jak nazwy funkcji i makr. 7 | // Aby uzyskać więcej informacji, zobacz https://go.microsoft.com/fwlink/?linkid=865984 8 | #define _NODISCARD_FRIEND 9 | -------------------------------------------------------------------------------- /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/icon.ico -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/logo.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainForm.h" 2 | using namespace szablon; 3 | [STAThreadAttribute] 4 | 5 | int main(array^ args) 6 | { 7 | Application::EnableVisualStyles(); 8 | Application::SetCompatibleTextRenderingDefault(false); 9 | Application::Run(gcnew MainForm()); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/resource.h -------------------------------------------------------------------------------- /szablon.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patryk-pszeniczny/sudoku-cpp/f037c340738bc7187b7517c2468385ffe2b81378/szablon.rc -------------------------------------------------------------------------------- /szablon.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34031.279 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "szablon", "szablon.vcxproj", "{CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Debug|x64.ActiveCfg = Debug|x64 17 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Debug|x64.Build.0 = Debug|x64 18 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Debug|x86.ActiveCfg = Debug|Win32 19 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Debug|x86.Build.0 = Debug|Win32 20 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Release|x64.ActiveCfg = Release|x64 21 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Release|x64.Build.0 = Release|x64 22 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Release|x86.ActiveCfg = Release|Win32 23 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DC3D0D87-2AD0-4773-A7A2-DEDE0C1D44E5} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /szablon.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | {CEEDA680-ADB7-4048-B85A-2C3C4D69AB0F} 24 | true 25 | v4.8 26 | ManagedCProj 27 | szablon 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v143 35 | true 36 | Unicode 37 | 38 | 39 | Application 40 | false 41 | v143 42 | true 43 | Unicode 44 | 45 | 46 | Application 47 | true 48 | v143 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v143 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Level3 81 | _DEBUG;%(PreprocessorDefinitions) 82 | 83 | 84 | 85 | Windows 86 | main 87 | 88 | 89 | 90 | 91 | Level3 92 | WIN32;_DEBUG;%(PreprocessorDefinitions) 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | Level3 101 | WIN32;NDEBUG;%(PreprocessorDefinitions) 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | Level3 110 | NDEBUG;%(PreprocessorDefinitions) 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | CppForm 135 | 136 | 137 | CppForm 138 | 139 | 140 | 141 | 142 | 143 | CppForm 144 | 145 | 146 | 147 | 148 | 149 | AboutForm.h 150 | 151 | 152 | GameForm.h 153 | 154 | 155 | MainForm.h 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /szablon.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Pliki źródłowe 20 | 21 | 22 | Pliki źródłowe 23 | 24 | 25 | Pliki źródłowe 26 | 27 | 28 | Pliki źródłowe 29 | 30 | 31 | Pliki źródłowe 32 | 33 | 34 | Pliki źródłowe 35 | 36 | 37 | Pliki źródłowe 38 | 39 | 40 | 41 | 42 | Pliki nagłówkowe 43 | 44 | 45 | Pliki nagłówkowe 46 | 47 | 48 | Pliki nagłówkowe 49 | 50 | 51 | Pliki nagłówkowe 52 | 53 | 54 | Pliki nagłówkowe 55 | 56 | 57 | Pliki nagłówkowe 58 | 59 | 60 | Pliki nagłówkowe 61 | 62 | 63 | 64 | 65 | Pliki zasobów 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Pliki zasobów 74 | 75 | 76 | --------------------------------------------------------------------------------