├── 2048 ├── 2048.vcxproj ├── 2048.vcxproj.filters ├── 2048.vcxproj.user ├── controller.cpp ├── controller.h ├── main.cpp ├── map.cpp └── map.h ├── .gitignore ├── EasyxProject.sln ├── Easyx_Maye ├── Easyx_Maye.vcxproj ├── Easyx_Maye.vcxproj.filters ├── Easyx_Maye.vcxproj.user ├── images │ ├── human (9).jpg │ ├── img1.png │ ├── planeNormal_1.jpg │ └── planeNormal_2.jpg ├── include │ ├── BasicWidget.h │ ├── Configure.h │ ├── Image.h │ ├── LineEdit.h │ ├── Table.h │ ├── Timer.h │ ├── Window.h │ ├── commonutils │ │ ├── Color.h │ │ ├── Font.h │ │ ├── Painter.h │ │ └── TypeDefine.h │ ├── pushButton.h │ └── randomGenerator.h ├── lib │ ├── x64 │ │ ├── Easyx_Maye.idb │ │ └── Easyx_Maye.lib │ └── x86 │ │ ├── Easyx_Maye.idb │ │ └── Easyx_Maye.lib ├── main.cpp └── source │ ├── BasicWidget.cpp │ ├── Image.cpp │ ├── LineEdit.cpp │ ├── Table.cpp │ ├── Timer.cpp │ ├── Window.cpp │ ├── commonutils │ ├── Color.cpp │ ├── Font.cpp │ └── Painter.cpp │ ├── pushButton.cpp │ └── randomGenerator.cpp ├── README.md ├── StudentManagementSystem_CPP ├── ManageMent(控制台版).cpp ├── ManageMent(控制台版).h ├── ManageMent_gui.cpp ├── ManageMent_gui.h ├── Student.cpp ├── Student.h ├── StudentManagementSystem_CPP.vcxproj ├── StudentManagementSystem_CPP.vcxproj.user ├── images │ ├── bk.png │ └── student.txt ├── main.cpp └── resource │ ├── student - 备份.txt │ └── student.txt ├── StudentManagementSystem_all.7z ├── StudentManagementSystem_all ├── ManageMent(控制台版).cpp ├── ManageMent(控制台版).h ├── ManageMent_gui.cpp ├── ManageMent_gui.h ├── Student.cpp ├── Student.h ├── StudentManagementSystem_all.sln ├── StudentManagementSystem_all.vcxproj ├── StudentManagementSystem_all.vcxproj.filters ├── StudentManagementSystem_all.vcxproj.user ├── images │ ├── bk.png │ └── student.txt ├── main.cpp ├── resource │ ├── student - 备份.txt │ └── student.txt └── widgets │ ├── BasicWidget.cpp │ ├── BasicWidget.h │ ├── Configure.h │ ├── Image.cpp │ ├── Image.h │ ├── LineEdit.cpp │ ├── LineEdit.h │ ├── Table.cpp │ ├── Table.h │ ├── Timer.cpp │ ├── Timer.h │ ├── Window.cpp │ ├── Window.h │ ├── commonutils │ ├── Color.cpp │ ├── Color.h │ ├── Font.cpp │ ├── Font.h │ └── TypeDefine.h │ ├── pushButton.cpp │ ├── pushButton.h │ ├── randomGenerator.cpp │ └── randomGenerator.h ├── gobang ├── checkerBoard.cpp ├── checkerBoard.h ├── chessPieces.cpp ├── chessPieces.h ├── controller.cpp ├── controller.h ├── gobang.vcxproj ├── gobang.vcxproj.filters ├── gobang.vcxproj.user ├── main.cpp └── resource │ ├── images │ └── bk.jpg │ └── music │ └── G弦之歌.mp3 ├── mineSweeper ├── controller.cpp ├── controller.h ├── main.cpp ├── map.cpp ├── map.h ├── mineSweeper.vcxproj ├── mineSweeper.vcxproj.filters ├── mineSweeper.vcxproj.user └── resource │ ├── images │ ├── 0.jpg │ ├── 1.jpg │ ├── 10.jpg │ ├── 11.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ ├── 8.jpg │ ├── 9.jpg │ └── 9_copy.jpg │ └── music │ ├── click.wav │ ├── rightClick.wav │ ├── search.wav │ └── start.mp3 └── pushBox ├── README.md ├── controller.cpp ├── controller.h ├── gamer.cpp ├── gamer.h ├── main.cpp ├── map.h ├── pushBox.vcxproj ├── pushBox.vcxproj.filters ├── pushBox.vcxproj.user ├── resource ├── images │ ├── 0.bmp │ ├── 1.bmp │ ├── 2.bmp │ ├── 3.bmp │ ├── 4.bmp │ ├── 5.bmp │ └── 6.bmp └── map.txt ├── rollback.cpp └── rollback.h /.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 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ -------------------------------------------------------------------------------- /2048/2048.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 | 16.0 23 | Win32Proj 24 | {96043313-d9dd-4a6d-9998-26fe1a432a90} 25 | My2048 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ..\Easyx_Maye\include;$(IncludePath) 76 | ..\Easyx_Maye\lib\x86\;$(LibraryPath) 77 | 78 | 79 | false 80 | 81 | 82 | true 83 | 84 | 85 | false 86 | 87 | 88 | 89 | Level3 90 | true 91 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | true 93 | 94 | 95 | Console 96 | true 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | true 104 | true 105 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | 108 | 109 | Console 110 | true 111 | true 112 | true 113 | 114 | 115 | 116 | 117 | Level3 118 | true 119 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | true 121 | 122 | 123 | Console 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | true 131 | true 132 | true 133 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | true 135 | 136 | 137 | Console 138 | true 139 | true 140 | true 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /2048/2048.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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 头文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /2048/2048.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /2048/controller.cpp: -------------------------------------------------------------------------------- 1 | #include "controller.h" 2 | #include 3 | 4 | 5 | Controller::Controller() 6 | :flag(false) 7 | { 8 | 9 | } 10 | void Controller::run() 11 | { 12 | while (true) 13 | { 14 | map.show(); 15 | GameControl(); 16 | GameWin(); 17 | } 18 | } 19 | 20 | //向上移动 21 | void Controller::moveup() 22 | { 23 | /* 24 | 向上移动:遍历每列 25 | */ 26 | for (int i = 0; i < map.cols(); i++) 27 | { 28 | int temp = 0; 29 | for (int begin = 1; begin < map.rows(); begin++) 30 | { 31 | if (map[begin][i] != 0) 32 | { 33 | if (map[temp][i] == 0) 34 | { 35 | map[temp][i] = map[begin][i]; 36 | map[begin][i] = 0; 37 | } 38 | else if (map[temp][i] == map[begin][i]) 39 | { 40 | map[temp][i] += map[begin][i]; 41 | map[begin][i] = 0; 42 | temp++; 43 | } 44 | else 45 | { 46 | map[temp + 1][i] = map[begin][i]; 47 | if (temp + 1 != begin)//如果temp+1和begn不在同一个位置,就让begin所在的位置的数字置空 48 | { 49 | map[begin][i] = 0; 50 | } 51 | temp++; 52 | } 53 | flag = 1; 54 | } 55 | } 56 | } 57 | } 58 | //向下移动 59 | void Controller::movedown() 60 | { 61 | for (int i = 0; i < map.cols(); i++) 62 | { 63 | int temp = map.rows() - 1; 64 | for (int begin = map.rows() - 2; begin >= 0; begin--) 65 | { 66 | if (map[begin][i] != 0) 67 | { 68 | if (map[temp][i] == 0) 69 | { 70 | map[temp][i] = map[begin][i]; 71 | map[begin][i] = 0; 72 | } 73 | else if (map[temp][i] == map[begin][i]) 74 | { 75 | map[temp][i] += map[begin][i]; 76 | map[begin][i] = 0; 77 | temp--; 78 | } 79 | else 80 | { 81 | map[temp - 1][i] = map[begin][i]; 82 | if ((temp - 1) != begin) 83 | { 84 | map[begin][i] = 0; 85 | } 86 | temp--; 87 | } 88 | flag = 1; 89 | } 90 | } 91 | } 92 | } 93 | //向左移动 94 | void Controller::moveleft() 95 | { 96 | for (int i = 0; i < map.rows(); i++) 97 | { 98 | int temp = 0; 99 | for (int begin = 1; begin < map.cols(); begin++) 100 | { 101 | if (map[i][begin] != 0) 102 | { 103 | if (map[i][temp] == 0) 104 | { 105 | map[i][temp] = map[i][begin]; 106 | map[i][begin] = 0;; 107 | } 108 | else if (map[i][temp] == map[i][begin]) 109 | { 110 | map[i][temp] += map[i][begin]; 111 | map[i][begin] = 0; 112 | temp++; 113 | } 114 | else 115 | { 116 | map[i][temp + 1] = map[i][begin]; 117 | if (temp + 1 != begin) 118 | { 119 | map[i][begin] = 0; 120 | } 121 | temp++; 122 | } 123 | flag = 1; 124 | } 125 | } 126 | } 127 | } 128 | //向右移动 129 | void Controller::moveright() 130 | { 131 | for (int i = 0; i < map.rows(); i++) 132 | { 133 | int temp = map.cols() - 1; 134 | for (int begin = map.cols() - 2; begin >= 0; begin--) 135 | { 136 | if (map[i][begin] != 0) 137 | { 138 | if (map[i][temp] == 0) 139 | { 140 | map[i][temp] = map[i][begin]; 141 | map[i][begin] = 0; 142 | } 143 | else if (map[i][temp] == map[i][begin]) 144 | { 145 | map[i][temp] += map[i][begin]; 146 | map[i][begin] = 0; 147 | temp--; 148 | } 149 | else 150 | { 151 | map[i][temp - 1] = map[i][begin]; 152 | if (temp - 1 != begin) 153 | { 154 | map[i][begin] = 0; 155 | } 156 | temp--; 157 | } 158 | flag = 1; 159 | } 160 | } 161 | } 162 | } 163 | void Controller::GameControl() 164 | { 165 | switch (_getch()) 166 | { 167 | case 72: 168 | case 'w': 169 | case 'W': 170 | moveup(); 171 | break; 172 | case 80: 173 | case 's': 174 | case 'S': 175 | movedown(); 176 | break; 177 | case 75: 178 | case 'a': 179 | case 'A': 180 | moveleft(); 181 | break; 182 | case 77: 183 | case 'd': 184 | case 'D': 185 | moveright(); 186 | break; 187 | default: 188 | break; 189 | } 190 | if (flag == 1) 191 | { 192 | map.generateNumber(); 193 | flag = 0; 194 | } 195 | //userkey = 0; 196 | } 197 | void Controller::GameWin() 198 | { 199 | for (int i = 0; i < map.rows(); i++) 200 | { 201 | for (int k = 0; k < map.cols(); k++) 202 | { 203 | if (map[i][k] == 2048) 204 | { 205 | HWND hnd = GetHWnd(); 206 | int isok = MessageBox(hnd, "你赢了", "提示", MB_OKCANCEL); 207 | if (isok == IDOK) 208 | { 209 | //GameInit(); 210 | } 211 | else 212 | { 213 | exit(666); 214 | } 215 | } 216 | } 217 | } 218 | } -------------------------------------------------------------------------------- /2048/controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"map.h" 3 | class Controller 4 | { 5 | public: 6 | Controller(); 7 | void run(); 8 | void moveup(); 9 | void movedown(); 10 | void moveleft(); 11 | void moveright(); 12 | void GameControl(); 13 | void GameWin(); 14 | private: 15 | Map map; 16 | bool flag; 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /2048/main.cpp: -------------------------------------------------------------------------------- 1 | #include"controller.h" 2 | #include 3 | #pragma comment(lib,"Easyx_Maye.lib") 4 | int main() 5 | { 6 | Window w(475, 475, EW_SHOWCONSOLE); 7 | w.setWindowTitle("2048游戏"); 8 | 9 | Controller c; 10 | c.run(); 11 | 12 | return w.exec(); 13 | } -------------------------------------------------------------------------------- /2048/map.cpp: -------------------------------------------------------------------------------- 1 | #include "map.h" 2 | #include 3 | 4 | Map::Map():m_rows(4),m_cols(4), m_GRIDW(100),m_SPACE(15) 5 | ,m_map(m_rows) 6 | { 7 | for (int i = 0; i < m_rows; i++) 8 | { 9 | for (int k = 0; k < m_cols; k++) 10 | { 11 | m_map[i].push_back(0); 12 | } 13 | } 14 | //开始随机生成两个数 15 | generateNumber(); 16 | generateNumber(); 17 | 18 | //设置背景颜色 19 | setbkcolor(Color::back); 20 | cleardevice(); 21 | } 22 | 23 | 24 | void Map::show() 25 | { 26 | //初始化格子颜色 27 | for (int i = 0; i < m_rows; i++) 28 | { 29 | for (int k = 0; k < m_cols; k++) 30 | { 31 | printf("%d ", m_map[i][k]); 32 | //求出每个格子左上角的坐标 33 | int x = k * m_GRIDW + (k + 1) * m_SPACE; 34 | int y = i * m_GRIDW + (i + 1) * m_SPACE; 35 | int index = (int)log2(m_map[i][k]);//求以2为底的x的对数(求出每个数对应的,颜色的下标) 36 | DWORD tempcolor = colors[index]; 37 | setfillcolor(tempcolor); 38 | setlinecolor(tempcolor); 39 | //fillrectangle(x, y, x + GRID_WIDTH, y + GRID_WIDTH); 40 | fillroundrect(x, y, x + m_GRIDW, y + m_GRIDW, 10, 10); 41 | if (m_map[i][k] != 0)//把当前数字,显示到窗口上 42 | { 43 | setbkmode(TRANSPARENT); 44 | settextstyle(50, 0, "黑体"); 45 | settextcolor(RGB(119, 110, 101)); 46 | char number[5] = " "; 47 | sprintf_s(number, "%d", m_map[i][k]); 48 | int temp = textwidth(number);//获取字符 49 | temp = m_GRIDW / 2 - temp / 2;//计算第一个字开始的位置 50 | outtextxy(x + temp, y + 25, number); 51 | } 52 | } 53 | printf("\n"); 54 | } 55 | } 56 | 57 | int Map::rows() 58 | { 59 | return m_rows; 60 | } 61 | 62 | int Map::cols() 63 | { 64 | return m_cols; 65 | } 66 | 67 | std::vector& Map::operator[](int index) 68 | { 69 | return m_map[index]; 70 | } 71 | 72 | void Map::generateNumber() 73 | { 74 | while (true) 75 | { 76 | int r = RandomGenerator::global()->bounded(m_rows); 77 | int c = RandomGenerator::global()->bounded(m_cols); 78 | if (m_map[r][c] == 0) 79 | { 80 | m_map[r][c] = generate2or4(5); //五分之一的概率生成4 81 | break; 82 | } 83 | } 84 | } 85 | 86 | int Map::generate2or4(int probability) 87 | { 88 | if (RandomGenerator::global()->bounded(probability) == 0) 89 | { 90 | return 4; 91 | } 92 | return 2; 93 | } 94 | -------------------------------------------------------------------------------- /2048/map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | class Map 5 | { 6 | enum Color //枚举格子颜色 7 | { 8 | zero = RGB(205, 193, 180), //0的颜色 9 | twoTo1 = RGB(238, 228, 218), //2的颜色 10 | twoTo2 = RGB(237, 224, 200), //4的颜色 11 | twoTo3 = RGB(242, 177, 121), //8的颜色 12 | twoTo4 = RGB(245, 149, 99), //16的颜色 13 | twoTo5 = RGB(246, 124, 95), //32的颜色 14 | twoTo6 = RGB(246, 94, 59), //64的颜色 15 | twoTo7 = RGB(242, 177, 121), //128的颜色 16 | twoTo8 = RGB(237, 204, 97), //256的颜色 17 | twoTo9 = RGB(255, 0, 128), //512的颜色 18 | twoTo10 = RGB(145, 0, 72), //1024的颜色 19 | twoTo11 = RGB(242, 17, 158), //2048的颜色 20 | back = RGB(187, 173, 160) //背景颜色 21 | }; 22 | Color colors[12] = { zero,twoTo1,twoTo2,twoTo3,twoTo4,twoTo5,twoTo6,twoTo7,twoTo8,twoTo9,twoTo10,twoTo11 }; 23 | public: 24 | Map(); 25 | void show(); 26 | int rows(); 27 | int cols(); 28 | void generateNumber(); 29 | std::vector& operator[](int index); 30 | private: 31 | //随机生成2 或 4 probability生成4的概率 32 | int generate2or4(int probability); 33 | private: 34 | const int m_rows; 35 | const int m_cols; 36 | const int m_GRIDW; 37 | const int m_SPACE; 38 | std::vector> m_map; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /EasyxProject.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31515.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pushBox", "pushBox\pushBox.vcxproj", "{E394C016-8C3C-4D35-A4BC-8FEC4567A239}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easyx_Maye", "Easyx_Maye\Easyx_Maye.vcxproj", "{D688C05B-DB21-4D73-A766-FDC8085B8A1F}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gobang", "gobang\gobang.vcxproj", "{8B7C6AE0-F434-4C35-84CA-F0351E3F375B}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mineSweeper", "mineSweeper\mineSweeper.vcxproj", "{61E2A3E8-C88D-4A30-8C81-30411FB7440E}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2048", "2048\2048.vcxproj", "{96043313-D9DD-4A6D-9998-26FE1A432A90}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StudentManagementSystem", "StudentManagementSystem_CPP\StudentManagementSystem_CPP.vcxproj", "{C2171D33-E8BB-429B-B040-673F15CD181A}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|x64 = Debug|x64 21 | Debug|x86 = Debug|x86 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Debug|x64.ActiveCfg = Debug|x64 27 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Debug|x64.Build.0 = Debug|x64 28 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Debug|x86.ActiveCfg = Debug|Win32 29 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Debug|x86.Build.0 = Debug|Win32 30 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Release|x64.ActiveCfg = Release|x64 31 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Release|x64.Build.0 = Release|x64 32 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Release|x86.ActiveCfg = Release|Win32 33 | {E394C016-8C3C-4D35-A4BC-8FEC4567A239}.Release|x86.Build.0 = Release|Win32 34 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Debug|x64.ActiveCfg = Debug|x64 35 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Debug|x64.Build.0 = Debug|x64 36 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Debug|x86.ActiveCfg = Debug|Win32 37 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Debug|x86.Build.0 = Debug|Win32 38 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Release|x64.ActiveCfg = Release|x64 39 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Release|x64.Build.0 = Release|x64 40 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Release|x86.ActiveCfg = Release|Win32 41 | {D688C05B-DB21-4D73-A766-FDC8085B8A1F}.Release|x86.Build.0 = Release|Win32 42 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Debug|x64.ActiveCfg = Debug|x64 43 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Debug|x64.Build.0 = Debug|x64 44 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Debug|x86.ActiveCfg = Debug|Win32 45 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Debug|x86.Build.0 = Debug|Win32 46 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Release|x64.ActiveCfg = Release|x64 47 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Release|x64.Build.0 = Release|x64 48 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Release|x86.ActiveCfg = Release|Win32 49 | {8B7C6AE0-F434-4C35-84CA-F0351E3F375B}.Release|x86.Build.0 = Release|Win32 50 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Debug|x64.ActiveCfg = Debug|x64 51 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Debug|x64.Build.0 = Debug|x64 52 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Debug|x86.ActiveCfg = Debug|Win32 53 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Debug|x86.Build.0 = Debug|Win32 54 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Release|x64.ActiveCfg = Release|x64 55 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Release|x64.Build.0 = Release|x64 56 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Release|x86.ActiveCfg = Release|Win32 57 | {61E2A3E8-C88D-4A30-8C81-30411FB7440E}.Release|x86.Build.0 = Release|Win32 58 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Debug|x64.ActiveCfg = Debug|x64 59 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Debug|x64.Build.0 = Debug|x64 60 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Debug|x86.ActiveCfg = Debug|Win32 61 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Debug|x86.Build.0 = Debug|Win32 62 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Release|x64.ActiveCfg = Release|x64 63 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Release|x64.Build.0 = Release|x64 64 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Release|x86.ActiveCfg = Release|Win32 65 | {96043313-D9DD-4A6D-9998-26FE1A432A90}.Release|x86.Build.0 = Release|Win32 66 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Debug|x64.ActiveCfg = Debug|x64 67 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Debug|x64.Build.0 = Debug|x64 68 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Debug|x86.ActiveCfg = Debug|Win32 69 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Debug|x86.Build.0 = Debug|Win32 70 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Release|x64.ActiveCfg = Release|x64 71 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Release|x64.Build.0 = Release|x64 72 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Release|x86.ActiveCfg = Release|Win32 73 | {C2171D33-E8BB-429B-B040-673F15CD181A}.Release|x86.Build.0 = Release|Win32 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(ExtensibilityGlobals) = postSolution 79 | SolutionGuid = {18079622-B81E-4E2B-8DEC-15D7C219C378} 80 | EndGlobalSection 81 | EndGlobal 82 | -------------------------------------------------------------------------------- /Easyx_Maye/Easyx_Maye.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 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 16.0 51 | Win32Proj 52 | {d688c05b-db21-4d73-a766-fdc8085b8a1f} 53 | EasyxMaye 54 | 10.0 55 | 56 | 57 | 58 | StaticLibrary 59 | true 60 | v142 61 | Unicode 62 | 63 | 64 | StaticLibrary 65 | false 66 | v142 67 | true 68 | MultiByte 69 | 70 | 71 | StaticLibrary 72 | true 73 | v142 74 | Unicode 75 | 76 | 77 | StaticLibrary 78 | false 79 | v143 80 | true 81 | MultiByte 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | true 103 | $(SolutionDir)Easyx_Maye\lib\x86\ 104 | 105 | 106 | false 107 | $(SolutionDir)Easyx_Maye\lib\x86\ 108 | 109 | 110 | true 111 | $(SolutionDir)\Easyx_Maye\lib\x64\ 112 | 113 | 114 | false 115 | $(SolutionDir)lib\x64 116 | 117 | 118 | 119 | Level3 120 | true 121 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 122 | true 123 | 124 | 125 | Console 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | true 133 | true 134 | false 135 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | stdcpplatest 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | Level3 149 | false 150 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 151 | true 152 | stdcpplatest 153 | 154 | 155 | Console 156 | true 157 | 158 | 159 | 160 | 161 | Level3 162 | true 163 | true 164 | false 165 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 166 | true 167 | stdcpp20 168 | 169 | 170 | Console 171 | true 172 | true 173 | true 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /Easyx_Maye/Easyx_Maye.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 | {6cd784be-ba6e-45fb-aac1-f404c32d8792} 18 | 19 | 20 | {896b99f4-1a82-4097-be7b-7b6294378428} 21 | 22 | 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 头文件 41 | 42 | 43 | 头文件 44 | 45 | 46 | 头文件 47 | 48 | 49 | 头文件\commonutils 50 | 51 | 52 | 头文件\commonutils 53 | 54 | 55 | 头文件\commonutils 56 | 57 | 58 | 头文件\commonutils 59 | 60 | 61 | 头文件 62 | 63 | 64 | 65 | 66 | 源文件 67 | 68 | 69 | 源文件 70 | 71 | 72 | 源文件 73 | 74 | 75 | 源文件 76 | 77 | 78 | 源文件 79 | 80 | 81 | 源文件 82 | 83 | 84 | 源文件 85 | 86 | 87 | 源文件\commonutils 88 | 89 | 90 | 源文件\commonutils 91 | 92 | 93 | 源文件\commonutils 94 | 95 | 96 | 源文件 97 | 98 | 99 | -------------------------------------------------------------------------------- /Easyx_Maye/Easyx_Maye.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Easyx_Maye/images/human (9).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/images/human (9).jpg -------------------------------------------------------------------------------- /Easyx_Maye/images/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/images/img1.png -------------------------------------------------------------------------------- /Easyx_Maye/images/planeNormal_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/images/planeNormal_1.jpg -------------------------------------------------------------------------------- /Easyx_Maye/images/planeNormal_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/images/planeNormal_2.jpg -------------------------------------------------------------------------------- /Easyx_Maye/include/BasicWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | #include"commonutils/Color.h" 4 | class BasicWidget 5 | { 6 | public: 7 | BasicWidget(int x, int y, int w, int h); 8 | int width() const; 9 | int height()const; 10 | void setFixedSize(int w, int h); 11 | 12 | int x()const; 13 | int y()const; 14 | void move(int x, int y); 15 | 16 | //未实现 17 | void setBackgroundColor(const Color& color); 18 | Color BackgroundColor(); 19 | 20 | void setFont(const Font& font); 21 | const Font& font(); 22 | virtual void show(); 23 | protected: 24 | int m_x; 25 | int m_y; 26 | int m_w; 27 | int m_h; 28 | 29 | Color m_bkColor; //背景颜色 30 | Font m_font; //字体 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /Easyx_Maye/include/Configure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #undef UNICODE 5 | #endif // UNICODE 6 | 7 | #ifdef _DEBUG 8 | #include 9 | #define plog printf 10 | #else 11 | #define plog 12 | #endif // DEBUG 13 | 14 | #include 15 | #include 16 | #include"Timer.h" 17 | #include"commonutils/Font.h" 18 | 19 | -------------------------------------------------------------------------------- /Easyx_Maye/include/Image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | class Image :public IMAGE 4 | { 5 | public: 6 | Image(); 7 | Image(const std::string& imgPath,int w = 0,int h =0); 8 | //example: Image("./res/images/jumpMask.jpg","./res/images/jumpSrc.jpg") 9 | Image(const std::string& maskImgPath, const std::string& srcImgPath,int w = 0,int h =0); 10 | //example: Image("./res/images/","jumpMask.jpg","jumpSrc.jpg") 11 | Image(const std::string& prefixPath,const std::string& maskImgPath, const std::string& srcImgPath,int w = 0,int h = 0); 12 | void draw(); 13 | void draw(DWORD maskdwRop, DWORD srcdwRop); 14 | void move(int x, int y); 15 | 16 | void save(const std::string& savePath); 17 | static void save(const std::string& savePath, Image* img); 18 | Image* getimage(int x, int y, int w, int h); 19 | 20 | DWORD* ImageBuffer(); // 获取绘图设备的显存指针 21 | 22 | private: 23 | void SetDefault() override; // 设置为默认状态 24 | static void putimage_alapha(int x, int y, IMAGE* src); 25 | 26 | int x; 27 | int y; 28 | private://使用掩码图透明贴图 29 | Image *pMaskImg; 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /Easyx_Maye/include/LineEdit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"BasicWidget.h" 3 | #include 4 | #pragma comment(lib,"Imm32.lib") 5 | class LineEdit:public BasicWidget 6 | { 7 | public: 8 | LineEdit(int x = 0, int y = 0, int w = 100, int h = 30); 9 | void show(); 10 | 11 | void eventLoop(const ExMessage& msg); 12 | 13 | //弹出数据输入框 14 | void popInputBox(); 15 | void setInputBoxTitle(const std::string& title); 16 | std::string text(); 17 | void clear(); 18 | //文本是否改变了 19 | bool textChanged(); 20 | private: 21 | std::string m_pretext; //上一次的文字 22 | std::string m_text; //行编辑器中的文字 23 | int textw; 24 | 25 | std::string m_title; //行编辑器弹出窗标题 26 | 27 | bool m_isPopUp; //是否弹出 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /Easyx_Maye/include/Table.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"BasicWidget.h" 3 | #include"pushButton.h" 4 | #include 5 | class Table :public BasicWidget 6 | { 7 | public: 8 | Table(int row = 1, int col = 0); 9 | void setRowCount(int row); 10 | void setColCount(int col); 11 | 12 | //插入以\t分隔的字符串数据 13 | void setHeader(const std::string& data); 14 | void insert(const std::string& data); 15 | void clear(); 16 | 17 | void eventLoop(const ExMessage& msg); 18 | 19 | 20 | void show(); 21 | std::vector split(std::string str, char separator = '\t'); 22 | private: 23 | void drawTableGrid(); 24 | void drawTableText(); 25 | void drawHeader(); 26 | void updateData(); //更新数据 27 | 28 | //初始化换页按钮位置 29 | void initPageBtnPos(); 30 | 31 | private: 32 | size_t m_rows; 33 | size_t m_cols; 34 | 35 | int m_gridw; 36 | int m_gridh; 37 | 38 | std::string m_header; 39 | std::vector m_datas; 40 | private: //换页处理 41 | int m_curPage; //当前页 42 | int m_maxPage; //总页数 43 | int m_extraData; //如果不是整数页,那么保存一下最后一页有多少条数据 44 | 45 | PushButton m_prevPageBtn; //上一页 46 | PushButton m_nextPageBtn; //下一页 47 | PushButton m_beginPageBtn; //第一页 48 | PushButton m_endPageBtn; //末尾页 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /Easyx_Maye/include/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std::chrono; 4 | /*定时器*/ 5 | class Timer 6 | { 7 | public: 8 | Timer(int64_t ms = 0); 9 | void startTimer(); 10 | bool timeout(); 11 | void setTime(int64_t ms); 12 | void killTimer(); 13 | public: 14 | //静态定时器 15 | static bool startTimer(int64_t ms, int id); 16 | //定时器的最大ID 17 | inline static size_t maxTimerID() { return 20; }; 18 | private: 19 | int64_t m_ms; //延迟毫秒数 20 | time_point m_startime; 21 | time_point m_endtime; 22 | 23 | bool m_threadIsRun; //控制线程运行 24 | }; 25 | 26 | /*时间间隔(计算运行时间)*/ 27 | class ElapsedTimer 28 | { 29 | public: 30 | ElapsedTimer(); 31 | void reset(); 32 | //默认输出毫秒 33 | int64_t elapsed() const; 34 | //微秒 35 | int64_t elapsed_micro() const; 36 | //纳秒 37 | int64_t elapsed_nano() const; 38 | //秒 39 | int64_t elapsed_seconds() const; 40 | //分 41 | int64_t elapsed_minutes() const; 42 | //时 43 | int64_t elapsed_hours() const; 44 | private: 45 | time_point m_begin; 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /Easyx_Maye/include/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | #include 4 | 5 | /*@setCursor光标样式名字 6 | IDC_ARROW, //正常 7 | IDC_IBEAM, //工 8 | IDC_WAIT, //○ 9 | IDC_CROSS, //十 10 | IDC_UPARROW, //↑ 11 | IDC_SIZE, //???? 12 | IDC_ICON, //???? 13 | IDC_SIZENWSE,//左上角缩放 14 | IDC_SIZENESW,//右上角缩放 15 | IDC_SIZEWE, //左右 16 | IDC_SIZENS, //上下 17 | IDC_SIZEALL, //带箭头的十 18 | IDC_NO //(X) 19 | */ 20 | 21 | class Window 22 | { 23 | public: 24 | Window(int w, int h,int flag = 0); 25 | ~Window(); 26 | void setWindowTitle(const std::string& title); 27 | void setWindowColor(COLORREF c); 28 | void setCursor(LPSTR curSorStyle); 29 | inline int exec() { system("pause"); return 0; }; 30 | public://static 31 | static int width(); 32 | static int height(); 33 | static void clear(); 34 | static void beginDraw(); 35 | static void flushDraw(); 36 | static void endDraw(); 37 | 38 | inline static bool hasMsg() { return peekmessage(&s_message, EM_MOUSE | EM_KEY); } 39 | inline static const ExMessage& getMsg() { return s_message; } 40 | 41 | private: 42 | HWND handle; //当前窗口句柄 43 | static ExMessage s_message; 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /Easyx_Maye/include/commonutils/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"TypeDefine.h" 3 | class Color 4 | { 5 | public: 6 | Color(int rgb = 0x000); 7 | Color(uint8 r, uint8 g, uint8 b); 8 | uint32 toRgb() const ; 9 | 10 | inline operator uint32() const 11 | { 12 | return m_color; 13 | } 14 | 15 | static uint32 rgb(uint8 r, uint8 g, uint8 b); 16 | private: 17 | uint32 m_color; 18 | public: 19 | enum ColorDef 20 | { 21 | Black = 0, 22 | Blue = 0xAA0000, 23 | Green = 0x00AA00, 24 | Cyan = 0xAAAA00, 25 | Red = 0x0000AA, 26 | Magenta = 0xAA00AA, 27 | Brown = 0x0055AA, 28 | LightGray = 0xAAAAAA, 29 | DarkGray = 0x555555, 30 | LightBlue = 0xFF5555, 31 | LightGreen = 0x55FF55, 32 | LightCyan = 0xFFFF55, 33 | LightRed = 0x5555FF, 34 | LightMagenta = 0xFF55FF, 35 | Yellow = 0x55FFFF, 36 | White = 0xFFFFFF, 37 | }; 38 | }; -------------------------------------------------------------------------------- /Easyx_Maye/include/commonutils/Font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"TypeDefine.h" 3 | #include 4 | #include"../../include/commonutils/Color.h" 5 | class Font 6 | { 7 | public: 8 | Font(); 9 | Font(const std::string& family, int Weight = 0, bool italic = false); 10 | 11 | void setHeight(int height); 12 | void setWidth(int width); 13 | void setBold(bool enable); 14 | void setItalic(bool enable); 15 | void setWeight(int weight); 16 | void setQuality(int Quality); 17 | void setFamily(const std::string& family); 18 | void setColor(const Color& color); 19 | 20 | const Color& color(); 21 | 22 | int Height(); 23 | int Width(); 24 | bool Bold(); 25 | bool Italic(); 26 | int Weight(); 27 | int Quality(); 28 | std::string Family(); 29 | 30 | private: 31 | int32 lfHeight = 0; //字符的平均高度 32 | int32 lfWidth = 0; //字符的平均宽度(0 表示自适应) 33 | int32 lfEscapement = 0; //字符串的书写角度(单位 0.1 度); 34 | int32 lfOrientation = 0; //每个字符的书写角度(单位 0.1 度); 35 | int32 lfWeight = 0; //字符的笔画粗细(0 表示默认粗细); 36 | Byte lfItalic = 0; //是否斜体; 37 | Byte lfUnderline = 0; //是否下划线; 38 | Byte lfStrikeOut = 0; //是否删除线 39 | Byte lfCharSet = 0; //指定字符集; 40 | Byte lfOutPrecision = 0; //指定文字的输出精度; 41 | Byte lfClipPrecision = 0; //指定文字的剪辑精度; 42 | Byte lfQuality = 0; //指定文字的输出质量; 43 | Byte lfPitchAndFamily = 0; //指定以常规方式描述字体的字体系列。 44 | char lfFaceName[32] = { 0 }; //字体名称 45 | Color lfcolor; 46 | }; -------------------------------------------------------------------------------- /Easyx_Maye/include/commonutils/Painter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/include/commonutils/Painter.h -------------------------------------------------------------------------------- /Easyx_Maye/include/commonutils/TypeDefine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using uint8 = unsigned char; 4 | using uint16 = unsigned short; 5 | using uint32 = unsigned int; 6 | using uint64 = unsigned long long; 7 | 8 | using int8 = char; 9 | using int16 = short; 10 | using int32 = int; 11 | using int64 = long long; 12 | 13 | using Byte = uint8; 14 | using Word = uint16; 15 | using Dword = uint32; -------------------------------------------------------------------------------- /Easyx_Maye/include/pushButton.h: -------------------------------------------------------------------------------- 1 | /*pushButton 按钮类*/ 2 | #ifndef __PUSHBUTTON_H_ 3 | #define __PUSHBUTTON_H_ 4 | #include"Configure.h" 5 | #include"image.h" 6 | #include"BasicWidget.h" 7 | 8 | class PushButton:public BasicWidget 9 | { 10 | public: 11 | PushButton(std::string text ="PushButton",int x=0,int y=0,int w =100,int h = 30); 12 | void show(); 13 | 14 | void setText(std::string text); 15 | void setBackgroundImage(std::string imgPath); 16 | void setBackgroundColor(Color color); 17 | 18 | void setHover(COLORREF c); 19 | void setHover(std::string imgPath); 20 | //事件循环 21 | void eventLoop(const ExMessage&); 22 | 23 | //鼠标是否在按钮上面 24 | bool isin(); 25 | //鼠标是否点击了按钮 26 | bool isClicked(); 27 | 28 | 29 | ~PushButton(); 30 | 31 | public: 32 | std::string text; 33 | bool isshow = false; //显示状态 34 | ExMessage _msg; //鼠标消息 35 | public: //current 36 | Image* cur_img = nullptr; 37 | COLORREF cur_color = RGB(232, 232, 236); 38 | 39 | public: //normal 40 | Image* nor_img = nullptr; 41 | COLORREF nor_color = RGB(232, 232, 236); 42 | 43 | public: //hover 44 | Image* h_img = nullptr; 45 | COLORREF h_color = RGB(194, 195, 201); 46 | }; 47 | #endif -------------------------------------------------------------------------------- /Easyx_Maye/include/randomGenerator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/include/randomGenerator.h -------------------------------------------------------------------------------- /Easyx_Maye/lib/x64/Easyx_Maye.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/lib/x64/Easyx_Maye.idb -------------------------------------------------------------------------------- /Easyx_Maye/lib/x64/Easyx_Maye.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/lib/x64/Easyx_Maye.lib -------------------------------------------------------------------------------- /Easyx_Maye/lib/x86/Easyx_Maye.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/lib/x86/Easyx_Maye.idb -------------------------------------------------------------------------------- /Easyx_Maye/lib/x86/Easyx_Maye.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/lib/x86/Easyx_Maye.lib -------------------------------------------------------------------------------- /Easyx_Maye/main.cpp: -------------------------------------------------------------------------------- 1 | #include"Window.h" 2 | #include"Image.h" 3 | #include"pushButton.h" 4 | #include"LineEdit.h" 5 | 6 | int main() 7 | { 8 | Window w(640, 480,EW_SHOWCONSOLE); 9 | w.setCursor(IDC_CROSS); 10 | w.setWindowTitle("Maye Easyx"); 11 | w.setWindowColor(RGB(194, 195, 201)); 12 | 13 | 14 | setbkmode(TRANSPARENT); 15 | 16 | LineEdit edit(100,100,200,30); 17 | 18 | Window::beginDraw(); 19 | while (true) 20 | { 21 | Window::clear(); 22 | edit.updateText(); 23 | edit.show(); 24 | 25 | std::cout << edit.text() << std::endl; 26 | Window::flushDraw(); 27 | } 28 | 29 | 30 | return w.exec(); 31 | } -------------------------------------------------------------------------------- /Easyx_Maye/source/BasicWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/BasicWidget.h" 2 | 3 | BasicWidget::BasicWidget(int x, int y, int w, int h) 4 | :m_x(x),m_y(y),m_w(w),m_h(h),m_bkColor(),m_font("黑体") 5 | { 6 | m_font.setHeight(20); 7 | m_font.setQuality(PROOF_QUALITY); 8 | settextstyle((LOGFONT*)&m_font); 9 | settextcolor(m_font.color().toRgb()); 10 | 11 | } 12 | 13 | int BasicWidget::width() const 14 | { 15 | return m_w; 16 | } 17 | 18 | int BasicWidget::height() const 19 | { 20 | return m_h; 21 | } 22 | 23 | void BasicWidget::setFixedSize(int w, int h) 24 | { 25 | this->m_w = w; 26 | this->m_h = h; 27 | } 28 | 29 | int BasicWidget::x() const 30 | { 31 | return m_x; 32 | } 33 | 34 | int BasicWidget::y() const 35 | { 36 | return m_y; 37 | } 38 | 39 | void BasicWidget::move(int x, int y) 40 | { 41 | this->m_x = x; 42 | this->m_y = y; 43 | } 44 | 45 | 46 | void BasicWidget::setBackgroundColor(const Color& color) 47 | { 48 | m_bkColor = color; 49 | } 50 | 51 | Color BasicWidget::BackgroundColor() 52 | { 53 | return m_bkColor; 54 | } 55 | 56 | void BasicWidget::setFont(const Font& font) 57 | { 58 | m_font = font; 59 | } 60 | 61 | const Font& BasicWidget::font() 62 | { 63 | return m_font; 64 | } 65 | 66 | void BasicWidget::show() 67 | { 68 | settextstyle((LOGFONT*)&m_font); 69 | settextcolor(m_font.color()); 70 | } 71 | -------------------------------------------------------------------------------- /Easyx_Maye/source/Image.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/Image.h" 2 | #include"../include/Window.h" 3 | 4 | Image::Image():x(0),y(0),pMaskImg(nullptr) 5 | { 6 | 7 | } 8 | 9 | Image::Image(const std::string& imgPath, int w, int h): Image() 10 | { 11 | ::loadimage(this, imgPath.c_str(), w, h); 12 | if (this->getwidth() == 0 && this->getheight() == 0) 13 | { 14 | plog("[error] %s load failed\n", imgPath.c_str()); 15 | } 16 | } 17 | 18 | Image::Image(const std::string& maskImgPath, const std::string& srcImgPath, int w, int h) 19 | :pMaskImg(new Image(maskImgPath,w,h)) 20 | { 21 | ::loadimage(this, srcImgPath.c_str(), w, h); 22 | if (this->getwidth() == 0 && this->getheight() == 0) 23 | { 24 | plog("[error] %s load failed\n", srcImgPath.c_str()); 25 | } 26 | } 27 | 28 | Image::Image(const std::string& prefixPath, const std::string& maskImgPath, const std::string& srcImgPath, int w, int h) 29 | :Image(prefixPath+maskImgPath, prefixPath+srcImgPath,w,h) 30 | { 31 | } 32 | 33 | void Image::draw() 34 | { 35 | putimage_alapha(this->x, this->y, this); 36 | } 37 | 38 | void Image::draw(DWORD maskdwRop,DWORD srcdwRop) 39 | { 40 | ::putimage(this->x, this->y, pMaskImg, maskdwRop); 41 | ::putimage(this->x, this->y, this, srcdwRop); 42 | } 43 | 44 | void Image::move(int x, int y) 45 | { 46 | this->x = x; 47 | this->y = y; 48 | } 49 | 50 | void Image::save(const std::string& savePath) 51 | { 52 | ::saveimage(savePath.c_str(), this); 53 | } 54 | 55 | void Image::save(const std::string& savePath, Image* img) 56 | { 57 | ::saveimage(savePath.c_str(), img); 58 | } 59 | 60 | Image* Image::getimage(int x, int y, int w, int h) 61 | { 62 | Image* img = new Image; 63 | ::getimage(img, x, y, w, h); 64 | return img; 65 | } 66 | 67 | DWORD* Image::ImageBuffer() 68 | { 69 | return ::GetImageBuffer(this); 70 | } 71 | 72 | void Image::SetDefault() 73 | { 74 | } 75 | 76 | 77 | 78 | /*@私有成员*/ 79 | //png图片透明贴图 80 | void Image::putimage_alapha(int x, int y, IMAGE* src) 81 | { 82 | // 变量初始化 83 | DWORD* pwin = GetImageBuffer(); //窗口缓冲区指针 84 | DWORD* psrc = GetImageBuffer(src); //图片缓冲区指针 85 | int win_w = Window::width(); //窗口宽高 86 | int win_h = Window::height(); 87 | int src_w = src->getwidth(); //图片宽高 88 | int src_h = src->getheight(); 89 | 90 | // 计算贴图的实际长宽 91 | int real_w = (x + src_w > win_w) ? win_w - x : src_w; // 处理超出右边界 92 | int real_h = (y + src_h > win_h) ? win_h - y : src_h; // 处理超出下边界 93 | if (x < 0) { psrc += -x; real_w -= -x; x = 0; } // 处理超出左边界 94 | if (y < 0) { psrc += (src_w * -y); real_h -= -y; y = 0; } // 处理超出上边界 95 | 96 | 97 | // 修正贴图起始位置 98 | pwin += (win_w * y + x); 99 | 100 | // 实现透明贴图 101 | for (int iy = 0; iy < real_h; iy++) 102 | { 103 | for (int ix = 0; ix < real_w; ix++) 104 | { 105 | byte a = (byte)(psrc[ix] >> 24);//计算透明通道的值[0,256) 0为完全透明 255为完全不透明 106 | if (a > 100) 107 | { 108 | pwin[ix] = psrc[ix]; 109 | } 110 | } 111 | //换到下一行 112 | pwin += win_w; 113 | psrc += src_w; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Easyx_Maye/source/LineEdit.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/LineEdit.h" 2 | #include"../include/Window.h" 3 | #include 4 | 5 | LineEdit::LineEdit(int x, int y, int w, int h) 6 | :BasicWidget(x, y, w, h), textw(2), m_isPopUp(false) 7 | , m_title("请输入") 8 | { 9 | 10 | } 11 | 12 | void LineEdit::show() 13 | { 14 | BasicWidget::show(); 15 | setfillcolor(RGB(232, 232, 236)); 16 | fillrectangle(m_x, m_y, m_x+m_w, m_y+m_h); 17 | 18 | //闪烁的小竖线 19 | setlinecolor(RED); 20 | line(m_x + textw + 2, m_y + 2, m_x + textw + 2, m_y + m_h - 2); 21 | 22 | //把文字输出到edit上 23 | outtextxy(m_x, m_y+(m_h - textheight(m_text.c_str())) / 2,m_text.c_str()); 24 | 25 | 26 | if (m_isPopUp) 27 | { 28 | m_pretext = m_text; 29 | popInputBox(); 30 | m_isPopUp = false; 31 | } 32 | } 33 | void LineEdit::eventLoop(const ExMessage& msg) 34 | { 35 | //判断是否需要弹出输入框 36 | if (msg.x > m_x && msg.x < m_x + m_w && msg.y > m_y && msg.y < m_y + m_h 37 | && msg.message == WM_LBUTTONDOWN) 38 | { 39 | m_isPopUp = true; 40 | } 41 | } 42 | void LineEdit::popInputBox() 43 | { 44 | char str[128] = { 0 }; 45 | InputBox(str, 128, nullptr,m_title.c_str(),m_text.c_str()); 46 | m_text = str; 47 | textw = ::textwidth(m_text.c_str()); 48 | } 49 | void LineEdit::setInputBoxTitle(const std::string& title) 50 | { 51 | m_title = title; 52 | } 53 | 54 | std::string LineEdit::text() 55 | { 56 | return m_text; 57 | } 58 | 59 | void LineEdit::clear() 60 | { 61 | m_text.clear(); 62 | textw = 0; 63 | } 64 | 65 | bool LineEdit::textChanged() 66 | { 67 | if (m_pretext == m_text) 68 | { 69 | return false; 70 | } 71 | m_pretext = m_text; //更新,通知一次文本改变即可 72 | return true; 73 | } 74 | -------------------------------------------------------------------------------- /Easyx_Maye/source/Table.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/Table.h" 2 | #include 3 | using namespace std; 4 | Table::Table(int row, int col) 5 | :m_rows(row), m_cols(col), m_curPage(0), m_maxPage(0) 6 | ,BasicWidget(0,0,0,0) 7 | { 8 | m_prevPageBtn.setText("上一页"); 9 | m_nextPageBtn.setText("下一页"); 10 | m_beginPageBtn.setText("第一页"); 11 | m_endPageBtn.setText("结尾页"); 12 | 13 | } 14 | 15 | void Table::setRowCount(int row) 16 | { 17 | m_rows = row; 18 | } 19 | 20 | void Table::setColCount(int col) 21 | { 22 | m_cols = col; 23 | } 24 | 25 | 26 | void Table::setHeader(const std::string& data) 27 | { 28 | m_header = data; 29 | m_cols = std::count(m_header.begin(), m_header.end(), '\t') - 1; 30 | 31 | 32 | int textw = ::textwidth("计算机1401"); 33 | int texth = ::textheight(m_header.c_str()); 34 | 35 | m_gridw = textw + 15; 36 | m_gridh = texth + 10; 37 | 38 | //设置从父类继承过来的宽度和高度 39 | m_h = m_rows * m_gridh; 40 | m_w = m_cols* m_gridw; 41 | } 42 | 43 | void Table::insert(const std::string& data) 44 | { 45 | m_datas.push_back(data); 46 | updateData(); 47 | } 48 | 49 | void Table::clear() 50 | { 51 | m_datas.clear(); 52 | updateData(); 53 | } 54 | 55 | void Table::eventLoop(const ExMessage& msg) 56 | { 57 | m_prevPageBtn.eventLoop(msg); 58 | m_nextPageBtn.eventLoop(msg); 59 | m_beginPageBtn.eventLoop(msg); 60 | m_endPageBtn.eventLoop(msg); 61 | 62 | if (m_prevPageBtn.isClicked()) 63 | { 64 | //cout << "m_prevPageBtn" << endl; 65 | if (m_curPage != 0) 66 | { 67 | m_curPage--; 68 | } 69 | //cout << "m_extraData:" << m_extraData << endl; 70 | } 71 | if (m_nextPageBtn.isClicked()) 72 | { 73 | //cout << "m_nextPageBtn" << endl; 74 | if (m_curPage != m_maxPage) 75 | { 76 | m_curPage++; 77 | } 78 | } 79 | if (m_beginPageBtn.isClicked()) 80 | { 81 | m_curPage = 0; 82 | //cout << "m_beginPageBtn" << endl; 83 | } 84 | if (m_endPageBtn.isClicked()) 85 | { 86 | m_curPage = m_maxPage; 87 | //cout << "m_endPageBtn" << endl; 88 | } 89 | //cout << "m_curPage:" << m_curPage << "/" << m_maxPage << endl; 90 | } 91 | 92 | void Table::drawTableGrid() 93 | { 94 | if (m_rows == 0) 95 | { 96 | m_rows = m_datas.size(); 97 | } 98 | drawHeader(); 99 | setlinestyle(PS_SOLID, 1); 100 | //表格横线 101 | for (size_t i = 0; i < m_rows + 1; i++) 102 | { 103 | //m_x + m_cols * textw 表格的总宽度 104 | int resy = m_y + m_gridh * i; 105 | line(m_x, resy, m_x + m_cols * m_gridw, resy); 106 | } 107 | //表格竖线 108 | for (size_t k = 0; k < m_cols+1; k++) 109 | { 110 | line(m_x + k * m_gridw, m_y, m_x + k * m_gridw, m_y + m_gridh * m_rows); 111 | } 112 | 113 | if (m_maxPage > 0) 114 | { 115 | initPageBtnPos(); 116 | } 117 | } 118 | 119 | void Table::drawTableText() 120 | { 121 | //防止越界 122 | if (m_rows > m_datas.size() &&m_datas.size()!=0) 123 | { 124 | m_rows = m_datas.size(); 125 | } 126 | 127 | int begPos = m_curPage * m_rows; //当前页数*每页行数,获取当前页在m_datas中的数据下标 128 | int endPos = m_rows + m_curPage * m_rows; //上面的数据加上 每行的行数,获取一页的数据 129 | //如果是最后一页,只遍历余下的数据 130 | if (m_curPage == m_maxPage) 131 | { 132 | endPos = begPos + m_extraData; 133 | } 134 | //如果没有数据,不输出 135 | if (m_datas.size() == 0) 136 | { 137 | endPos = 0; 138 | } 139 | 140 | for (int beg = begPos,i =0; beg < endPos; beg++,i++) 141 | { 142 | std::vector line_data = split(m_datas[beg]); 143 | 144 | for (size_t k = 0; k < line_data.size(); k++) 145 | { 146 | int tx = m_x + k * m_gridw; 147 | int ty = m_y + i * m_gridh; 148 | BasicWidget::show(); 149 | outtextxy(tx,ty+5, line_data[k].c_str()); 150 | } 151 | } 152 | } 153 | 154 | void Table::drawHeader() 155 | { 156 | //绘制表头表格 157 | setlinestyle(PS_SOLID, 2); 158 | rectangle(m_x, m_y - 30, m_x + m_gridw * m_cols, m_y); 159 | for (size_t i = 0; i < m_cols + 1; i++) 160 | { 161 | line(m_x + i * m_gridw, m_y - 30, m_x + i * m_gridw, m_y); 162 | } 163 | //绘制表头数据 164 | std::vector header = split(m_header); 165 | for (auto it = header.begin(); it != header.end();) 166 | { 167 | if (it->empty()) 168 | { 169 | it = header.erase(it); 170 | } 171 | else 172 | { 173 | it++; 174 | } 175 | } 176 | int space = 0; 177 | for (size_t i = 0; i < header.size(); i++) 178 | { 179 | space = (m_gridw - textwidth(header[i].c_str())) / 2; //居中显示表头,计算两边的间隔 180 | outtextxy(m_x + i * m_gridw + space, m_y - m_gridh+5, header[i].c_str()); 181 | } 182 | } 183 | 184 | void Table::updateData() 185 | { 186 | //计算最大页数 187 | if (m_rows >= m_datas.size()) 188 | { 189 | m_maxPage = 0; 190 | m_extraData = m_datas.size(); 191 | } 192 | else 193 | { 194 | m_extraData = m_datas.size() % m_rows; //计算余下多少条数据 195 | m_maxPage = m_datas.size() / m_rows; 196 | } 197 | } 198 | 199 | void Table::initPageBtnPos() 200 | { 201 | m_prevPageBtn.move(m_x, m_y + m_gridh * m_rows + 20); 202 | m_nextPageBtn.move(m_x + 100, m_y + m_gridh * m_rows + 20); 203 | m_beginPageBtn.move(m_x + 200, m_y + m_gridh * m_rows + 20); 204 | m_endPageBtn.move(m_x + 300, m_y + m_gridh * m_rows + 20); 205 | 206 | m_prevPageBtn.show(); 207 | m_nextPageBtn.show(); 208 | m_beginPageBtn.show(); 209 | m_endPageBtn.show(); 210 | 211 | std::string pageInfo("共" + std::to_string(m_maxPage + 1) + "页,第" + std::to_string(m_curPage + 1) + "页"); 212 | outtextxy(m_x + 450, m_y + m_gridh * m_rows + 20, pageInfo.c_str()); 213 | } 214 | 215 | std::vector Table::split(std::string str,char separator) 216 | { 217 | std::vector res; 218 | for (size_t pos = 0; pos != std::string::npos ; ) 219 | { 220 | if (pos != 0) 221 | pos++; 222 | //以指定的字符分隔 223 | pos = str.find(separator); 224 | //保存分隔出来的字符串 225 | res.push_back(str.substr(0, pos)); 226 | //剩下未分隔的字符串 227 | str = std::string(str.data() + pos+1); 228 | } 229 | return res; 230 | } 231 | 232 | void Table::show() 233 | { 234 | BasicWidget::show(); 235 | drawTableGrid(); 236 | drawTableText(); 237 | } 238 | 239 | -------------------------------------------------------------------------------- /Easyx_Maye/source/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/Timer.h" 2 | #include 3 | #include 4 | Timer::Timer(int64_t ms) 5 | :m_ms(ms), m_threadIsRun(false) 6 | { 7 | } 8 | 9 | void Timer::startTimer() 10 | { 11 | m_startime = high_resolution_clock::now(); 12 | 13 | m_threadIsRun = true; 14 | static std::thread thr; 15 | thr = std::thread([this]() 16 | { 17 | while (m_threadIsRun) 18 | { 19 | m_endtime = high_resolution_clock::now(); 20 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); 21 | } 22 | }); 23 | } 24 | 25 | bool Timer::timeout() 26 | { 27 | if (m_endtime - m_startime >= milliseconds(m_ms)) 28 | { 29 | m_startime = m_endtime; 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | void Timer::setTime(int64_t ms) 36 | { 37 | m_ms = ms; 38 | } 39 | 40 | void Timer::killTimer() 41 | { 42 | m_threadIsRun = false; 43 | } 44 | 45 | bool Timer::startTimer(int64_t ms, int id) 46 | { 47 | static int64_t start[21] = { 0 }; 48 | int64_t end = clock(); 49 | if (end - start[id] >= ms) 50 | { 51 | start[id] = end; 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | 58 | /*@时间间隔*/ 59 | ElapsedTimer::ElapsedTimer() : m_begin(high_resolution_clock::now()) {} 60 | void ElapsedTimer::reset() { m_begin = high_resolution_clock::now(); } 61 | //默认输出毫秒 62 | int64_t ElapsedTimer::elapsed() const 63 | { 64 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 65 | } 66 | //微秒 67 | int64_t ElapsedTimer::elapsed_micro() const 68 | { 69 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 70 | } 71 | //纳秒 72 | int64_t ElapsedTimer::elapsed_nano() const 73 | { 74 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 75 | } 76 | //秒 77 | int64_t ElapsedTimer::elapsed_seconds() const 78 | { 79 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 80 | } 81 | //分 82 | int64_t ElapsedTimer::elapsed_minutes() const 83 | { 84 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 85 | } 86 | //时 87 | int64_t ElapsedTimer::elapsed_hours() const 88 | { 89 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 90 | } -------------------------------------------------------------------------------- /Easyx_Maye/source/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/Window.h" 2 | #include 3 | ExMessage Window::s_message; 4 | Window::Window(int w, int h, int flag) 5 | { 6 | handle = initgraph(w, h, flag); 7 | setbkmode(TRANSPARENT); 8 | } 9 | 10 | Window::~Window() 11 | { 12 | closegraph(); 13 | } 14 | 15 | void Window::setWindowTitle(const std::string& title) 16 | { 17 | SetWindowText(handle, title.c_str()); 18 | } 19 | 20 | void Window::setWindowColor(COLORREF c) 21 | { 22 | ::setbkcolor(c); 23 | clear(); 24 | } 25 | 26 | void Window::setCursor(LPSTR curSorStyle) 27 | { 28 | IDC_ARROW; 29 | HCURSOR hcur = LoadCursor(NULL, curSorStyle); 30 | SetClassLong(GetHWnd(), GCLP_HCURSOR, (long)hcur); 31 | } 32 | 33 | int Window::width() 34 | { 35 | return ::getwidth(); 36 | } 37 | 38 | int Window::height() 39 | { 40 | return ::getheight(); 41 | } 42 | 43 | void Window::clear() 44 | { 45 | ::cleardevice(); 46 | } 47 | 48 | void Window::beginDraw() 49 | { 50 | ::BeginBatchDraw(); 51 | } 52 | 53 | void Window::flushDraw() 54 | { 55 | ::FlushBatchDraw(); 56 | } 57 | 58 | void Window::endDraw() 59 | { 60 | ::EndBatchDraw(); 61 | } 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Easyx_Maye/source/commonutils/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "..\..\include\commonutils\Color.h" 2 | 3 | Color::Color(int rgb) 4 | { 5 | m_color = rgb; 6 | } 7 | 8 | Color::Color(uint8 r, uint8 g, uint8 b) 9 | { 10 | //m_color = ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) ) 11 | m_color = ((Dword)(((Byte)(r) | ((Word)((Byte)(g)) << 8)) | (((Dword)(Byte)(b)) << 16))); 12 | } 13 | 14 | uint32 Color::toRgb() const 15 | { 16 | return m_color; 17 | } 18 | 19 | uint32 Color::rgb(uint8 r, uint8 g, uint8 b) 20 | { 21 | return ((Dword)(((Byte)(r) | ((Word)((Byte)(g)) << 8)) | (((Dword)(Byte)(b)) << 16))); 22 | } 23 | -------------------------------------------------------------------------------- /Easyx_Maye/source/commonutils/Font.cpp: -------------------------------------------------------------------------------- 1 | #include"../../include/commonutils/Font.h" 2 | 3 | Font::Font() 4 | { 5 | } 6 | 7 | Font::Font(const std::string& family, int Weight, bool italic) 8 | { 9 | strcpy_s(lfFaceName, family.c_str()); 10 | lfWeight = Weight; 11 | lfItalic = italic; 12 | lfcolor = Color::Black; //黑色 13 | } 14 | 15 | 16 | 17 | void Font::setHeight(int height) 18 | { 19 | lfHeight = height; 20 | } 21 | 22 | void Font::setWidth(int width) 23 | { 24 | lfWidth = width; 25 | } 26 | 27 | void Font::setBold(bool enable) 28 | { 29 | 30 | } 31 | 32 | void Font::setItalic(bool enable) 33 | { 34 | lfItalic = enable; 35 | } 36 | 37 | void Font::setWeight(int weight) 38 | { 39 | lfWeight = weight; 40 | } 41 | 42 | void Font::setQuality(int Quality) 43 | { 44 | lfQuality = lfQuality; 45 | } 46 | 47 | void Font::setFamily(const std::string& family) 48 | { 49 | strcpy_s(lfFaceName, family.c_str()); 50 | } 51 | 52 | void Font::setColor(const Color& color) 53 | { 54 | lfcolor = color; 55 | } 56 | 57 | const Color& Font::color() 58 | { 59 | return lfcolor; 60 | } 61 | 62 | int Font::Height() 63 | { 64 | return lfHeight; 65 | } 66 | 67 | int Font::Width() 68 | { 69 | return lfWidth; 70 | } 71 | 72 | bool Font::Bold() 73 | { 74 | return false; 75 | } 76 | 77 | bool Font::Italic() 78 | { 79 | return lfItalic; 80 | } 81 | 82 | int Font::Weight() 83 | { 84 | return lfWeight; 85 | } 86 | 87 | int Font::Quality() 88 | { 89 | return lfQuality; 90 | } 91 | 92 | std::string Font::Family() 93 | { 94 | return lfFaceName; 95 | } 96 | -------------------------------------------------------------------------------- /Easyx_Maye/source/commonutils/Painter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/Easyx_Maye/source/commonutils/Painter.cpp -------------------------------------------------------------------------------- /Easyx_Maye/source/pushButton.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pushButton.h" 2 | 3 | 4 | PushButton::PushButton(std::string text, int x, int y, int w, int h) 5 | :text(text),BasicWidget(x,y,w,h) 6 | { 7 | memset(&_msg, 0, sizeof(ExMessage)); 8 | 9 | } 10 | 11 | void PushButton::show() 12 | { 13 | BasicWidget::show(); 14 | if (cur_img) 15 | { 16 | cur_img->draw(); 17 | } 18 | else 19 | { 20 | setlinecolor(BLACK); 21 | setfillcolor(cur_color); 22 | ::fillroundrect(m_x, m_y, m_x + m_w, m_y + m_h,10,10); 23 | } 24 | 25 | //居中显示文本 26 | int tx = m_x + (m_w - textwidth(text.data())) / 2; 27 | int ty = m_y + (m_h - textheight(text.data())) / 2; 28 | outtextxy(tx, ty, text.data()); 29 | } 30 | 31 | void PushButton::setText(std::string text) 32 | { 33 | this->text = text; 34 | } 35 | 36 | void PushButton::setBackgroundImage(std::string imgPath) 37 | { 38 | if(!nor_img) 39 | nor_img = new Image(imgPath.data(), this->m_w, this->m_h); 40 | this->cur_img = nor_img; 41 | this->show(); 42 | } 43 | 44 | void PushButton::setBackgroundColor(Color color) 45 | { 46 | this->nor_color = color; 47 | } 48 | 49 | void PushButton::setHover(COLORREF c) 50 | { 51 | h_color = c; 52 | } 53 | 54 | void PushButton::setHover(std::string imgPath) 55 | { 56 | if(!h_img) 57 | h_img = new Image(imgPath.c_str(),m_w,m_h); 58 | } 59 | 60 | void PushButton::eventLoop(const ExMessage& msg) 61 | { 62 | this->_msg = msg; 63 | if (isin()) 64 | { 65 | if (cur_img) 66 | { 67 | cur_img = h_img; 68 | } 69 | else 70 | { 71 | cur_color = h_color; 72 | } 73 | } 74 | else 75 | { 76 | if (cur_img) 77 | { 78 | cur_img = nor_img; 79 | } 80 | else 81 | { 82 | cur_color = nor_color; 83 | } 84 | 85 | } 86 | 87 | //this->show(); 88 | } 89 | 90 | bool PushButton::isin() 91 | { 92 | if (_msg.x >= m_x && _msg.x <= m_x + m_w && _msg.y >= m_y && _msg.y <= m_y+m_h) 93 | { 94 | return true; 95 | } 96 | return false; 97 | } 98 | 99 | bool PushButton::isClicked() 100 | { 101 | if (isin()) 102 | { 103 | switch (_msg.message) 104 | { 105 | case WM_LBUTTONDOWN: 106 | return true; 107 | } 108 | } 109 | return false; 110 | } 111 | 112 | PushButton::~PushButton() 113 | { 114 | } 115 | -------------------------------------------------------------------------------- /Easyx_Maye/source/randomGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/randomGenerator.h" 2 | #include 3 | 4 | RandomGenerator::RandomGenerator(uint32_t seedValue) 5 | :m_engine(new std::default_random_engine(seedValue)) 6 | { 7 | 8 | } 9 | 10 | int RandomGenerator::bounded(int highest) 11 | { 12 | std::uniform_int_distribution intDis(0, highest-1); 13 | return intDis(*m_engine); 14 | } 15 | 16 | int RandomGenerator::bounded(int lowest, int highest) 17 | { 18 | std::uniform_int_distribution intDis(lowest, highest-1); 19 | return intDis(*m_engine); 20 | } 21 | 22 | RandomGenerator* RandomGenerator::global() 23 | { 24 | static RandomGenerator* instance = nullptr; 25 | if (instance == nullptr) 26 | { 27 | instance = new RandomGenerator((uint32_t)std::chrono::system_clock::now().time_since_epoch().count()); 28 | } 29 | return instance; 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # easyx-Project-C_CPP 2 | Easyx的一些项目 3 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/ManageMent(控制台版).cpp: -------------------------------------------------------------------------------- 1 | #include "ManageMent.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | ManageMent::ManageMent() 10 | { 11 | readData("./student.txt"); 12 | //writeData("./test.txt"); 13 | } 14 | 15 | void ManageMent::run() 16 | { 17 | menu(); 18 | while (true) 19 | { 20 | cout << "请选择>"; 21 | int op = -1; 22 | cin >> op; 23 | switch (op) 24 | { 25 | case 0: 26 | system("cls"); 27 | menu(); 28 | break; 29 | case ManageMent::ShowAll: 30 | displayAll(); 31 | break; 32 | case ManageMent::Insert: 33 | insert(); 34 | break; 35 | case ManageMent::Erase: 36 | erase(); 37 | break; 38 | case ManageMent::Modify: 39 | modify(); 40 | break; 41 | case ManageMent::Find: 42 | find(); 43 | break; 44 | case ManageMent::Sort: 45 | sort(); 46 | break; 47 | case ManageMent::Exit: 48 | writeData("./test.txt"); 49 | break; 50 | default: 51 | break; 52 | } 53 | } 54 | } 55 | 56 | void ManageMent::menu() 57 | { 58 | cout << "***** 学生成绩管理系统 *****" << endl; 59 | cout << "***** 1,查看学生 *****" << endl; 60 | cout << "***** 2,添加学生 *****" << endl; 61 | cout << "***** 3,删除学生 *****" << endl; 62 | cout << "***** 4,修改学生 *****" << endl; 63 | cout << "***** 5,查找学生 *****" << endl; 64 | cout << "***** 6,排序 *****" << endl; 65 | cout << "***** 7,退出系统 *****" << endl; 66 | cout << "***** 0,清除屏幕 *****" << endl; 67 | cout << endl; 68 | } 69 | 70 | void ManageMent::displayAll() 71 | { 72 | std::cout << this->tableHeader << endl; 73 | for (auto& val : vec_stu) 74 | { 75 | val.display(); 76 | } 77 | std::cout << "共(" << vec_stu.size() << ")条数据" << endl; 78 | } 79 | 80 | void ManageMent::insert() 81 | { 82 | Student stu; 83 | cout << "请依次输入<学号,姓名,班级,数学,语文,英语>" << endl; 84 | cin >> stu.number >> stu.name >> stu.grade >> stu.math >> stu.chinese >> stu.english; 85 | vec_stu.push_back(stu); 86 | } 87 | 88 | void ManageMent::erase() 89 | { 90 | int number = -1; 91 | cout << "请输入要删除的学生的学号>"; 92 | cin >> number; 93 | auto delIt = std::find(vec_stu.begin(), vec_stu.end(), Student(number)); 94 | if (delIt != vec_stu.end()) 95 | { 96 | vec_stu.erase(delIt); 97 | } 98 | } 99 | 100 | void ManageMent::modify() 101 | { 102 | //略 103 | } 104 | 105 | void ManageMent::find() 106 | { 107 | cout << "*** 选择查找属性 ***" << endl; 108 | cout << "*** 1,按学号查找 ***" << endl; 109 | cout << "*** 2,按姓名查找 ***" << endl; 110 | int op = -1; 111 | cout << "select>"; 112 | cin >> op; 113 | Student stu; 114 | if (op == 1) 115 | { 116 | cout << "输入学号:"; 117 | cin >> stu.number; 118 | auto findIt = std::find(vec_stu.begin(), vec_stu.end(), stu); 119 | if (findIt != vec_stu.end()) 120 | { 121 | cout << "找到咯~ "; 122 | findIt->display(); 123 | } 124 | } 125 | else 126 | { 127 | cout << "输入姓名:"; 128 | cin >> stu.name; 129 | for (Student& s : vec_stu) 130 | { 131 | if (s.name == stu.name) 132 | { 133 | cout << "找到咯~ "; 134 | s.display(); 135 | } 136 | } 137 | } 138 | } 139 | 140 | void ManageMent::sort() 141 | { 142 | //默认升序 143 | std::sort(vec_stu.begin(), vec_stu.end()); 144 | std::cout << "排序成功QAQ~" << std::endl; 145 | } 146 | 147 | void ManageMent::readData(const std::string& fileName) 148 | { 149 | fstream stream(fileName.c_str(), ios::in); 150 | if (!stream.is_open()) 151 | { 152 | cerr << fileName << " file open failed" << endl; 153 | return; 154 | } 155 | Student stu; 156 | char buf[1024] = { 0 }; 157 | //读取表头 158 | stream.getline(buf, 1024); 159 | tableHeader = buf; 160 | //读取数据 161 | while (!stream.eof()) 162 | { 163 | memset(buf, 0, sizeof(buf)); 164 | stream.getline(buf, 1024); 165 | 166 | stringstream ss(buf); 167 | ss >> stu.number >> stu.name >> stu.grade >> stu.math >> stu.chinese >> stu.english; 168 | vec_stu.push_back(stu); 169 | } 170 | stream.close(); 171 | } 172 | 173 | void ManageMent::writeData(const std::string& fileName) 174 | { 175 | fstream write(fileName.c_str(), ios::trunc | ios::out); 176 | if (!write.is_open()) 177 | { 178 | cerr << fileName << " file open failed [save]"; 179 | return; 180 | } 181 | tableHeader += '\n'; 182 | write.write(tableHeader.c_str(), tableHeader.size()); 183 | for (auto& val : vec_stu) 184 | { 185 | string info = val.formatInfo(); 186 | write.write(info.c_str(),info.size()); 187 | } 188 | write.close(); 189 | } 190 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/ManageMent(控制台版).h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Student.h" 3 | #include 4 | class ManageMent 5 | { 6 | enum Operator 7 | { 8 | ShowAll =1, 9 | Insert, 10 | Erase, 11 | Modify, 12 | Find, 13 | Sort, 14 | Exit, 15 | }; 16 | public: 17 | ManageMent(); 18 | void run(); 19 | void menu(); 20 | //显示所有学生信息 21 | void displayAll(); 22 | //添加 23 | void insert(); 24 | //删除 25 | void erase(); 26 | //修改 27 | void modify(); 28 | void find(); 29 | //排序 30 | void sort(); 31 | private: 32 | //从文件读取学生信息 33 | void readData(const std::string& fileName); 34 | //保存学生信息到文件 35 | void writeData(const std::string& fileName); 36 | public: 37 | std::string tableHeader; //表头 38 | std::vector vec_stu; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/ManageMent_gui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Student.h" 3 | #include 4 | #include 5 | #include"pushButton.h" 6 | #include"Table.h" 7 | #include"LineEdit.h" 8 | class ManageMent 9 | { 10 | enum Operator 11 | { 12 | ShowAll, 13 | Insert, 14 | Erase, 15 | Modify, 16 | Find, 17 | Exit, 18 | }; 19 | public: 20 | ManageMent(); 21 | void run(); 22 | void menu(); 23 | 24 | void eventLoop(); 25 | void drawBackground(); 26 | 27 | int mainMenu(const ExMessage& msg); 28 | //插入和删除数据时,更新一下表格 29 | void updateTableData(); 30 | //显示所有学生信息 31 | void displayAll(); 32 | //添加 33 | void insert(); 34 | //删除 35 | void erase(); 36 | //修改 37 | void modify(); 38 | //查找 39 | void find(); 40 | //排序 41 | void sort(); 42 | private: 43 | //从文件读取学生信息 44 | void readData(const std::string& fileName); 45 | //保存学生信息到文件 46 | void writeData(const std::string& fileName); 47 | public: 48 | std::string tableHeader; //表头 49 | std::vector vec_stu; 50 | int m_prevStuCnt; //上一次学生的数量 51 | 52 | std::vector menu_btns; 53 | 54 | Table m_insertTable; 55 | LineEdit m_insertEdit; //添加学生编辑框 56 | PushButton m_insertBtn; //添加学生确认按钮 57 | 58 | ExMessage m_msg; 59 | int m_key; 60 | public: 61 | Image m_bk; 62 | public://查找学生页面 63 | LineEdit* searchEdit; 64 | PushButton* searchIdBtn; 65 | PushButton* searchNameBtn; 66 | Table* searchTable; 67 | public://删除学生页面 68 | LineEdit* delEdit; 69 | PushButton* delBtn; 70 | Table* delTable; 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/Student.cpp: -------------------------------------------------------------------------------- 1 | #include "Student.h" 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | Student::Student():number(0),math(0),chinese(0),english(0) 7 | { 8 | //memset(this,0, sizeof(Student));//不能使用这个,否则会乱码 9 | } 10 | 11 | Student::Student(uint32 number):Student() 12 | { 13 | this->number = number; 14 | } 15 | 16 | Student::Student(uint32 number, const std::string& name, const std::string& grade, int math, int chinese, int english) 17 | : number(number),name(name),grade(grade), math(math), chinese(chinese), english(english) 18 | {} 19 | 20 | void Student::display() 21 | { 22 | cout << this->number << "\t" << this->name << "\t" << this->grade << "\t" << this->math << "\t" << this->chinese << "\t" << this->english << endl; 23 | } 24 | 25 | std::string Student::formatInfo() 26 | { 27 | stringstream ss; 28 | ss<< this->number << "\t" << this->name << "\t" << this->grade << "\t" << this->math << "\t" << this->chinese << "\t" << this->english << endl; 29 | return ss.str(); 30 | } 31 | 32 | void Student::formatWrite(const std::string& str) 33 | { 34 | stringstream ss(str); 35 | ss >> this->number >> this->name >> this->grade >> this->math >> this->chinese >> this->english; 36 | } 37 | 38 | bool Student::operator==(const Student& right) const 39 | { 40 | return this->number == right.number; 41 | } 42 | 43 | bool Student::operator>(const Student& right) const 44 | { 45 | return this->number > right.number; 46 | } 47 | 48 | bool Student::operator<(const Student& right) const 49 | { 50 | return this->number < right.number; 51 | } 52 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/Student.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class Student 4 | { 5 | using uint32 = unsigned; 6 | public: 7 | Student(); 8 | Student(uint32 number); 9 | Student(uint32 number,const std::string& name,const std::string& grade, 10 | int math,int chinese,int englist); 11 | //显示信息 12 | void display(); 13 | //把学生的所有信息格式化成字符串 14 | std::string formatInfo(); 15 | void formatWrite(const std::string& str); 16 | public: 17 | bool operator==(const Student& right) const; 18 | bool operator>(const Student& right) const; 19 | bool operator<(const Student& right) const; 20 | public: 21 | uint32 number; 22 | std::string name; 23 | std::string grade; 24 | int math; 25 | int chinese; 26 | int english; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/StudentManagementSystem_CPP.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 | 16.0 23 | Win32Proj 24 | {c2171d33-e8bb-429b-b040-673f15cd181a} 25 | StudentManagementSystemCPP 26 | 10.0 27 | StudentManagementSystem 28 | 29 | 30 | 31 | Application 32 | true 33 | v142 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v142 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | MultiByte 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | true 76 | $(ReferencePath) 77 | ..\Easyx_Maye\include;$(IncludePath) 78 | ..\Easyx_Maye\lib\x86;$(LibraryPath) 79 | 80 | 81 | false 82 | 83 | 84 | true 85 | ..\Easyx_Maye\include;$(IncludePath) 86 | ..\Easyx_Maye\lib\x64;$(LibraryPath) 87 | 88 | 89 | false 90 | 91 | 92 | 93 | Level3 94 | true 95 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 96 | true 97 | 98 | 99 | Console 100 | true 101 | 102 | 103 | 104 | 105 | Level3 106 | true 107 | true 108 | true 109 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 110 | true 111 | 112 | 113 | Console 114 | true 115 | true 116 | true 117 | 118 | 119 | 120 | 121 | Level3 122 | false 123 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | stdcpplatest 126 | 127 | 128 | Console 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | true 136 | true 137 | false 138 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 139 | true 140 | stdcpp20 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/StudentManagementSystem_CPP.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/images/bk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_CPP/images/bk.png -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/images/student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_CPP/images/student.txt -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/main.cpp: -------------------------------------------------------------------------------- 1 | #include"ManageMent_gui.h" 2 | #include"Window.h" 3 | #pragma comment(lib,"Easyx_Maye.lib") 4 | #include"Table.h" 5 | #include"Timer.h" 6 | int main() 7 | { 8 | Window w(960, 640, EW_SHOWCONSOLE | EW_NOCLOSE); 9 | w.setWindowTitle("学生成绩管理系统"); 10 | 11 | ManageMent m; 12 | m.run(); 13 | 14 | return w.exec(); 15 | } -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/resource/student - 备份.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_CPP/resource/student - 备份.txt -------------------------------------------------------------------------------- /StudentManagementSystem_CPP/resource/student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_CPP/resource/student.txt -------------------------------------------------------------------------------- /StudentManagementSystem_all.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all.7z -------------------------------------------------------------------------------- /StudentManagementSystem_all/ManageMent(控制台版).cpp: -------------------------------------------------------------------------------- 1 | #include "ManageMent.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | ManageMent::ManageMent() 10 | { 11 | readData("./student.txt"); 12 | //writeData("./test.txt"); 13 | } 14 | 15 | void ManageMent::run() 16 | { 17 | menu(); 18 | while (true) 19 | { 20 | cout << "请选择>"; 21 | int op = -1; 22 | cin >> op; 23 | switch (op) 24 | { 25 | case 0: 26 | system("cls"); 27 | menu(); 28 | break; 29 | case ManageMent::ShowAll: 30 | displayAll(); 31 | break; 32 | case ManageMent::Insert: 33 | insert(); 34 | break; 35 | case ManageMent::Erase: 36 | erase(); 37 | break; 38 | case ManageMent::Modify: 39 | modify(); 40 | break; 41 | case ManageMent::Find: 42 | find(); 43 | break; 44 | case ManageMent::Sort: 45 | sort(); 46 | break; 47 | case ManageMent::Exit: 48 | writeData("./test.txt"); 49 | break; 50 | default: 51 | break; 52 | } 53 | } 54 | } 55 | 56 | void ManageMent::menu() 57 | { 58 | cout << "***** 学生成绩管理系统 *****" << endl; 59 | cout << "***** 1,查看学生 *****" << endl; 60 | cout << "***** 2,添加学生 *****" << endl; 61 | cout << "***** 3,删除学生 *****" << endl; 62 | cout << "***** 4,修改学生 *****" << endl; 63 | cout << "***** 5,查找学生 *****" << endl; 64 | cout << "***** 6,排序 *****" << endl; 65 | cout << "***** 7,退出系统 *****" << endl; 66 | cout << "***** 0,清除屏幕 *****" << endl; 67 | cout << endl; 68 | } 69 | 70 | void ManageMent::displayAll() 71 | { 72 | std::cout << this->tableHeader << endl; 73 | for (auto& val : vec_stu) 74 | { 75 | val.display(); 76 | } 77 | std::cout << "共(" << vec_stu.size() << ")条数据" << endl; 78 | } 79 | 80 | void ManageMent::insert() 81 | { 82 | Student stu; 83 | cout << "请依次输入<学号,姓名,班级,数学,语文,英语>" << endl; 84 | cin >> stu.number >> stu.name >> stu.grade >> stu.math >> stu.chinese >> stu.english; 85 | vec_stu.push_back(stu); 86 | } 87 | 88 | void ManageMent::erase() 89 | { 90 | int number = -1; 91 | cout << "请输入要删除的学生的学号>"; 92 | cin >> number; 93 | auto delIt = std::find(vec_stu.begin(), vec_stu.end(), Student(number)); 94 | if (delIt != vec_stu.end()) 95 | { 96 | vec_stu.erase(delIt); 97 | } 98 | } 99 | 100 | void ManageMent::modify() 101 | { 102 | //略 103 | } 104 | 105 | void ManageMent::find() 106 | { 107 | cout << "*** 选择查找属性 ***" << endl; 108 | cout << "*** 1,按学号查找 ***" << endl; 109 | cout << "*** 2,按姓名查找 ***" << endl; 110 | int op = -1; 111 | cout << "select>"; 112 | cin >> op; 113 | Student stu; 114 | if (op == 1) 115 | { 116 | cout << "输入学号:"; 117 | cin >> stu.number; 118 | auto findIt = std::find(vec_stu.begin(), vec_stu.end(), stu); 119 | if (findIt != vec_stu.end()) 120 | { 121 | cout << "找到咯~ "; 122 | findIt->display(); 123 | } 124 | } 125 | else 126 | { 127 | cout << "输入姓名:"; 128 | cin >> stu.name; 129 | for (Student& s : vec_stu) 130 | { 131 | if (s.name == stu.name) 132 | { 133 | cout << "找到咯~ "; 134 | s.display(); 135 | } 136 | } 137 | } 138 | } 139 | 140 | void ManageMent::sort() 141 | { 142 | //默认升序 143 | std::sort(vec_stu.begin(), vec_stu.end()); 144 | std::cout << "排序成功QAQ~" << std::endl; 145 | } 146 | 147 | void ManageMent::readData(const std::string& fileName) 148 | { 149 | fstream stream(fileName.c_str(), ios::in); 150 | if (!stream.is_open()) 151 | { 152 | cerr << fileName << " file open failed" << endl; 153 | return; 154 | } 155 | Student stu; 156 | char buf[1024] = { 0 }; 157 | //读取表头 158 | stream.getline(buf, 1024); 159 | tableHeader = buf; 160 | //读取数据 161 | while (!stream.eof()) 162 | { 163 | memset(buf, 0, sizeof(buf)); 164 | stream.getline(buf, 1024); 165 | 166 | stringstream ss(buf); 167 | ss >> stu.number >> stu.name >> stu.grade >> stu.math >> stu.chinese >> stu.english; 168 | vec_stu.push_back(stu); 169 | } 170 | stream.close(); 171 | } 172 | 173 | void ManageMent::writeData(const std::string& fileName) 174 | { 175 | fstream write(fileName.c_str(), ios::trunc | ios::out); 176 | if (!write.is_open()) 177 | { 178 | cerr << fileName << " file open failed [save]"; 179 | return; 180 | } 181 | tableHeader += '\n'; 182 | write.write(tableHeader.c_str(), tableHeader.size()); 183 | for (auto& val : vec_stu) 184 | { 185 | string info = val.formatInfo(); 186 | write.write(info.c_str(),info.size()); 187 | } 188 | write.close(); 189 | } 190 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/ManageMent(控制台版).h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Student.h" 3 | #include 4 | class ManageMent 5 | { 6 | enum Operator 7 | { 8 | ShowAll =1, 9 | Insert, 10 | Erase, 11 | Modify, 12 | Find, 13 | Sort, 14 | Exit, 15 | }; 16 | public: 17 | ManageMent(); 18 | void run(); 19 | void menu(); 20 | //显示所有学生信息 21 | void displayAll(); 22 | //添加 23 | void insert(); 24 | //删除 25 | void erase(); 26 | //修改 27 | void modify(); 28 | void find(); 29 | //排序 30 | void sort(); 31 | private: 32 | //从文件读取学生信息 33 | void readData(const std::string& fileName); 34 | //保存学生信息到文件 35 | void writeData(const std::string& fileName); 36 | public: 37 | std::string tableHeader; //表头 38 | std::vector vec_stu; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/ManageMent_gui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Student.h" 3 | #include 4 | #include 5 | #include"widgets/pushButton.h" 6 | #include"widgets/Table.h" 7 | #include"widgets/LineEdit.h" 8 | class ManageMent 9 | { 10 | enum Operator 11 | { 12 | ShowAll, 13 | Insert, 14 | Erase, 15 | Modify, 16 | Find, 17 | Exit, 18 | }; 19 | public: 20 | ManageMent(); 21 | void run(); 22 | void menu(); 23 | 24 | void eventLoop(); 25 | void drawBackground(); 26 | 27 | int mainMenu(const ExMessage& msg); 28 | //插入和删除数据时,更新一下表格 29 | void updateTableData(); 30 | //显示所有学生信息 31 | void displayAll(); 32 | //添加 33 | void insert(); 34 | //删除 35 | void erase(); 36 | //修改 37 | void modify(); 38 | //查找 39 | void find(); 40 | //排序 41 | void sort(); 42 | private: 43 | //从文件读取学生信息 44 | void readData(const std::string& fileName); 45 | //保存学生信息到文件 46 | void writeData(const std::string& fileName); 47 | public: 48 | std::string tableHeader; //表头 49 | std::vector vec_stu; 50 | int m_prevStuCnt; //上一次学生的数量 51 | 52 | std::vector menu_btns; 53 | 54 | 55 | int opt = 66; //当前所在页 56 | ExMessage m_msg; 57 | int m_key; 58 | public: 59 | Image m_bk; 60 | public://添加学生页 61 | Table m_insertTable; 62 | LineEdit m_insertEdit; //添加学生编辑框 63 | PushButton m_insertBtn; //添加学生确认按钮 64 | public://查找学生页面 65 | LineEdit* searchEdit; 66 | PushButton* searchIdBtn; 67 | PushButton* searchNameBtn; 68 | Table* searchTable; 69 | public://修改学生页 70 | LineEdit *m_modifyEdit; //添加学生编辑框 71 | std::vector m_stuEdits; 72 | std::vector::iterator m_modifyIt; //指向要修改的学生 73 | bool haveStu = false; //是否有要修改的学生 74 | bool isfirst = true; //是不是第一次查找 75 | public://删除学生页面 76 | LineEdit* delEdit; 77 | PushButton* delBtn; 78 | Table* delTable; 79 | }; 80 | 81 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/Student.cpp: -------------------------------------------------------------------------------- 1 | #include "Student.h" 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | Student::Student():number(0),math(0),chinese(0),english(0) 7 | { 8 | //memset(this,0, sizeof(Student));//不能使用这个,否则会乱码 9 | } 10 | 11 | Student::Student(uint32 number):Student() 12 | { 13 | this->number = number; 14 | } 15 | 16 | Student::Student(uint32 number, const std::string& name, const std::string& grade, int math, int chinese, int english) 17 | : number(number),name(name),grade(grade), math(math), chinese(chinese), english(english) 18 | {} 19 | 20 | void Student::display() 21 | { 22 | cout << this->number << "\t" << this->name << "\t" << this->grade << "\t" << this->math << "\t" << this->chinese << "\t" << this->english << endl; 23 | } 24 | 25 | std::string Student::formatInfo() 26 | { 27 | stringstream ss; 28 | ss<< this->number << "\t" << this->name << "\t" << this->grade << "\t" << this->math << "\t" << this->chinese << "\t" << this->english << endl; 29 | return ss.str(); 30 | } 31 | 32 | void Student::formatWrite(const std::string& str) 33 | { 34 | stringstream ss(str); 35 | ss >> this->number >> this->name >> this->grade >> this->math >> this->chinese >> this->english; 36 | } 37 | 38 | bool Student::operator==(const Student& right) const 39 | { 40 | return this->number == right.number; 41 | } 42 | 43 | bool Student::operator>(const Student& right) const 44 | { 45 | return this->number > right.number; 46 | } 47 | 48 | bool Student::operator<(const Student& right) const 49 | { 50 | return this->number < right.number; 51 | } 52 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/Student.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class Student 4 | { 5 | using uint32 = unsigned; 6 | public: 7 | Student(); 8 | Student(uint32 number); 9 | Student(uint32 number,const std::string& name,const std::string& grade, 10 | int math,int chinese,int englist); 11 | //显示信息 12 | void display(); 13 | //把学生的所有信息格式化成字符串 14 | std::string formatInfo(); 15 | void formatWrite(const std::string& str); 16 | public: 17 | bool operator==(const Student& right) const; 18 | bool operator>(const Student& right) const; 19 | bool operator<(const Student& right) const; 20 | public: 21 | uint32 number; 22 | std::string name; 23 | std::string grade; 24 | int math; 25 | int chinese; 26 | int english; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/StudentManagementSystem_all.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31911.196 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StudentManagementSystem_all", "StudentManagementSystem_all.vcxproj", "{35A2C069-E7AF-4810-B378-B9E8540AD124}" 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 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Debug|x64.ActiveCfg = Debug|x64 17 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Debug|x64.Build.0 = Debug|x64 18 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Debug|x86.ActiveCfg = Debug|Win32 19 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Debug|x86.Build.0 = Debug|Win32 20 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Release|x64.ActiveCfg = Release|x64 21 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Release|x64.Build.0 = Release|x64 22 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Release|x86.ActiveCfg = Release|Win32 23 | {35A2C069-E7AF-4810-B378-B9E8540AD124}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {506CFED1-BF2D-4326-BD2F-B4694BF26956} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/StudentManagementSystem_all.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 | 16.0 23 | Win32Proj 24 | {35a2c069-e7af-4810-b378-b9e8540ad124} 25 | StudentManagementSystemall 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/StudentManagementSystem_all.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 | {ca1c2ba0-e6ed-406a-8fad-12ab1e24bb11} 18 | 19 | 20 | {9a403654-8a46-4876-bff8-9b9f282a00e3} 21 | 22 | 23 | {2b587b3c-3a1a-4173-b36a-dffce544bcf2} 24 | 25 | 26 | {ccab1ea6-c6c0-4aab-aa8d-1c5dd959c54e} 27 | 28 | 29 | 30 | 31 | 源文件\widgets\commonutils 32 | 33 | 34 | 源文件\widgets\commonutils 35 | 36 | 37 | 源文件 38 | 39 | 40 | 源文件 41 | 42 | 43 | 源文件 44 | 45 | 46 | 源文件\widgets 47 | 48 | 49 | 源文件\widgets 50 | 51 | 52 | 源文件\widgets 53 | 54 | 55 | 源文件\widgets 56 | 57 | 58 | 源文件\widgets 59 | 60 | 61 | 源文件\widgets 62 | 63 | 64 | 源文件\widgets 65 | 66 | 67 | 源文件\widgets 68 | 69 | 70 | 71 | 72 | 头文件\widgets\commonutils 73 | 74 | 75 | 头文件\widgets\commonutils 76 | 77 | 78 | 头文件\widgets\commonutils 79 | 80 | 81 | 头文件\widgets 82 | 83 | 84 | 头文件\widgets 85 | 86 | 87 | 头文件\widgets 88 | 89 | 90 | 头文件\widgets 91 | 92 | 93 | 头文件\widgets 94 | 95 | 96 | 头文件\widgets 97 | 98 | 99 | 头文件\widgets 100 | 101 | 102 | 头文件\widgets 103 | 104 | 105 | 头文件\widgets 106 | 107 | 108 | 头文件 109 | 110 | 111 | 头文件 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/StudentManagementSystem_all.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/images/bk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all/images/bk.png -------------------------------------------------------------------------------- /StudentManagementSystem_all/images/student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all/images/student.txt -------------------------------------------------------------------------------- /StudentManagementSystem_all/main.cpp: -------------------------------------------------------------------------------- 1 | #include"ManageMent_gui.h" 2 | #include"widgets/Window.h" 3 | #include"widgets/Table.h" 4 | #include"widgets/Timer.h" 5 | int main() 6 | { 7 | Window w(960, 640, EW_SHOWCONSOLE | EW_NOCLOSE); 8 | w.setWindowTitle("学生成绩管理系统"); 9 | 10 | ManageMent m; 11 | m.run(); 12 | 13 | return w.exec(); 14 | } -------------------------------------------------------------------------------- /StudentManagementSystem_all/resource/student - 备份.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all/resource/student - 备份.txt -------------------------------------------------------------------------------- /StudentManagementSystem_all/resource/student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all/resource/student.txt -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/BasicWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BasicWidget.h" 2 | 3 | BasicWidget::BasicWidget(int x, int y, int w, int h) 4 | :m_x(x),m_y(y),m_w(w),m_h(h),m_bkColor(),m_font("黑体") 5 | { 6 | m_font.setHeight(20); 7 | m_font.setQuality(PROOF_QUALITY); 8 | settextstyle((LOGFONT*)&m_font); 9 | settextcolor(m_font.color().toRgb()); 10 | 11 | } 12 | 13 | int BasicWidget::width() const 14 | { 15 | return m_w; 16 | } 17 | 18 | int BasicWidget::height() const 19 | { 20 | return m_h; 21 | } 22 | 23 | void BasicWidget::setFixedSize(int w, int h) 24 | { 25 | this->m_w = w; 26 | this->m_h = h; 27 | } 28 | 29 | int BasicWidget::x() const 30 | { 31 | return m_x; 32 | } 33 | 34 | int BasicWidget::y() const 35 | { 36 | return m_y; 37 | } 38 | 39 | void BasicWidget::move(int x, int y) 40 | { 41 | this->m_x = x; 42 | this->m_y = y; 43 | } 44 | 45 | 46 | void BasicWidget::setBackgroundColor(const Color& color) 47 | { 48 | m_bkColor = color; 49 | } 50 | 51 | Color BasicWidget::BackgroundColor() 52 | { 53 | return m_bkColor; 54 | } 55 | 56 | void BasicWidget::setFont(const Font& font) 57 | { 58 | m_font = font; 59 | } 60 | 61 | const Font& BasicWidget::font() 62 | { 63 | return m_font; 64 | } 65 | 66 | void BasicWidget::show() 67 | { 68 | settextstyle((LOGFONT*)&m_font); 69 | settextcolor(m_font.color()); 70 | } 71 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/BasicWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | #include"commonutils/Color.h" 4 | class BasicWidget 5 | { 6 | public: 7 | BasicWidget(int x, int y, int w, int h); 8 | int width() const; 9 | int height()const; 10 | void setFixedSize(int w, int h); 11 | 12 | int x()const; 13 | int y()const; 14 | void move(int x, int y); 15 | 16 | //未实现 17 | void setBackgroundColor(const Color& color); 18 | Color BackgroundColor(); 19 | 20 | void setFont(const Font& font); 21 | const Font& font(); 22 | virtual void show(); 23 | protected: 24 | int m_x; 25 | int m_y; 26 | int m_w; 27 | int m_h; 28 | 29 | Color m_bkColor; //背景颜色 30 | Font m_font; //字体 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Configure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #undef UNICODE 5 | #endif // UNICODE 6 | 7 | #ifdef _DEBUG 8 | #include 9 | #define plog printf 10 | #else 11 | #define plog 12 | #endif // DEBUG 13 | 14 | #include 15 | #include 16 | #include"Timer.h" 17 | #include"commonutils/Font.h" 18 | 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Image.cpp: -------------------------------------------------------------------------------- 1 | #include "Image.h" 2 | #include"Window.h" 3 | 4 | Image::Image():x(0),y(0),pMaskImg(nullptr) 5 | { 6 | 7 | } 8 | 9 | Image::Image(const std::string& imgPath, int w, int h): Image() 10 | { 11 | ::loadimage(this, imgPath.c_str(), w, h); 12 | if (this->getwidth() == 0 && this->getheight() == 0) 13 | { 14 | plog("[error] %s load failed\n", imgPath.c_str()); 15 | } 16 | } 17 | 18 | Image::Image(const std::string& maskImgPath, const std::string& srcImgPath, int w, int h) 19 | :pMaskImg(new Image(maskImgPath,w,h)) 20 | { 21 | ::loadimage(this, srcImgPath.c_str(), w, h); 22 | if (this->getwidth() == 0 && this->getheight() == 0) 23 | { 24 | plog("[error] %s load failed\n", srcImgPath.c_str()); 25 | } 26 | } 27 | 28 | Image::Image(const std::string& prefixPath, const std::string& maskImgPath, const std::string& srcImgPath, int w, int h) 29 | :Image(prefixPath+maskImgPath, prefixPath+srcImgPath,w,h) 30 | { 31 | } 32 | 33 | void Image::draw() 34 | { 35 | putimage_alapha(this->x, this->y, this); 36 | } 37 | 38 | void Image::draw(DWORD maskdwRop,DWORD srcdwRop) 39 | { 40 | ::putimage(this->x, this->y, pMaskImg, maskdwRop); 41 | ::putimage(this->x, this->y, this, srcdwRop); 42 | } 43 | 44 | void Image::move(int x, int y) 45 | { 46 | this->x = x; 47 | this->y = y; 48 | } 49 | 50 | void Image::save(const std::string& savePath) 51 | { 52 | ::saveimage(savePath.c_str(), this); 53 | } 54 | 55 | void Image::save(const std::string& savePath, Image* img) 56 | { 57 | ::saveimage(savePath.c_str(), img); 58 | } 59 | 60 | Image* Image::getimage(int x, int y, int w, int h) 61 | { 62 | Image* img = new Image; 63 | ::getimage(img, x, y, w, h); 64 | return img; 65 | } 66 | 67 | DWORD* Image::ImageBuffer() 68 | { 69 | return ::GetImageBuffer(this); 70 | } 71 | 72 | void Image::SetDefault() 73 | { 74 | } 75 | 76 | 77 | 78 | /*@私有成员*/ 79 | //png图片透明贴图 80 | void Image::putimage_alapha(int x, int y, IMAGE* src) 81 | { 82 | // 变量初始化 83 | DWORD* pwin = GetImageBuffer(); //窗口缓冲区指针 84 | DWORD* psrc = GetImageBuffer(src); //图片缓冲区指针 85 | int win_w = Window::width(); //窗口宽高 86 | int win_h = Window::height(); 87 | int src_w = src->getwidth(); //图片宽高 88 | int src_h = src->getheight(); 89 | 90 | // 计算贴图的实际长宽 91 | int real_w = (x + src_w > win_w) ? win_w - x : src_w; // 处理超出右边界 92 | int real_h = (y + src_h > win_h) ? win_h - y : src_h; // 处理超出下边界 93 | if (x < 0) { psrc += -x; real_w -= -x; x = 0; } // 处理超出左边界 94 | if (y < 0) { psrc += (src_w * -y); real_h -= -y; y = 0; } // 处理超出上边界 95 | 96 | 97 | // 修正贴图起始位置 98 | pwin += (win_w * y + x); 99 | 100 | // 实现透明贴图 101 | for (int iy = 0; iy < real_h; iy++) 102 | { 103 | for (int ix = 0; ix < real_w; ix++) 104 | { 105 | byte a = (byte)(psrc[ix] >> 24);//计算透明通道的值[0,256) 0为完全透明 255为完全不透明 106 | if (a > 100) 107 | { 108 | pwin[ix] = psrc[ix]; 109 | } 110 | } 111 | //换到下一行 112 | pwin += win_w; 113 | psrc += src_w; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | class Image :public IMAGE 4 | { 5 | public: 6 | Image(); 7 | Image(const std::string& imgPath,int w = 0,int h =0); 8 | //example: Image("./res/images/jumpMask.jpg","./res/images/jumpSrc.jpg") 9 | Image(const std::string& maskImgPath, const std::string& srcImgPath,int w = 0,int h =0); 10 | //example: Image("./res/images/","jumpMask.jpg","jumpSrc.jpg") 11 | Image(const std::string& prefixPath,const std::string& maskImgPath, const std::string& srcImgPath,int w = 0,int h = 0); 12 | void draw(); 13 | void draw(DWORD maskdwRop, DWORD srcdwRop); 14 | void move(int x, int y); 15 | 16 | void save(const std::string& savePath); 17 | static void save(const std::string& savePath, Image* img); 18 | Image* getimage(int x, int y, int w, int h); 19 | 20 | DWORD* ImageBuffer(); // 获取绘图设备的显存指针 21 | 22 | private: 23 | void SetDefault() override; // 设置为默认状态 24 | static void putimage_alapha(int x, int y, IMAGE* src); 25 | 26 | int x; 27 | int y; 28 | private://使用掩码图透明贴图 29 | Image *pMaskImg; 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/LineEdit.cpp: -------------------------------------------------------------------------------- 1 | #include "LineEdit.h" 2 | #include"Window.h" 3 | #include 4 | 5 | LineEdit::LineEdit(int x, int y, int w, int h) 6 | :BasicWidget(x, y, w, h), textw(2), m_isPopUp(false) 7 | , m_title("请输入") 8 | { 9 | 10 | } 11 | 12 | void LineEdit::show() 13 | { 14 | BasicWidget::show(); 15 | setfillcolor(RGB(232, 232, 236)); 16 | fillrectangle(m_x, m_y, m_x+m_w, m_y+m_h); 17 | 18 | if (!m_hideCursor) 19 | { 20 | //闪烁的小竖线 21 | setlinecolor(RED); 22 | line(m_x + textw + 2, m_y + 2, m_x + textw + 2, m_y + m_h - 2); 23 | } 24 | //把文字输出到edit上 25 | outtextxy(m_x, m_y+(m_h - textheight(m_text.c_str())) / 2,m_text.c_str()); 26 | 27 | 28 | if (m_isPopUp) 29 | { 30 | m_pretext = m_text; 31 | popInputBox(); 32 | m_isPopUp = false; 33 | } 34 | } 35 | void LineEdit::eventLoop(const ExMessage& msg) 36 | { 37 | //判断是否需要弹出输入框 38 | if (msg.x > m_x && msg.x < m_x + m_w && msg.y > m_y && msg.y < m_y + m_h 39 | && msg.message == WM_LBUTTONDOWN) 40 | { 41 | m_isPopUp = true; 42 | } 43 | } 44 | void LineEdit::popInputBox() 45 | { 46 | char str[128] = { 0 }; 47 | InputBox(str, 128, nullptr,m_title.c_str(),m_text.c_str()); 48 | m_text = str; 49 | textw = ::textwidth(m_text.c_str()); 50 | } 51 | void LineEdit::setInputBoxTitle(const std::string& title) 52 | { 53 | m_title = title; 54 | } 55 | 56 | void LineEdit::setText(const std::string& text) 57 | { 58 | m_text = text; 59 | textw = ::textwidth(m_text.c_str()); 60 | } 61 | 62 | std::string LineEdit::text() 63 | { 64 | return m_text; 65 | } 66 | 67 | void LineEdit::clear() 68 | { 69 | m_text.clear(); 70 | textw = 0; 71 | } 72 | 73 | void LineEdit::setCursorHide(bool isHide) 74 | { 75 | m_hideCursor = isHide; 76 | } 77 | 78 | bool LineEdit::textChanged() 79 | { 80 | if (m_pretext == m_text) 81 | { 82 | return false; 83 | } 84 | m_pretext = m_text; //更新,通知一次文本改变即可 85 | return true; 86 | } 87 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/LineEdit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"BasicWidget.h" 3 | #include 4 | #pragma comment(lib,"Imm32.lib") 5 | class LineEdit:public BasicWidget 6 | { 7 | public: 8 | LineEdit(int x = 0, int y = 0, int w = 100, int h = 30); 9 | void show(); 10 | 11 | void eventLoop(const ExMessage& msg); 12 | 13 | //弹出数据输入框 14 | void popInputBox(); 15 | void setInputBoxTitle(const std::string& title); 16 | void setText(const std::string&text); 17 | std::string text(); 18 | void clear(); 19 | void setCursorHide(bool isHide); 20 | //文本是否改变了 21 | bool textChanged(); 22 | private: 23 | std::string m_pretext; //上一次的文字 24 | std::string m_text; //行编辑器中的文字 25 | int textw; 26 | 27 | std::string m_title; //行编辑器弹出窗标题 28 | bool m_hideCursor = false; //是否显示光标 29 | bool m_isPopUp; //是否弹出 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Table.cpp: -------------------------------------------------------------------------------- 1 | #include "Table.h" 2 | #include 3 | using namespace std; 4 | Table::Table(int row, int col) 5 | :m_rows(row), m_cols(col), m_curPage(0), m_maxPage(0) 6 | ,BasicWidget(0,0,0,0) 7 | { 8 | m_prevPageBtn.setText("上一页"); 9 | m_nextPageBtn.setText("下一页"); 10 | m_beginPageBtn.setText("第一页"); 11 | m_endPageBtn.setText("结尾页"); 12 | 13 | } 14 | 15 | void Table::setRowCount(int row) 16 | { 17 | m_rows = row; 18 | } 19 | 20 | void Table::setColCount(int col) 21 | { 22 | m_cols = col; 23 | } 24 | 25 | 26 | void Table::setHeader(const std::string& data) 27 | { 28 | m_header = data; 29 | m_cols = std::count(m_header.begin(), m_header.end(), '\t') - 1; 30 | 31 | 32 | int textw = ::textwidth("计算机1401"); 33 | int texth = ::textheight(m_header.c_str()); 34 | 35 | m_gridw = textw + 15; 36 | m_gridh = texth + 10; 37 | 38 | //设置从父类继承过来的宽度和高度 39 | m_h = m_rows * m_gridh; 40 | m_w = m_cols* m_gridw; 41 | } 42 | 43 | void Table::insert(const std::string& data) 44 | { 45 | m_datas.push_back(data); 46 | updateData(); 47 | } 48 | 49 | void Table::clear() 50 | { 51 | m_datas.clear(); 52 | updateData(); 53 | } 54 | 55 | void Table::eventLoop(const ExMessage& msg) 56 | { 57 | m_prevPageBtn.eventLoop(msg); 58 | m_nextPageBtn.eventLoop(msg); 59 | m_beginPageBtn.eventLoop(msg); 60 | m_endPageBtn.eventLoop(msg); 61 | 62 | if (m_prevPageBtn.isClicked()) 63 | { 64 | //cout << "m_prevPageBtn" << endl; 65 | if (m_curPage != 0) 66 | { 67 | m_curPage--; 68 | } 69 | //cout << "m_extraData:" << m_extraData << endl; 70 | } 71 | if (m_nextPageBtn.isClicked()) 72 | { 73 | //cout << "m_nextPageBtn" << endl; 74 | if (m_curPage != m_maxPage) 75 | { 76 | m_curPage++; 77 | } 78 | } 79 | if (m_beginPageBtn.isClicked()) 80 | { 81 | m_curPage = 0; 82 | //cout << "m_beginPageBtn" << endl; 83 | } 84 | if (m_endPageBtn.isClicked()) 85 | { 86 | m_curPage = m_maxPage; 87 | //cout << "m_endPageBtn" << endl; 88 | } 89 | //cout << "m_curPage:" << m_curPage << "/" << m_maxPage << endl; 90 | } 91 | 92 | void Table::drawTableGrid() 93 | { 94 | if (m_rows == 0) 95 | { 96 | m_rows = m_datas.size(); 97 | } 98 | drawHeader(); 99 | setlinestyle(PS_SOLID, 1); 100 | //表格横线 101 | for (size_t i = 0; i < m_rows + 1; i++) 102 | { 103 | //m_x + m_cols * textw 表格的总宽度 104 | int resy = m_y + m_gridh * i; 105 | line(m_x, resy, m_x + m_cols * m_gridw, resy); 106 | } 107 | //表格竖线 108 | for (size_t k = 0; k < m_cols+1; k++) 109 | { 110 | line(m_x + k * m_gridw, m_y, m_x + k * m_gridw, m_y + m_gridh * m_rows); 111 | } 112 | 113 | if (m_maxPage > 0) 114 | { 115 | initPageBtnPos(); 116 | } 117 | } 118 | 119 | void Table::drawTableText() 120 | { 121 | //防止越界 122 | if (m_rows > m_datas.size() &&m_datas.size()!=0) 123 | { 124 | m_rows = m_datas.size(); 125 | } 126 | 127 | int begPos = m_curPage * m_rows; //当前页数*每页行数,获取当前页在m_datas中的数据下标 128 | int endPos = m_rows + m_curPage * m_rows; //上面的数据加上 每行的行数,获取一页的数据 129 | //如果是最后一页,只遍历余下的数据 130 | if (m_curPage == m_maxPage) 131 | { 132 | endPos = begPos + m_extraData; 133 | } 134 | //如果没有数据,不输出 135 | if (m_datas.size() == 0) 136 | { 137 | endPos = 0; 138 | } 139 | 140 | for (int beg = begPos,i =0; beg < endPos; beg++,i++) 141 | { 142 | std::vector line_data = split(m_datas[beg]); 143 | 144 | for (size_t k = 0; k < line_data.size(); k++) 145 | { 146 | int tx = m_x + k * m_gridw; 147 | int ty = m_y + i * m_gridh; 148 | BasicWidget::show(); 149 | outtextxy(tx,ty+5, line_data[k].c_str()); 150 | } 151 | } 152 | } 153 | 154 | void Table::drawHeader() 155 | { 156 | //绘制表头表格 157 | setlinestyle(PS_SOLID, 2); 158 | rectangle(m_x, m_y - 30, m_x + m_gridw * m_cols, m_y); 159 | for (size_t i = 0; i < m_cols + 1; i++) 160 | { 161 | line(m_x + i * m_gridw, m_y - 30, m_x + i * m_gridw, m_y); 162 | } 163 | //绘制表头数据 164 | std::vector header = split(m_header); 165 | for (auto it = header.begin(); it != header.end();) 166 | { 167 | if (it->empty()) 168 | { 169 | it = header.erase(it); 170 | } 171 | else 172 | { 173 | it++; 174 | } 175 | } 176 | int space = 0; 177 | for (size_t i = 0; i < header.size(); i++) 178 | { 179 | space = (m_gridw - textwidth(header[i].c_str())) / 2; //居中显示表头,计算两边的间隔 180 | outtextxy(m_x + i * m_gridw + space, m_y - m_gridh+5, header[i].c_str()); 181 | } 182 | } 183 | 184 | void Table::updateData() 185 | { 186 | //计算最大页数 187 | if (m_rows >= m_datas.size()) 188 | { 189 | m_maxPage = 0; 190 | m_extraData = m_datas.size(); 191 | } 192 | else 193 | { 194 | m_extraData = m_datas.size() % m_rows; //计算余下多少条数据 195 | m_maxPage = m_datas.size() / m_rows; 196 | } 197 | } 198 | 199 | void Table::initPageBtnPos() 200 | { 201 | m_prevPageBtn.move(m_x, m_y + m_gridh * m_rows + 20); 202 | m_nextPageBtn.move(m_x + 100, m_y + m_gridh * m_rows + 20); 203 | m_beginPageBtn.move(m_x + 200, m_y + m_gridh * m_rows + 20); 204 | m_endPageBtn.move(m_x + 300, m_y + m_gridh * m_rows + 20); 205 | 206 | m_prevPageBtn.show(); 207 | m_nextPageBtn.show(); 208 | m_beginPageBtn.show(); 209 | m_endPageBtn.show(); 210 | 211 | std::string pageInfo("共" + std::to_string(m_maxPage + 1) + "页,第" + std::to_string(m_curPage + 1) + "页"); 212 | outtextxy(m_x + 450, m_y + m_gridh * m_rows + 20, pageInfo.c_str()); 213 | } 214 | 215 | std::vector Table::split(std::string str,char separator) 216 | { 217 | std::vector res; 218 | for (size_t pos = 0; pos != std::string::npos ; ) 219 | { 220 | if (pos != 0) 221 | pos++; 222 | //以指定的字符分隔 223 | pos = str.find(separator); 224 | //保存分隔出来的字符串 225 | res.push_back(str.substr(0, pos)); 226 | //剩下未分隔的字符串 227 | str = std::string(str.data() + pos+1); 228 | } 229 | return res; 230 | } 231 | 232 | void Table::show() 233 | { 234 | BasicWidget::show(); 235 | drawTableGrid(); 236 | drawTableText(); 237 | } 238 | 239 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Table.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"BasicWidget.h" 3 | #include"pushButton.h" 4 | #include 5 | class Table :public BasicWidget 6 | { 7 | public: 8 | Table(int row = 1, int col = 0); 9 | void setRowCount(int row); 10 | void setColCount(int col); 11 | 12 | //插入以\t分隔的字符串数据 13 | void setHeader(const std::string& data); 14 | void insert(const std::string& data); 15 | void clear(); 16 | 17 | void eventLoop(const ExMessage& msg); 18 | 19 | 20 | void show(); 21 | std::vector split(std::string str, char separator = '\t'); 22 | private: 23 | void drawTableGrid(); 24 | void drawTableText(); 25 | void drawHeader(); 26 | void updateData(); //更新数据 27 | 28 | //初始化换页按钮位置 29 | void initPageBtnPos(); 30 | 31 | private: 32 | size_t m_rows; 33 | size_t m_cols; 34 | 35 | int m_gridw; 36 | int m_gridh; 37 | 38 | std::string m_header; 39 | std::vector m_datas; 40 | private: //换页处理 41 | int m_curPage; //当前页 42 | int m_maxPage; //总页数 43 | int m_extraData; //如果不是整数页,那么保存一下最后一页有多少条数据 44 | 45 | PushButton m_prevPageBtn; //上一页 46 | PushButton m_nextPageBtn; //下一页 47 | PushButton m_beginPageBtn; //第一页 48 | PushButton m_endPageBtn; //末尾页 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | #include 3 | #include 4 | Timer::Timer(int64_t ms) 5 | :m_ms(ms), m_threadIsRun(false) 6 | { 7 | } 8 | 9 | void Timer::startTimer() 10 | { 11 | m_startime = high_resolution_clock::now(); 12 | 13 | m_threadIsRun = true; 14 | static std::thread thr; 15 | thr = std::thread([this]() 16 | { 17 | while (m_threadIsRun) 18 | { 19 | m_endtime = high_resolution_clock::now(); 20 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); 21 | } 22 | }); 23 | } 24 | 25 | bool Timer::timeout() 26 | { 27 | if (m_endtime - m_startime >= milliseconds(m_ms)) 28 | { 29 | m_startime = m_endtime; 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | void Timer::setTime(int64_t ms) 36 | { 37 | m_ms = ms; 38 | } 39 | 40 | void Timer::killTimer() 41 | { 42 | m_threadIsRun = false; 43 | } 44 | 45 | bool Timer::startTimer(int64_t ms, int id) 46 | { 47 | static int64_t start[21] = { 0 }; 48 | int64_t end = clock(); 49 | if (end - start[id] >= ms) 50 | { 51 | start[id] = end; 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | 58 | /*@时间间隔*/ 59 | ElapsedTimer::ElapsedTimer() : m_begin(high_resolution_clock::now()) {} 60 | void ElapsedTimer::reset() { m_begin = high_resolution_clock::now(); } 61 | //默认输出毫秒 62 | int64_t ElapsedTimer::elapsed() const 63 | { 64 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 65 | } 66 | //微秒 67 | int64_t ElapsedTimer::elapsed_micro() const 68 | { 69 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 70 | } 71 | //纳秒 72 | int64_t ElapsedTimer::elapsed_nano() const 73 | { 74 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 75 | } 76 | //秒 77 | int64_t ElapsedTimer::elapsed_seconds() const 78 | { 79 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 80 | } 81 | //分 82 | int64_t ElapsedTimer::elapsed_minutes() const 83 | { 84 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 85 | } 86 | //时 87 | int64_t ElapsedTimer::elapsed_hours() const 88 | { 89 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 90 | } -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std::chrono; 4 | /*定时器*/ 5 | class Timer 6 | { 7 | public: 8 | Timer(int64_t ms = 0); 9 | void startTimer(); 10 | bool timeout(); 11 | void setTime(int64_t ms); 12 | void killTimer(); 13 | public: 14 | //静态定时器 15 | static bool startTimer(int64_t ms, int id); 16 | //定时器的最大ID 17 | inline static size_t maxTimerID() { return 20; }; 18 | private: 19 | int64_t m_ms; //延迟毫秒数 20 | time_point m_startime; 21 | time_point m_endtime; 22 | 23 | bool m_threadIsRun; //控制线程运行 24 | }; 25 | 26 | /*时间间隔(计算运行时间)*/ 27 | class ElapsedTimer 28 | { 29 | public: 30 | ElapsedTimer(); 31 | void reset(); 32 | //默认输出毫秒 33 | int64_t elapsed() const; 34 | //微秒 35 | int64_t elapsed_micro() const; 36 | //纳秒 37 | int64_t elapsed_nano() const; 38 | //秒 39 | int64_t elapsed_seconds() const; 40 | //分 41 | int64_t elapsed_minutes() const; 42 | //时 43 | int64_t elapsed_hours() const; 44 | private: 45 | time_point m_begin; 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "Window.h" 2 | #include 3 | ExMessage Window::s_message; 4 | Window::Window(int w, int h, int flag) 5 | { 6 | handle = initgraph(w, h, flag); 7 | setbkmode(TRANSPARENT); 8 | } 9 | 10 | Window::~Window() 11 | { 12 | closegraph(); 13 | } 14 | 15 | void Window::setWindowTitle(const std::string& title) 16 | { 17 | SetWindowText(handle, title.c_str()); 18 | } 19 | 20 | void Window::setWindowColor(COLORREF c) 21 | { 22 | ::setbkcolor(c); 23 | clear(); 24 | } 25 | 26 | void Window::setCursor(LPSTR curSorStyle) 27 | { 28 | IDC_ARROW; 29 | HCURSOR hcur = LoadCursor(NULL, curSorStyle); 30 | SetClassLong(GetHWnd(), GCLP_HCURSOR, (long)hcur); 31 | } 32 | 33 | int Window::width() 34 | { 35 | return ::getwidth(); 36 | } 37 | 38 | int Window::height() 39 | { 40 | return ::getheight(); 41 | } 42 | 43 | void Window::clear() 44 | { 45 | ::cleardevice(); 46 | } 47 | 48 | void Window::beginDraw() 49 | { 50 | ::BeginBatchDraw(); 51 | } 52 | 53 | void Window::flushDraw() 54 | { 55 | ::FlushBatchDraw(); 56 | } 57 | 58 | void Window::endDraw() 59 | { 60 | ::EndBatchDraw(); 61 | } 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Configure.h" 3 | #include 4 | 5 | /*@setCursor光标样式名字 6 | IDC_ARROW, //正常 7 | IDC_IBEAM, //工 8 | IDC_WAIT, //○ 9 | IDC_CROSS, //十 10 | IDC_UPARROW, //↑ 11 | IDC_SIZE, //???? 12 | IDC_ICON, //???? 13 | IDC_SIZENWSE,//左上角缩放 14 | IDC_SIZENESW,//右上角缩放 15 | IDC_SIZEWE, //左右 16 | IDC_SIZENS, //上下 17 | IDC_SIZEALL, //带箭头的十 18 | IDC_NO //(X) 19 | */ 20 | 21 | class Window 22 | { 23 | public: 24 | Window(int w, int h,int flag = 0); 25 | ~Window(); 26 | void setWindowTitle(const std::string& title); 27 | void setWindowColor(COLORREF c); 28 | void setCursor(LPSTR curSorStyle); 29 | inline int exec() { system("pause"); return 0; }; 30 | public://static 31 | static int width(); 32 | static int height(); 33 | static void clear(); 34 | static void beginDraw(); 35 | static void flushDraw(); 36 | static void endDraw(); 37 | 38 | inline static bool hasMsg() { return peekmessage(&s_message, EM_MOUSE | EM_KEY); } 39 | inline static const ExMessage& getMsg() { return s_message; } 40 | 41 | private: 42 | HWND handle; //当前窗口句柄 43 | static ExMessage s_message; 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/commonutils/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "Color.h" 2 | 3 | Color::Color(int rgb) 4 | { 5 | m_color = rgb; 6 | } 7 | 8 | Color::Color(uint8 r, uint8 g, uint8 b) 9 | { 10 | //m_color = ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) ) 11 | m_color = ((Dword)(((Byte)(r) | ((Word)((Byte)(g)) << 8)) | (((Dword)(Byte)(b)) << 16))); 12 | } 13 | 14 | uint32 Color::toRgb() const 15 | { 16 | return m_color; 17 | } 18 | 19 | uint32 Color::rgb(uint8 r, uint8 g, uint8 b) 20 | { 21 | return ((Dword)(((Byte)(r) | ((Word)((Byte)(g)) << 8)) | (((Dword)(Byte)(b)) << 16))); 22 | } 23 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/commonutils/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"TypeDefine.h" 3 | class Color 4 | { 5 | public: 6 | Color(int rgb = 0x000); 7 | Color(uint8 r, uint8 g, uint8 b); 8 | uint32 toRgb() const ; 9 | 10 | inline operator uint32() const 11 | { 12 | return m_color; 13 | } 14 | 15 | static uint32 rgb(uint8 r, uint8 g, uint8 b); 16 | private: 17 | uint32 m_color; 18 | public: 19 | enum ColorDef 20 | { 21 | Black = 0, 22 | Blue = 0xAA0000, 23 | Green = 0x00AA00, 24 | Cyan = 0xAAAA00, 25 | Red = 0x0000AA, 26 | Magenta = 0xAA00AA, 27 | Brown = 0x0055AA, 28 | LightGray = 0xAAAAAA, 29 | DarkGray = 0x555555, 30 | LightBlue = 0xFF5555, 31 | LightGreen = 0x55FF55, 32 | LightCyan = 0xFFFF55, 33 | LightRed = 0x5555FF, 34 | LightMagenta = 0xFF55FF, 35 | Yellow = 0x55FFFF, 36 | White = 0xFFFFFF, 37 | }; 38 | }; -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/commonutils/Font.cpp: -------------------------------------------------------------------------------- 1 | #include"Font.h" 2 | 3 | Font::Font() 4 | { 5 | } 6 | 7 | Font::Font(const std::string& family, int Weight, bool italic) 8 | { 9 | strcpy_s(lfFaceName, family.c_str()); 10 | lfWeight = Weight; 11 | lfItalic = italic; 12 | lfcolor = Color::Black; //黑色 13 | } 14 | 15 | 16 | 17 | void Font::setHeight(int height) 18 | { 19 | lfHeight = height; 20 | } 21 | 22 | void Font::setWidth(int width) 23 | { 24 | lfWidth = width; 25 | } 26 | 27 | void Font::setBold(bool enable) 28 | { 29 | 30 | } 31 | 32 | void Font::setItalic(bool enable) 33 | { 34 | lfItalic = enable; 35 | } 36 | 37 | void Font::setWeight(int weight) 38 | { 39 | lfWeight = weight; 40 | } 41 | 42 | void Font::setQuality(int Quality) 43 | { 44 | lfQuality = lfQuality; 45 | } 46 | 47 | void Font::setFamily(const std::string& family) 48 | { 49 | strcpy_s(lfFaceName, family.c_str()); 50 | } 51 | 52 | void Font::setColor(const Color& color) 53 | { 54 | lfcolor = color; 55 | } 56 | 57 | const Color& Font::color() 58 | { 59 | return lfcolor; 60 | } 61 | 62 | int Font::Height() 63 | { 64 | return lfHeight; 65 | } 66 | 67 | int Font::Width() 68 | { 69 | return lfWidth; 70 | } 71 | 72 | bool Font::Bold() 73 | { 74 | return false; 75 | } 76 | 77 | bool Font::Italic() 78 | { 79 | return lfItalic; 80 | } 81 | 82 | int Font::Weight() 83 | { 84 | return lfWeight; 85 | } 86 | 87 | int Font::Quality() 88 | { 89 | return lfQuality; 90 | } 91 | 92 | std::string Font::Family() 93 | { 94 | return lfFaceName; 95 | } 96 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/commonutils/Font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"TypeDefine.h" 3 | #include 4 | #include"Color.h" 5 | class Font 6 | { 7 | public: 8 | Font(); 9 | Font(const std::string& family, int Weight = 0, bool italic = false); 10 | 11 | void setHeight(int height); 12 | void setWidth(int width); 13 | void setBold(bool enable); 14 | void setItalic(bool enable); 15 | void setWeight(int weight); 16 | void setQuality(int Quality); 17 | void setFamily(const std::string& family); 18 | void setColor(const Color& color); 19 | 20 | const Color& color(); 21 | 22 | int Height(); 23 | int Width(); 24 | bool Bold(); 25 | bool Italic(); 26 | int Weight(); 27 | int Quality(); 28 | std::string Family(); 29 | 30 | private: 31 | int32 lfHeight = 0; //字符的平均高度 32 | int32 lfWidth = 0; //字符的平均宽度(0 表示自适应) 33 | int32 lfEscapement = 0; //字符串的书写角度(单位 0.1 度); 34 | int32 lfOrientation = 0; //每个字符的书写角度(单位 0.1 度); 35 | int32 lfWeight = 0; //字符的笔画粗细(0 表示默认粗细); 36 | Byte lfItalic = 0; //是否斜体; 37 | Byte lfUnderline = 0; //是否下划线; 38 | Byte lfStrikeOut = 0; //是否删除线 39 | Byte lfCharSet = 0; //指定字符集; 40 | Byte lfOutPrecision = 0; //指定文字的输出精度; 41 | Byte lfClipPrecision = 0; //指定文字的剪辑精度; 42 | Byte lfQuality = 0; //指定文字的输出质量; 43 | Byte lfPitchAndFamily = 0; //指定以常规方式描述字体的字体系列。 44 | char lfFaceName[32] = { 0 }; //字体名称 45 | Color lfcolor; 46 | }; -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/commonutils/TypeDefine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using uint8 = unsigned char; 4 | using uint16 = unsigned short; 5 | using uint32 = unsigned int; 6 | using uint64 = unsigned long long; 7 | 8 | using int8 = char; 9 | using int16 = short; 10 | using int32 = int; 11 | using int64 = long long; 12 | 13 | using Byte = uint8; 14 | using Word = uint16; 15 | using Dword = uint32; -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/pushButton.cpp: -------------------------------------------------------------------------------- 1 | #include "pushButton.h" 2 | 3 | 4 | PushButton::PushButton(std::string text, int x, int y, int w, int h) 5 | :text(text),BasicWidget(x,y,w,h) 6 | { 7 | memset(&_msg, 0, sizeof(ExMessage)); 8 | 9 | } 10 | 11 | void PushButton::show() 12 | { 13 | BasicWidget::show(); 14 | if (cur_img) 15 | { 16 | cur_img->draw(); 17 | } 18 | else 19 | { 20 | setlinecolor(BLACK); 21 | setfillcolor(cur_color); 22 | ::fillroundrect(m_x, m_y, m_x + m_w, m_y + m_h,10,10); 23 | } 24 | 25 | //居中显示文本 26 | int tx = m_x + (m_w - textwidth(text.data())) / 2; 27 | int ty = m_y + (m_h - textheight(text.data())) / 2; 28 | outtextxy(tx, ty, text.data()); 29 | } 30 | 31 | void PushButton::setText(std::string text) 32 | { 33 | this->text = text; 34 | } 35 | 36 | void PushButton::setBackgroundImage(std::string imgPath) 37 | { 38 | if(!nor_img) 39 | nor_img = new Image(imgPath.data(), this->m_w, this->m_h); 40 | this->cur_img = nor_img; 41 | this->show(); 42 | } 43 | 44 | void PushButton::setBackgroundColor(Color color) 45 | { 46 | this->nor_color = color; 47 | } 48 | 49 | void PushButton::setHover(COLORREF c) 50 | { 51 | h_color = c; 52 | } 53 | 54 | void PushButton::setHover(std::string imgPath) 55 | { 56 | if(!h_img) 57 | h_img = new Image(imgPath.c_str(),m_w,m_h); 58 | } 59 | 60 | void PushButton::eventLoop(const ExMessage& msg) 61 | { 62 | this->_msg = msg; 63 | if (isin()) 64 | { 65 | if (cur_img) 66 | { 67 | cur_img = h_img; 68 | } 69 | else 70 | { 71 | cur_color = h_color; 72 | } 73 | } 74 | else 75 | { 76 | if (cur_img) 77 | { 78 | cur_img = nor_img; 79 | } 80 | else 81 | { 82 | cur_color = nor_color; 83 | } 84 | 85 | } 86 | 87 | //this->show(); 88 | } 89 | 90 | bool PushButton::isin() 91 | { 92 | if (_msg.x >= m_x && _msg.x <= m_x + m_w && _msg.y >= m_y && _msg.y <= m_y+m_h) 93 | { 94 | return true; 95 | } 96 | return false; 97 | } 98 | 99 | bool PushButton::isClicked() 100 | { 101 | if (isin()) 102 | { 103 | switch (_msg.message) 104 | { 105 | case WM_LBUTTONDOWN: 106 | return true; 107 | } 108 | } 109 | return false; 110 | } 111 | 112 | PushButton::~PushButton() 113 | { 114 | } 115 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/pushButton.h: -------------------------------------------------------------------------------- 1 | /*pushButton 按钮类*/ 2 | #ifndef __PUSHBUTTON_H_ 3 | #define __PUSHBUTTON_H_ 4 | #include"Configure.h" 5 | #include"image.h" 6 | #include"BasicWidget.h" 7 | 8 | class PushButton:public BasicWidget 9 | { 10 | public: 11 | PushButton(std::string text ="PushButton",int x=0,int y=0,int w =100,int h = 30); 12 | void show(); 13 | 14 | void setText(std::string text); 15 | void setBackgroundImage(std::string imgPath); 16 | void setBackgroundColor(Color color); 17 | 18 | void setHover(COLORREF c); 19 | void setHover(std::string imgPath); 20 | //事件循环 21 | void eventLoop(const ExMessage&); 22 | 23 | //鼠标是否在按钮上面 24 | bool isin(); 25 | //鼠标是否点击了按钮 26 | bool isClicked(); 27 | 28 | 29 | ~PushButton(); 30 | 31 | public: 32 | std::string text; 33 | bool isshow = false; //显示状态 34 | ExMessage _msg; //鼠标消息 35 | public: //current 36 | Image* cur_img = nullptr; 37 | COLORREF cur_color = RGB(232, 232, 236); 38 | 39 | public: //normal 40 | Image* nor_img = nullptr; 41 | COLORREF nor_color = RGB(232, 232, 236); 42 | 43 | public: //hover 44 | Image* h_img = nullptr; 45 | COLORREF h_color = RGB(194, 195, 201); 46 | }; 47 | #endif -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/randomGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "randomGenerator.h" 2 | #include 3 | 4 | RandomGenerator::RandomGenerator(uint32_t seedValue) 5 | :m_engine(new std::default_random_engine(seedValue)) 6 | { 7 | 8 | } 9 | 10 | int RandomGenerator::bounded(int highest) 11 | { 12 | std::uniform_int_distribution intDis(0, highest-1); 13 | return intDis(*m_engine); 14 | } 15 | 16 | int RandomGenerator::bounded(int lowest, int highest) 17 | { 18 | std::uniform_int_distribution intDis(lowest, highest-1); 19 | return intDis(*m_engine); 20 | } 21 | 22 | RandomGenerator* RandomGenerator::global() 23 | { 24 | static RandomGenerator* instance = nullptr; 25 | if (instance == nullptr) 26 | { 27 | instance = new RandomGenerator((uint32_t)std::chrono::system_clock::now().time_since_epoch().count()); 28 | } 29 | return instance; 30 | } 31 | -------------------------------------------------------------------------------- /StudentManagementSystem_all/widgets/randomGenerator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/StudentManagementSystem_all/widgets/randomGenerator.h -------------------------------------------------------------------------------- /gobang/checkerBoard.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/gobang/checkerBoard.cpp -------------------------------------------------------------------------------- /gobang/checkerBoard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | struct ExMessage; 5 | #include"chessPieces.h" 6 | class CheckerBoard :public BasicWidget 7 | { 8 | public: 9 | CheckerBoard(int x,int y,int rows = 15,int cols = 15,int gridSize = 25); 10 | ~CheckerBoard(); 11 | void show(); 12 | void eventLoop(const ExMessage& msg); 13 | //判断是否连了五子棋 14 | bool judge(); 15 | public: 16 | const ExMessage* m_msg; 17 | 18 | public: //鼠标操作的坐标和下标 19 | std::vector> m_map; 20 | int whoOp; //当前是那方在下棋 21 | 22 | const int GRID_W; 23 | 24 | int m_rows; 25 | int m_cols; 26 | 27 | int opx; 28 | int opy; 29 | int opr; 30 | int opc; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /gobang/chessPieces.cpp: -------------------------------------------------------------------------------- 1 | #include "chessPieces.h" 2 | #include 3 | ChessPieces::ChessPieces() 4 | :m_x(-1), m_y(-1), m_colorPiece(None) 5 | { 6 | } 7 | ChessPieces::ChessPieces(int x, int y, ChessPieces::ColorPiece colorPiece) 8 | :m_x(x),m_y(y),m_colorPiece(colorPiece) 9 | { 10 | } 11 | 12 | void ChessPieces::draw() 13 | { 14 | switch (m_colorPiece) 15 | { 16 | case ChessPieces::None: 17 | break; 18 | case ChessPieces::Black: 19 | setfillcolor(BLACK); 20 | ::solidcircle(m_x, m_y, 10); 21 | break; 22 | case ChessPieces::White: 23 | setfillcolor(WHITE); 24 | ::solidcircle(m_x, m_y, 10); 25 | break; 26 | default: 27 | break; 28 | } 29 | 30 | } 31 | 32 | bool ChessPieces::operator==(const ChessPieces& right)const 33 | { 34 | return (m_x == right.m_x && m_y == right.m_y && m_colorPiece != ChessPieces::None); 35 | } 36 | 37 | bool ChessPieces::operator<(const ChessPieces& right)const 38 | { 39 | /* 40 | 00 01 02 03 04 05 41 | 10 11 12 13 14 15 42 | 20 21 22 23 24 25 43 | */ 44 | return (m_x * 100 + m_y < right.m_x * 100 + right.m_y); 45 | } 46 | 47 | int ChessPieces::operator[](int index) const 48 | { 49 | return m_colorPiece; 50 | } 51 | 52 | ChessPieces::operator int() 53 | { 54 | return m_colorPiece; 55 | } 56 | -------------------------------------------------------------------------------- /gobang/chessPieces.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/gobang/chessPieces.h -------------------------------------------------------------------------------- /gobang/controller.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/gobang/controller.cpp -------------------------------------------------------------------------------- /gobang/controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include"checkerBoard.h" 4 | class Controller 5 | { 6 | public: 7 | Controller(); 8 | void run(); 9 | 10 | private: 11 | Image m_bk; 12 | 13 | CheckerBoard checkerBoard; 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /gobang/gobang.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 | 16.0 23 | Win32Proj 24 | {8b7c6ae0-f434-4c35-84ca-f0351e3f375b} 25 | gobang 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ..\Easyx_Maye\include;$(IncludePath) 76 | ..\Easyx_Maye\lib\x86;$(LibraryPath) 77 | 78 | 79 | false 80 | 81 | 82 | true 83 | $(ExecutablePath) 84 | ..\Easyx_Maye\lib\x64;$(LibraryPath) 85 | ..\Easyx_Maye\include;$(IncludePath) 86 | 87 | 88 | false 89 | 90 | 91 | 92 | Level3 93 | true 94 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | 97 | 98 | Console 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | true 107 | true 108 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 109 | true 110 | 111 | 112 | Console 113 | true 114 | true 115 | true 116 | 117 | 118 | 119 | 120 | Level3 121 | true 122 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /gobang/gobang.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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 32 | 33 | 头文件 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /gobang/gobang.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /gobang/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"controller.h" 3 | #pragma comment(lib,"Easyx_Maye.lib") 4 | 5 | int main() 6 | { 7 | Window w(600, 500,EW_SHOWCONSOLE); 8 | Controller c; 9 | c.run(); 10 | 11 | return w.exec(); 12 | } -------------------------------------------------------------------------------- /gobang/resource/images/bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/gobang/resource/images/bk.jpg -------------------------------------------------------------------------------- /gobang/resource/music/G弦之歌.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/gobang/resource/music/G弦之歌.mp3 -------------------------------------------------------------------------------- /mineSweeper/controller.cpp: -------------------------------------------------------------------------------- 1 | #include "controller.h" 2 | #include 3 | 4 | Controller::Controller() 5 | :m_map(10,10), 6 | isOver(false),isWin(false) 7 | { 8 | 9 | } 10 | void Controller::run() 11 | { 12 | while (true) 13 | { 14 | mouseEvent(); 15 | m_map.draw(); 16 | if (isOver || isWin) 17 | { 18 | char text[50] = { 0 }; 19 | if (isOver) 20 | { 21 | strcpy_s(text, "你点到了雷,是否再来一把?"); 22 | } 23 | else 24 | { 25 | strcpy_s(text, "你过关了,是否再来一把?"); 26 | } 27 | //询问用户是否再来一把 28 | int ret = MessageBox(GetHWnd(), text, "提示", MB_OKCANCEL); 29 | if (ret == IDOK) 30 | { 31 | m_map.init(); 32 | isOver = false; 33 | isWin = false; 34 | } 35 | else 36 | { 37 | exit(0); 38 | } 39 | } 40 | } 41 | } 42 | 43 | void Controller::mouseEvent() 44 | { 45 | if (Window::hasMsg()) 46 | { 47 | const ExMessage& msg = Window::getMsg(); 48 | //鼠标msg 里面有x,y但是没有行和列,自己求一下 49 | int r = msg.y / 40; 50 | int c = msg.x / 40; 51 | //鼠标左键点击打开对应的格子,让数组元素-20 52 | if (msg.message == WM_LBUTTONDOWN) 53 | { 54 | if (m_map[r][c] >= 19 && m_map[r][c] <= 28) 55 | { 56 | m_map[r][c] -= 20; 57 | openNull(r, c); 58 | judge(r, c); 59 | //showMap(m_map); 60 | } 61 | } 62 | //鼠标右键标记格子 63 | else if (msg.message == WM_RBUTTONDOWN) 64 | { 65 | if (m_map[r][c] >= 19 && m_map[r][c] <= 28) //如果没有打开,也没有标记,就标记一下 66 | { 67 | m_map[r][c] += 20; 68 | //showMap(m_map); 69 | } 70 | else if (m_map[r][c] > 28) //已经标记过了,取消标记 71 | { 72 | m_map[r][c] -= 20; 73 | } 74 | } 75 | } 76 | } 77 | 78 | void Controller::openNull(int row, int col) 79 | { 80 | if (m_map[row][col] == 0) 81 | { 82 | for (int i = row - 1; i <= row + 1; i++) 83 | { 84 | for (int k = col - 1; k <= col + 1; k++) 85 | { 86 | //如果周围的格子没有被打开,就打开 87 | if ((i >= 0 && i < m_map.rows() && k >= 0 && k < m_map.cols()) && m_map[i][k] > 19 && m_map[i][k] <= 28) 88 | { 89 | m_map[i][k] -= 20; 90 | openNull(i, k); 91 | } 92 | } 93 | } 94 | } 95 | } 96 | 97 | void Controller::judge(int row, int col) 98 | { 99 | //点到了雷,游戏结束(输了) 100 | if (m_map[row][col] == -1) 101 | { 102 | for (int i = 0; i < m_map.rows(); i++) 103 | { 104 | for (int k = 0; k < m_map.cols(); k++) 105 | { 106 | //打开未标记,但没有打开的雷 107 | if (m_map[i][k] == 19) 108 | { 109 | m_map[i][k] -= 20; 110 | } 111 | //标记了的雷 112 | else if (m_map[i][k] == 39) 113 | { 114 | m_map[i][k] -= 40; 115 | } 116 | } 117 | } 118 | isOver = true; 119 | return; 120 | } 121 | //赢了,应该点开的格子都点开了,就赢了 122 | static int cnt = 0; 123 | for (int i = 0; i < m_map.rows(); i++) 124 | { 125 | for (int k = 0; k < m_map.cols(); k++) 126 | { 127 | if (m_map[i][k] >= 0 && m_map[i][k] <= 8) 128 | { 129 | cnt++; 130 | } 131 | } 132 | } 133 | 134 | if (cnt == m_map.rows() * m_map.cols() - 10) 135 | { 136 | isWin = true; 137 | } 138 | cnt = 0; 139 | } -------------------------------------------------------------------------------- /mineSweeper/controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"map.h" 3 | class Controller 4 | { 5 | enum State { None, Win, Lose }; 6 | public: 7 | Controller(); 8 | void run(); 9 | 10 | void mouseEvent(); 11 | void openNull(int row, int col); 12 | void judge(int row, int col); 13 | private: 14 | Map m_map; 15 | 16 | bool isOver; 17 | bool isWin; 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /mineSweeper/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"controller.h" 3 | #pragma comment(lib,"Easyx_Maye.lib") 4 | 5 | int main() 6 | { 7 | Window w(400,400,EW_SHOWCONSOLE); 8 | w.setWindowTitle("扫雷游戏"); 9 | 10 | Controller c; 11 | c.run(); 12 | 13 | return w.exec(); 14 | } -------------------------------------------------------------------------------- /mineSweeper/map.cpp: -------------------------------------------------------------------------------- 1 | #include "..\2048\map.h" 2 | #include "map.h" 3 | #include 4 | #include 5 | Map::Map(int rows, int cols) 6 | :m_rows(rows),m_cols(cols), 7 | m_map(new int* [rows]) 8 | { 9 | for (int i = 0; i < m_rows; i++) 10 | { 11 | m_map[i] = new int[m_cols] {0}; 12 | } 13 | init(); 14 | 15 | loadResource(); 16 | 17 | 18 | //std::unique_ptr up(new int* [], [](int*[]) {}); 19 | //std::unique_ptr up(new int*[rows], [](int** p) {}); 20 | //std::unique_ptr> up(new int* [rows], [](int** p) {}); 21 | } 22 | 23 | Map::Map() 24 | { 25 | } 26 | 27 | void Map::show() 28 | { 29 | for (int i = 0; i < 10; i++) 30 | { 31 | for (int k = 0; k < 10; k++) 32 | { 33 | std::cout << m_map[i][k] << " "; 34 | } 35 | std::cout << std::endl; 36 | } 37 | std::cout << std::endl; 38 | } 39 | 40 | void Map::draw() 41 | { 42 | for (int i = 0; i < m_rows; i++) 43 | { 44 | for (int k = 0; k < m_cols; k++) 45 | { 46 | if (m_map[i][k] >= 0 && m_map[i][k] <= 8) 47 | { 48 | putimage(k * 40, i * 40, m_imgs[m_map[i][k]]); 49 | } 50 | else if (m_map[i][k] == -1) 51 | { 52 | putimage(k * 40, i * 40, m_imgs[9]); 53 | } 54 | else if (m_map[i][k] >= 19 && m_map[i][k] <= 28) 55 | { 56 | putimage(k * 40, i * 40, m_imgs[10]); 57 | } 58 | else if (m_map[i][k] > 28) 59 | { 60 | putimage(k * 40, i * 40, m_imgs[11]); 61 | } 62 | } 63 | } 64 | } 65 | 66 | void Map::loadResource() 67 | { 68 | for (int i = 0; i < 12; i++) 69 | { 70 | std::string imgPath = "./resource/images/" + std::to_string(i) + ".jpg"; 71 | m_imgs.push_back(new Image(imgPath,40,40)); 72 | } 73 | } 74 | 75 | int Map::rows() 76 | { 77 | return m_rows; 78 | } 79 | 80 | int Map::cols() 81 | { 82 | return m_cols; 83 | } 84 | 85 | void Map::init() 86 | { 87 | for (size_t i = 0; i < m_rows; i++) 88 | { 89 | for (int k = 0; k < m_cols; k++) 90 | { 91 | m_map[i][k] = 0; 92 | } 93 | } 94 | //给数组里面随机埋雷 雷用-1表示 只要10个 95 | for (int i = 0; i < 10; ) 96 | { 97 | int r = rand() % m_rows; 98 | int c = rand() % m_cols; 99 | if (m_map[r][c] == 0) 100 | { 101 | m_map[r][c] = -1; 102 | i++; //只有成功设置了一个雷,i才会自增 103 | } 104 | } 105 | 106 | //雷周围的九宫格数字都加1(雷自己除外 -1) 107 | for (int i = 0; i < m_rows; i++) 108 | { 109 | for (int k = 0; k < m_cols; k++) 110 | { 111 | //找到每一个雷 112 | if (m_map[i][k] == -1) 113 | { 114 | //遍历雷周围的九宫格 115 | for (int r = i - 1; r <= i + 1; r++) 116 | { 117 | for (int c = k - 1; c <= k + 1; c++) 118 | { 119 | if ((r >= 0 && r < m_rows && c >= 0 && c < m_cols) && m_map[r][c] != -1) 120 | { 121 | m_map[r][c] ++; 122 | } 123 | } 124 | } 125 | 126 | } 127 | } 128 | } 129 | 130 | //加密格子 131 | for (int i = 0; i < m_rows; i++) 132 | { 133 | for (int k = 0; k < m_cols; k++) 134 | { 135 | m_map[i][k] += 20; 136 | } 137 | } 138 | } 139 | 140 | int* Map::operator[](int index) 141 | { 142 | return m_map[index]; 143 | } 144 | -------------------------------------------------------------------------------- /mineSweeper/map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | class Map 6 | { 7 | public: 8 | Map(int rows, int cols); 9 | void show(); 10 | void init(); 11 | void draw(); 12 | void loadResource(); 13 | 14 | int rows(); 15 | int cols(); 16 | 17 | //std::unique_ptr& getMap() { return m_map; } 18 | //operator std::unique_ptr& () { return m_map;} 19 | int* operator[](int index); 20 | private: 21 | std::unique_ptr m_map; 22 | std::vector m_imgs; 23 | 24 | int m_rows; 25 | int m_cols; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /mineSweeper/mineSweeper.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 | 16.0 23 | Win32Proj 24 | {61e2a3e8-c88d-4a30-8c81-30411fb7440e} 25 | mineSweeper 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ..\Easyx_Maye\include;$(IncludePath) 76 | ..\Easyx_Maye\lib\x86;$(LibraryPath) 77 | 78 | 79 | false 80 | 81 | 82 | true 83 | ..\Easyx_Maye\include;$(ExecutablePath) 84 | ..\Easyx_Maye\lib\x64;$(LibraryPath) 85 | 86 | 87 | false 88 | 89 | 90 | 91 | Level3 92 | false 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | 96 | 97 | Console 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | true 106 | true 107 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 108 | true 109 | 110 | 111 | Console 112 | true 113 | true 114 | true 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 122 | true 123 | 124 | 125 | Console 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | true 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /mineSweeper/mineSweeper.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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 头文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /mineSweeper/mineSweeper.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /mineSweeper/resource/images/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/0.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/1.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/10.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/11.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/2.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/3.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/4.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/5.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/6.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/7.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/8.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/9.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/images/9_copy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/images/9_copy.jpg -------------------------------------------------------------------------------- /mineSweeper/resource/music/click.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/music/click.wav -------------------------------------------------------------------------------- /mineSweeper/resource/music/rightClick.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/music/rightClick.wav -------------------------------------------------------------------------------- /mineSweeper/resource/music/search.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/music/search.wav -------------------------------------------------------------------------------- /mineSweeper/resource/music/start.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/mineSweeper/resource/music/start.mp3 -------------------------------------------------------------------------------- /pushBox/README.md: -------------------------------------------------------------------------------- 1 | # PushBox(推箱子) 2 | 3 | -------------------------------------------------------------------------------- /pushBox/controller.cpp: -------------------------------------------------------------------------------- 1 | #include "controller.h" 2 | #include 3 | Controller::Controller() 4 | :gamer(m), roll(m,gamer) 5 | { 6 | } 7 | 8 | void Controller::run() 9 | { 10 | loadResource(); 11 | m.setCurMap(3); 12 | while (true) 13 | { 14 | system("cls"); 15 | m.showCur(); 16 | drawMap(); 17 | 18 | if (m.isPass()) 19 | { 20 | roll.clear(); 21 | if (!m.cutNextLevel()) 22 | { 23 | settextcolor(RED); 24 | settextstyle(30, 0, "黑体"); 25 | outtextxy(20, 20, "恭喜你通关了~"); 26 | return; 27 | } 28 | } 29 | char key = _getch(); 30 | switch (key) 31 | { 32 | case ' ': 33 | roll.rollBack(); 34 | break; 35 | default: 36 | roll.saveState(key); 37 | gamer.move(key); 38 | break; 39 | } 40 | } 41 | 42 | } 43 | 44 | void Controller::loadResource() 45 | { 46 | for (size_t i = 0; i < 7; i++) 47 | { 48 | std::string path = "./resource/images/"+std::to_string(i)+".bmp"; 49 | m_imgs.push_back(new Image(path)); 50 | } 51 | } 52 | 53 | void Controller::drawMap() 54 | { 55 | for (size_t i = 0; i < m.row(); i++) 56 | { 57 | for (size_t k = 0; k < m.col(); k++) 58 | { 59 | int x = k * 64; 60 | int y = i * 64; 61 | switch (m.getCurMap()[i][k]) 62 | { 63 | case SPACE: 64 | putimage(x, y, m_imgs[0]); 65 | break; 66 | case WALL: 67 | putimage(x, y, m_imgs[1]); 68 | break; 69 | case DEST: 70 | putimage(x, y, m_imgs[2]); 71 | break; 72 | case BOX: 73 | putimage(x, y, m_imgs[3]); 74 | break; 75 | case PLAYER: 76 | putimage(x, y, m_imgs[4]); 77 | break; 78 | case BOX + DEST: 79 | putimage(x, y, m_imgs[5]); 80 | break; 81 | case PLAYER + DEST: 82 | putimage(x, y, m_imgs[6]); 83 | break; 84 | } 85 | } 86 | } 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /pushBox/controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"map.h" 3 | #include"gamer.h" 4 | #include"rollback.h" 5 | #include 6 | class Controller 7 | { 8 | public: 9 | Controller(); 10 | void run(); 11 | void loadResource(); 12 | void drawMap(); 13 | private: 14 | Map<> m; 15 | int level; 16 | std::vector m_imgs; 17 | 18 | Gamer gamer; 19 | Rollback roll; 20 | 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /pushBox/gamer.cpp: -------------------------------------------------------------------------------- 1 | #include "gamer.h" 2 | 3 | Gamer::Gamer(Map<>& map) 4 | :m_map(&map),m_row(-1),m_col(-1),m_dir(-1) 5 | { 6 | 7 | } 8 | 9 | void Gamer::updatePos() 10 | { 11 | for (int i = 0; i < m_map->row(); i++) 12 | { 13 | for (int k = 0; k < m_map->col(); k++) 14 | { 15 | if (m_map->getCurMap()[i][k] == PLAYER || m_map->getCurMap()[i][k] == PLAYER + DEST) 16 | { 17 | m_row = i; 18 | m_col = k; 19 | return; 20 | } 21 | } 22 | } 23 | } 24 | 25 | void Gamer::move(char key) 26 | { 27 | m_dir = key; 28 | int (*map)[10] = m_map->getCurMap(); 29 | updatePos(); 30 | switch (key) 31 | { 32 | case 72: 33 | //玩家的前面是空地 34 | if (map[m_row - 1][m_col] == SPACE || map[m_row - 1][m_col] == DEST) 35 | { 36 | map[m_row - 1][m_col] += PLAYER; 37 | map[m_row][m_col] -= PLAYER; 38 | } 39 | //玩家前面是箱子 40 | else if (map[m_row - 1][m_col] == BOX || map[m_row - 1][m_col] == BOX + DEST) 41 | { 42 | //箱子前面是空地 43 | if (map[m_row - 2][m_col] == SPACE || map[m_row - 2][m_col] == DEST) 44 | { 45 | map[m_row - 2][m_col] += BOX; 46 | map[m_row - 1][m_col] += (-BOX + PLAYER); 47 | map[m_row][m_col] -= PLAYER; 48 | } 49 | } 50 | break; 51 | case 80: 52 | //玩家的前面是空地 53 | if (map[m_row + 1][m_col] == SPACE || map[m_row + 1][m_col] == DEST) 54 | { 55 | map[m_row + 1][m_col] += PLAYER; 56 | map[m_row][m_col] -= PLAYER; 57 | } 58 | //玩家前面是箱子 59 | else if (map[m_row + 1][m_col] == BOX || map[m_row + 1][m_col] == BOX + DEST) 60 | { 61 | //箱子前面是空地 62 | if (map[m_row + 2][m_col] == SPACE || map[m_row + 2][m_col] == DEST) 63 | { 64 | map[m_row + 2][m_col] += BOX; 65 | map[m_row + 1][m_col] += (-BOX + PLAYER); 66 | map[m_row][m_col] -= PLAYER; 67 | } 68 | } 69 | break; 70 | case 75: 71 | //玩家的前面是空地 72 | if (map[m_row][m_col - 1] == SPACE || map[m_row][m_col - 1] == DEST) 73 | { 74 | map[m_row][m_col - 1] += PLAYER; 75 | map[m_row][m_col] -= PLAYER; 76 | } 77 | //玩家前面是箱子 78 | else if (map[m_row][m_col - 1] == BOX || map[m_row][m_col - 1] == BOX + DEST) 79 | { 80 | //箱子前面是空地 81 | if (map[m_row][m_col - 2] == SPACE || map[m_row][m_col - 2] == DEST) 82 | { 83 | map[m_row][m_col - 2] += BOX; 84 | map[m_row][m_col - 1] += (-BOX + PLAYER); 85 | map[m_row][m_col] -= PLAYER; 86 | } 87 | } 88 | break; 89 | case 77: 90 | 91 | //玩家的前面是空地 92 | if (map[m_row][m_col + 1] == SPACE || map[m_row][m_col + 1] == DEST) 93 | { 94 | printf("right\n"); 95 | map[m_row][m_col + 1] += PLAYER; 96 | map[m_row][m_col] -= PLAYER; 97 | } 98 | //玩家前面是箱子 99 | else if (map[m_row][m_col + 1] == BOX || map[m_row][m_col + 1] == BOX + DEST) 100 | { 101 | //箱子前面是空地 102 | if (map[m_row][m_col + 2] == SPACE || map[m_row][m_col + 2] == DEST) 103 | { 104 | map[m_row][m_col + 2] += BOX; 105 | map[m_row][m_col + 1] += (-BOX + PLAYER); 106 | map[m_row][m_col] -= PLAYER; 107 | } 108 | } 109 | break; 110 | } 111 | } 112 | 113 | int Gamer::row()const 114 | { 115 | return m_row; 116 | } 117 | 118 | int Gamer::col()const 119 | { 120 | return m_col; 121 | } 122 | 123 | char Gamer::dir() const 124 | { 125 | return m_dir; 126 | } 127 | -------------------------------------------------------------------------------- /pushBox/gamer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"map.h" 3 | class Gamer 4 | { 5 | public: 6 | Gamer(Map<>& map); 7 | //更新玩家位置 8 | void updatePos(); 9 | //移动玩家 10 | void move(char key); 11 | //玩家下标 12 | int row()const; 13 | int col()const; 14 | char dir()const; 15 | private: 16 | Map<>* m_map; 17 | int m_row; //玩家当前下标 18 | int m_col; 19 | char m_dir; //保存刚才移动的方向 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /pushBox/main.cpp: -------------------------------------------------------------------------------- 1 | #include"controller.h" 2 | #include 3 | #pragma comment(lib,"Easyx_Maye.lib") 4 | int main() 5 | { 6 | Window w(640,640,EW_SHOWCONSOLE); 7 | 8 | Controller c; 9 | c.run(); 10 | 11 | 12 | return w.exec(); 13 | } -------------------------------------------------------------------------------- /pushBox/map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | //using namespace std; 7 | enum MAP 8 | { 9 | SPACE = 0, //空地 10 | WALL = 1, //墙 11 | DEST = 2, //目的地 12 | BOX = 3, //箱子 13 | PLAYER = 6 //玩家 14 | }; 15 | template 16 | class Map 17 | { 18 | using Pointer = int(*)[COL]; //二维数组指针类型 19 | using MapArr = int[ROW][COL]; //二维数组 20 | 21 | public: 22 | Map(const std::string& fileName = "./resource/map.txt") :m_curLevel(0) 23 | { 24 | readFile(fileName); 25 | } 26 | void showCur() 27 | { 28 | if (m_map.empty()) 29 | { 30 | return; 31 | } 32 | for (int i = 0; i < ROW; i++) 33 | { 34 | for (int k = 0; k < COL; k++) 35 | { 36 | std::cout << m_map[m_curLevel][i][k] << " "; 37 | } 38 | std::cout << std::endl; 39 | } 40 | } 41 | void showAll() 42 | { 43 | if (m_map.empty()) 44 | { 45 | return; 46 | } 47 | for (size_t le = 0; le < m_map.size(); le++) 48 | { 49 | std::cout << "le:" << le << std::endl; 50 | for (int i = 0; i < ROW; i++) 51 | { 52 | for (int k = 0; k < COL; k++) 53 | { 54 | std::cout << m_map[le][i][k] << " "; 55 | } 56 | std::cout << std::endl; 57 | } 58 | } 59 | } 60 | //获取当前地图 61 | Pointer getCurMap() 62 | { 63 | return m_map[m_curLevel]; 64 | } 65 | Pointer operator[](int index) 66 | { 67 | if (index >= m_map.size()) 68 | { 69 | return m_map.back(); 70 | } 71 | return m_map[m_curLevel]; 72 | } 73 | //是否过关 74 | bool isPass() 75 | { 76 | for (int i = 0; i < ROW; i++) 77 | { 78 | for (int k = 0; k < COL; k++) 79 | { 80 | if (m_map[m_curLevel][i][k] == BOX) 81 | { 82 | return false; 83 | } 84 | } 85 | } 86 | return true; 87 | } 88 | //切换到下一关,切换成功返会true 否则返回false 89 | bool cutNextLevel() 90 | { 91 | if (m_curLevel < m_map.size()-1) 92 | { 93 | ++m_curLevel; 94 | return true; 95 | } 96 | return false; 97 | } 98 | //设置当前管卡 99 | void setCurMap(size_t level) 100 | { 101 | if (level >= m_map.size()) 102 | { 103 | return; 104 | } 105 | else 106 | { 107 | m_curLevel = level; 108 | } 109 | } 110 | size_t row() 111 | { 112 | return ROW; 113 | } 114 | size_t col() 115 | { 116 | return COL; 117 | } 118 | protected: 119 | void readFile(const std::string& fileName) 120 | { 121 | std::fstream read(fileName, std::ios::in); 122 | if (!read.is_open()) 123 | { 124 | std::cout << "map file open failed~" << std::endl; 125 | exit(-1); 126 | } 127 | 128 | while (!read.eof()) 129 | { 130 | char buf[50] = { 0 }; 131 | //读取关卡信息,并丢掉 132 | read.getline(buf, 50); 133 | 134 | Pointer tmap = new MapArr{ 0 }; 135 | //读Row行数据 136 | for(size_t row = 0;row m_map; 165 | int m_curLevel; //当前关卡 166 | }; 167 | 168 | -------------------------------------------------------------------------------- /pushBox/pushBox.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 | 16.0 23 | Win32Proj 24 | {e394c016-8c3c-4d35-a4bc-8fec4567a239} 25 | EasyxProject 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ../Easyx_Maye/include;$(IncludePath) 76 | ..\Easyx_Maye\lib\x86;$(LibraryPath) 77 | 78 | 79 | false 80 | ../Easyx_Maye/include;$(IncludePath) 81 | ../Easyx_Maye/lib/x86;$(LibraryPath) 82 | 83 | 84 | true 85 | $(ExecutablePath) 86 | ../Easyx_Maye/lib/x64;$(LibraryPath) 87 | ..\Easyx_Maye\include;$(IncludePath) 88 | 89 | 90 | false 91 | 92 | 93 | 94 | Level3 95 | true 96 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 97 | true 98 | stdcpplatest 99 | 100 | 101 | Console 102 | true 103 | 104 | 105 | 106 | 107 | Level3 108 | true 109 | true 110 | true 111 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | true 113 | 114 | 115 | Console 116 | true 117 | true 118 | true 119 | 120 | 121 | 122 | 123 | Level3 124 | true 125 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 126 | true 127 | 128 | 129 | Console 130 | true 131 | 132 | 133 | 134 | 135 | Level3 136 | true 137 | true 138 | true 139 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /pushBox/pushBox.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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 32 | 33 | 头文件 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | 头文件 43 | 44 | 45 | -------------------------------------------------------------------------------- /pushBox/pushBox.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /pushBox/resource/images/0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/0.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/1.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/2.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/3.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/4.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/5.bmp -------------------------------------------------------------------------------- /pushBox/resource/images/6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/images/6.bmp -------------------------------------------------------------------------------- /pushBox/resource/map.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zcmaye/easyx-Project-C_CPP/c87130da2b470a85601a373784d42c5c033f2220/pushBox/resource/map.txt -------------------------------------------------------------------------------- /pushBox/rollback.cpp: -------------------------------------------------------------------------------- 1 | #include "rollback.h" 2 | 3 | Rollback::Rollback(Map<>& map,Gamer&gamer) 4 | :map(map),gamer(gamer) 5 | { 6 | } 7 | void Rollback::rollBack() 8 | { 9 | if (s.empty()) 10 | return; 11 | State temp = s.top(); 12 | for (int i = 0; i < 3; i++) 13 | { 14 | map.getCurMap()[temp.pos[i].r][temp.pos[i].c] = temp.pos[i].data; 15 | } 16 | s.pop(); 17 | } 18 | 19 | void Rollback::saveState(char key) 20 | { 21 | int r = gamer.row(); 22 | int c = gamer.col(); 23 | State a; 24 | switch (key) 25 | { 26 | case 72: 27 | for (int i = 0, k = 0; i < 3; i++) 28 | { 29 | a.pos[i].r = r - k; 30 | a.pos[i].c = c; 31 | a.pos[i].data = map.getCurMap()[a.pos[i].r][a.pos[i].c]; 32 | k++; 33 | } 34 | s.push(a); 35 | break; 36 | case 80: 37 | for (int i = 0, k = 0; i < 3; i++) 38 | { 39 | a.pos[i].r = r + k; 40 | a.pos[i].c = c; 41 | a.pos[i].data = map.getCurMap()[a.pos[i].r][a.pos[i].c]; 42 | k++; 43 | } 44 | s.push(a); 45 | break; 46 | case 75: 47 | for (int i = 0, k = 0; i < 3; i++) 48 | { 49 | a.pos[i].r = r; 50 | a.pos[i].c = c - k; 51 | a.pos[i].data = map.getCurMap()[a.pos[i].r][a.pos[i].c]; 52 | k++; 53 | } 54 | s.push(a); 55 | break; 56 | case 77: 57 | for (int i = 0, k = 0; i < 3; i++) 58 | { 59 | a.pos[i].r = r; 60 | a.pos[i].c = c + k; 61 | a.pos[i].data = map.getCurMap()[a.pos[i].r][a.pos[i].c]; 62 | k++; 63 | } 64 | s.push(a); 65 | break; 66 | } 67 | } 68 | 69 | void Rollback::clear() 70 | { 71 | while (!s.empty()) 72 | { 73 | s.pop(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /pushBox/rollback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include"map.h" 4 | #include"gamer.h" 5 | class Rollback 6 | { 7 | public: 8 | Rollback(Map<>& map,Gamer& gamer); 9 | //一步一步回退 10 | void rollBack(); 11 | //保存上一步的状态 12 | void saveState(char key); 13 | //清空所有状态 14 | void clear(); 15 | private: 16 | struct Point 17 | { 18 | int r; 19 | int c; 20 | int data; 21 | }; 22 | struct State 23 | { 24 | struct Point pos[3]; 25 | }; 26 | std::stack s; 27 | Map<>& map; 28 | Gamer& gamer; 29 | }; 30 | 31 | --------------------------------------------------------------------------------