├── .gitattributes ├── .gitignore ├── 001.png ├── 002.png ├── 003.png ├── FightLandlord.sln ├── LICENSE ├── background.png ├── ddz.yaml ├── readme.md └── src ├── BetGame.DDZ.Robot ├── BetGame.DDZ.Robot.csproj ├── LandLord.cs ├── LandLordRobot.cs └── Robot.cs ├── BetGame.DDZ.Tests ├── BetGame.DDZ.Tests.csproj ├── GamePlayTest.cs └── UtilsTest.cs ├── BetGame.DDZ.WasmClient ├── App.razor ├── BetGame.DDZ.WasmClient.csproj ├── Model │ ├── APIReturn.cs │ ├── ClientDefaults.cs │ ├── GameInfo.cs │ ├── HandPokerInfo.cs │ └── Player.cs ├── Pages │ └── Index.razor ├── Program.cs ├── Properties │ └── launchSettings.json ├── Services │ ├── ApiService.cs │ ├── CustomAuthStateProvider.cs │ ├── FunctionHelper.cs │ ├── HttpClientExtensions.cs │ ├── LocalStorage.cs │ └── Utils.cs ├── Shared │ └── MainLayout.razor ├── _Imports.razor └── wwwroot │ ├── css │ ├── bootstrap │ │ ├── LICENSE │ │ └── dist │ │ │ ├── css │ │ │ ├── bootstrap-grid.css │ │ │ ├── bootstrap-grid.css.map │ │ │ ├── bootstrap-grid.min.css │ │ │ ├── bootstrap-grid.min.css.map │ │ │ ├── bootstrap-reboot.css │ │ │ ├── bootstrap-reboot.css.map │ │ │ ├── bootstrap-reboot.min.css │ │ │ ├── bootstrap-reboot.min.css.map │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ ├── bootstrap.min.css │ │ │ └── bootstrap.min.css.map │ │ │ └── js │ │ │ ├── bootstrap.bundle.js │ │ │ ├── bootstrap.bundle.js.map │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── bootstrap.bundle.min.js.map │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.js.map │ │ │ ├── bootstrap.min.js │ │ │ └── bootstrap.min.js.map │ ├── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ └── site.css │ ├── index.html │ ├── js │ └── websockethelper.js │ ├── poker.ttf │ └── sample-data │ └── weather.json ├── BetGame.DDZ.WebHost ├── BetGame.DDZ.WebHost.csproj ├── Common │ ├── APIReturn.cs │ ├── CustomExceptionFilter.cs │ └── GlobalExtensions.cs ├── Controllers │ └── DDZGamePlayController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ ├── index.html │ └── poker.ttf ├── BetGame.DDZ.WebHost2 ├── .config │ └── dotnet-tools.json ├── BetGame.DDZ.WebHost2.csproj ├── Common │ ├── APIReturn.cs │ ├── CustomExceptionFilter.cs │ └── GlobalExtensions.cs ├── Controllers │ └── DDZGamePlayController.cs ├── Dockerfile ├── Model │ └── Player.cs ├── Program.cs ├── Properties │ ├── PublishProfiles │ │ └── FolderProfile.pubxml │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── webhost2.db └── wwwroot.zip └── BetGame.DDZ ├── BetGame.DDZ.csproj ├── GameInfo.cs ├── GamePlay.cs ├── HandPokerInfo.cs └── Utils.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | *.VC.db 83 | 84 | # Visual Studio profiler 85 | *.psess 86 | *.vsp 87 | *.vspx 88 | *.sap 89 | 90 | # TFS 2012 Local Workspace 91 | $tf/ 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | *.DotSettings.user 100 | 101 | # JustCode is a .NET coding add-in 102 | .JustCode 103 | 104 | # TeamCity is a build add-in 105 | _TeamCity* 106 | 107 | # DotCover is a Code Coverage Tool 108 | *.dotCover 109 | 110 | # NCrunch 111 | _NCrunch_* 112 | .*crunch*.local.xml 113 | nCrunchTemp_* 114 | 115 | # MightyMoose 116 | *.mm.* 117 | AutoTest.Net/ 118 | 119 | # Web workbench (sass) 120 | .sass-cache/ 121 | 122 | # Installshield output folder 123 | [Ee]xpress/ 124 | 125 | # DocProject is a documentation generator add-in 126 | DocProject/buildhelp/ 127 | DocProject/Help/*.HxT 128 | DocProject/Help/*.HxC 129 | DocProject/Help/*.hhc 130 | DocProject/Help/*.hhk 131 | DocProject/Help/*.hhp 132 | DocProject/Help/Html2 133 | DocProject/Help/html 134 | 135 | # Click-Once directory 136 | publish/ 137 | 138 | # Publish Web Output 139 | *.[Pp]ublish.xml 140 | *.azurePubxml 141 | 142 | # TODO: Un-comment the next line if you do not want to checkin 143 | # your web deploy settings because they may include unencrypted 144 | # passwords 145 | #*.pubxml 146 | *.publishproj 147 | 148 | # NuGet Packages 149 | *.nupkg 150 | # The packages folder can be ignored because of Package Restore 151 | **/packages/* 152 | # except build/, which is used as an MSBuild target. 153 | !**/packages/build/ 154 | # Uncomment if necessary however generally it will be regenerated when needed 155 | #!**/packages/repositories.config 156 | # NuGet v3's project.json files produces more ignoreable files 157 | *.nuget.props 158 | *.nuget.targets 159 | 160 | # Microsoft Azure Build Output 161 | csx/ 162 | *.build.csdef 163 | 164 | # Microsoft Azure Emulator 165 | ecf/ 166 | rcf/ 167 | 168 | # Microsoft Azure ApplicationInsights config file 169 | ApplicationInsights.config 170 | 171 | # Windows Store app package directory 172 | AppPackages/ 173 | BundleArtifacts/ 174 | 175 | # Visual Studio cache files 176 | # files ending in .cache can be ignored 177 | *.[Cc]ache 178 | # but keep track of directories ending in .cache 179 | !*.[Cc]ache/ 180 | 181 | # Others 182 | ClientBin/ 183 | [Ss]tyle[Cc]op.* 184 | ~$* 185 | *~ 186 | *.dbmdl 187 | *.dbproj.schemaview 188 | *.pfx 189 | *.publishsettings 190 | node_modules/ 191 | orleans.codegen.cs 192 | 193 | # RIA/Silverlight projects 194 | Generated_Code/ 195 | 196 | # Backup & report files from converting an old project file 197 | # to a newer Visual Studio version. Backup files are not needed, 198 | # because we have git ;-) 199 | _UpgradeReport_Files/ 200 | Backup*/ 201 | UpgradeLog*.XML 202 | UpgradeLog*.htm 203 | 204 | # SQL Server files 205 | *.mdf 206 | *.ldf 207 | 208 | # Business Intelligence projects 209 | *.rdl.data 210 | *.bim.layout 211 | *.bim_*.settings 212 | 213 | # Microsoft Fakes 214 | FakesAssemblies/ 215 | 216 | # GhostDoc plugin setting file 217 | *.GhostDoc.xml 218 | 219 | # Node.js Tools for Visual Studio 220 | .ntvs_analysis.dat 221 | 222 | # Visual Studio 6 build log 223 | *.plg 224 | 225 | # Visual Studio 6 workspace options file 226 | *.opt 227 | 228 | # Visual Studio LightSwitch build output 229 | **/*.HTMLClient/GeneratedArtifacts 230 | **/*.DesktopClient/GeneratedArtifacts 231 | **/*.DesktopClient/ModelManifest.xml 232 | **/*.Server/GeneratedArtifacts 233 | **/*.Server/ModelManifest.xml 234 | _Pvt_Extensions 235 | 236 | # LightSwitch generated files 237 | GeneratedArtifacts/ 238 | ModelManifest.xml 239 | 240 | # Paket dependency manager 241 | .paket/paket.exe 242 | 243 | # FAKE - F# Make 244 | .fake/ -------------------------------------------------------------------------------- /001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/001.png -------------------------------------------------------------------------------- /002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/002.png -------------------------------------------------------------------------------- /003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/003.png -------------------------------------------------------------------------------- /FightLandlord.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29503.13 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetGame.DDZ", "src\BetGame.DDZ\BetGame.DDZ.csproj", "{90B92E83-C3B1-42EF-96F6-25E604B666B6}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetGame.DDZ.WebHost", "src\BetGame.DDZ.WebHost\BetGame.DDZ.WebHost.csproj", "{0EE99B29-011A-4888-96A6-35FCF6D035A6}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetGame.DDZ.Tests", "src\BetGame.DDZ.Tests\BetGame.DDZ.Tests.csproj", "{A150A79E-3557-426C-98C3-F51871C34EDE}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{7410A9CB-26AC-4DFA-862E-2A9EA1ABE603}" 13 | ProjectSection(SolutionItems) = preProject 14 | readme.md = readme.md 15 | EndProjectSection 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetGame.DDZ.WebHost2", "src\BetGame.DDZ.WebHost2\BetGame.DDZ.WebHost2.csproj", "{E910A384-9C4B-40DC-B40F-B2FF8162B374}" 18 | EndProject 19 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetGame.DDZ.WasmClient", "src\BetGame.DDZ.WasmClient\BetGame.DDZ.WasmClient.csproj", "{3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Debug|x64 = Debug|x64 25 | Debug|x86 = Debug|x86 26 | Release|Any CPU = Release|Any CPU 27 | Release|x64 = Release|x64 28 | Release|x86 = Release|x86 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|x64.ActiveCfg = Debug|Any CPU 34 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|x64.Build.0 = Debug|Any CPU 35 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|x86.ActiveCfg = Debug|Any CPU 36 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Debug|x86.Build.0 = Debug|Any CPU 37 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|x64.ActiveCfg = Release|Any CPU 40 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|x64.Build.0 = Release|Any CPU 41 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|x86.ActiveCfg = Release|Any CPU 42 | {90B92E83-C3B1-42EF-96F6-25E604B666B6}.Release|x86.Build.0 = Release|Any CPU 43 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|x64.ActiveCfg = Debug|Any CPU 46 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|x64.Build.0 = Debug|Any CPU 47 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|x86.ActiveCfg = Debug|Any CPU 48 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Debug|x86.Build.0 = Debug|Any CPU 49 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|x64.ActiveCfg = Release|Any CPU 52 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|x64.Build.0 = Release|Any CPU 53 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|x86.ActiveCfg = Release|Any CPU 54 | {0EE99B29-011A-4888-96A6-35FCF6D035A6}.Release|x86.Build.0 = Release|Any CPU 55 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|x64.ActiveCfg = Debug|Any CPU 58 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|x64.Build.0 = Debug|Any CPU 59 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|x86.ActiveCfg = Debug|Any CPU 60 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Debug|x86.Build.0 = Debug|Any CPU 61 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU 62 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|Any CPU.Build.0 = Release|Any CPU 63 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|x64.ActiveCfg = Release|Any CPU 64 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|x64.Build.0 = Release|Any CPU 65 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|x86.ActiveCfg = Release|Any CPU 66 | {A150A79E-3557-426C-98C3-F51871C34EDE}.Release|x86.Build.0 = Release|Any CPU 67 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 68 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|Any CPU.Build.0 = Debug|Any CPU 69 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|x64.ActiveCfg = Debug|Any CPU 70 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|x64.Build.0 = Debug|Any CPU 71 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|x86.ActiveCfg = Debug|Any CPU 72 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Debug|x86.Build.0 = Debug|Any CPU 73 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|Any CPU.ActiveCfg = Release|Any CPU 74 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|Any CPU.Build.0 = Release|Any CPU 75 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|x64.ActiveCfg = Release|Any CPU 76 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|x64.Build.0 = Release|Any CPU 77 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|x86.ActiveCfg = Release|Any CPU 78 | {E910A384-9C4B-40DC-B40F-B2FF8162B374}.Release|x86.Build.0 = Release|Any CPU 79 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 80 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|Any CPU.Build.0 = Debug|Any CPU 81 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|x64.ActiveCfg = Debug|Any CPU 82 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|x64.Build.0 = Debug|Any CPU 83 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|x86.ActiveCfg = Debug|Any CPU 84 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Debug|x86.Build.0 = Debug|Any CPU 85 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|Any CPU.ActiveCfg = Release|Any CPU 86 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|Any CPU.Build.0 = Release|Any CPU 87 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|x64.ActiveCfg = Release|Any CPU 88 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|x64.Build.0 = Release|Any CPU 89 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|x86.ActiveCfg = Release|Any CPU 90 | {3EE6ACCA-A673-4FD9-A0B6-0E11BD357379}.Release|x86.Build.0 = Release|Any CPU 91 | EndGlobalSection 92 | GlobalSection(SolutionProperties) = preSolution 93 | HideSolutionNode = FALSE 94 | EndGlobalSection 95 | GlobalSection(ExtensibilityGlobals) = postSolution 96 | SolutionGuid = {8BF70590-FF0A-4BE5-9EE2-8DCFB7ABEEC7} 97 | EndGlobalSection 98 | EndGlobal 99 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2018] [yexiangqin of copyright 2881099] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/background.png -------------------------------------------------------------------------------- /ddz.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: ddz.deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: ddz 10 | template: 11 | metadata: 12 | labels: 13 | app: ddz 14 | spec: 15 | containers: 16 | - name: ddz 17 | image: registry.cn-hangzhou.aliyuncs.com/xfcode/ddz:112 18 | env: 19 | - name: redis 20 | value: "redis.default.svc.cluster.local:6379" 21 | - name: imserver 22 | value: "39.106.159.180:31000" 23 | ports: 24 | - containerPort: 80 25 | --- 26 | apiVersion: v1 27 | kind: Service 28 | metadata: 29 | name: ddz 30 | labels: 31 | app: ddz 32 | spec: 33 | ports: 34 | - port: 80 35 | protocol: TCP 36 | nodePort: 31000 37 | #将设置的nodePort端口映射到宿主机上-云环境应该使用负载均衡? 38 | type: NodePort 39 | externalTrafficPolicy: Local 40 | selector: 41 | app: ddz -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # .NETCore斗地主服务端 + Blazor(WebAssembly)前端 2 | 3 | 本项目最终目标为AI斗地主,机器人最优方案对打。 4 | 5 | 声明:本项目谥在学习,任何用于违法用途的行为与作者无关。 6 | 7 | 如果对本项目感兴趣,欢迎加入QQ讨论群:8578575 8 | 9 | > 目前尚处于研阶段,为了方便测试,HTML5做成了单机方式运行,但这并不影响后期部署成多端游戏。 10 | 11 | [【在线试玩(网络版)】](http://39.106.159.180:31000/) 12 | ![](001.png) 13 | 14 | ![](003.png) 15 | 16 | # 环境依赖 17 | 18 | * .NETCore 3.1 19 | * chrome 20 | * redis-server(本地环境) 21 | 22 | # 更新 23 | 24 | * 2020-05-23 25 | 26 | 升级到3.2.0 27 | 28 | * 2020-02-12 29 | 30 | 升级到3.2.0-preview1.20073.1,并使用ClientWebSocket替换js的websocket 31 | 32 | 33 | # 已实现功能 34 | 35 | * 洗牌 36 | * 发牌 37 | * 抢地主 38 | * 斗地主(游戏环节) 39 | * 提示出牌 40 | * 游戏结束 41 | 42 | # 待现实功能 43 | 44 | * 超时机制设计(抢地主、斗地主) 45 | * 牌型分析 -------------------------------------------------------------------------------- /src/BetGame.DDZ.Robot/BetGame.DDZ.Robot.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.Robot/LandLordRobot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Threading; 5 | using ZyGames.Framework.Common.Serialization; 6 | 7 | namespace GameServer.Script.CsScript.Action 8 | { 9 | /// 10 | /// 机器人: 11 | /// 做简单的AI判断 12 | /// 13 | /// 14 | public class LandLordRobot : IBaseRobot 15 | { 16 | public int _lv; 17 | public int UserID; 18 | UserStatus _us; 19 | LandLordUser myu; 20 | 21 | public void RobotDealMSG(object UserIDandStrMSG) 22 | { 23 | object[] objArr = new object[4]; 24 | objArr = (object[])UserIDandStrMSG; 25 | int UserID = (int)objArr[0]; 26 | string strMSG = (string)objArr[1]; 27 | _us = (UserStatus)objArr[2]; 28 | myu = (LandLordUser)objArr[3]; 29 | try 30 | { 31 | RobotDealMSGEx(UserID, strMSG); 32 | } 33 | catch (Exception ex) 34 | { TraceLogEx.Error(ex, "201611122210ll"); } 35 | } 36 | /// 37 | /// 摹仿客户端 消息处理 不加锁 38 | /// 39 | /// 40 | /// 41 | private void RobotDealMSGEx(int UserID, string strMSG) 42 | { 43 | sc_base _csdata = JsonUtils.Deserialize(strMSG); 44 | if (_csdata == null) 45 | { 46 | TraceLogEx.Error(" 201206062216ll " + UserID); 47 | return; 48 | } 49 | 50 | switch (_csdata.fn) 51 | { 52 | case "sc_entertable_n": //自动 准备 53 | ////Thread.Sleep(100); 54 | ////sc_entertable_n _entertable = JsonUtils.Deserialize(strMSG); 55 | ////LandLordTable myt001 = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 56 | ////if (myt001 != null && myu._Pos == _entertable.pos) myt001.GetReady(myu._userid); // 自己的进房间通知才准备 57 | break; 58 | case "sc_ready_ll_n": 59 | break; 60 | case "sc_tablestart_ll_n": 61 | 62 | break; 63 | case "sc_cangetbanker_ll": 64 | Thread.Sleep(1100); 65 | sc_cangetbanker_ll _cangetbanker = JsonUtils.Deserialize(strMSG); 66 | LandLordTable myt_cangetbanker = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 67 | 68 | //默认AI 直接抢庄 69 | if (myt_cangetbanker != null) 70 | { 71 | if (_cangetbanker.pos == myu._Pos && !_cangetbanker.closefun) myt_cangetbanker.GetBanker(myu._userid, true); //抢庄 72 | } 73 | break; 74 | case "sc_getbanker_ll_n": // 75 | break; 76 | case "sc_canaddrate_ll_n"://处理自己的加倍情况 77 | Thread.Sleep(1500); 78 | sc_canaddrate_ll_n _canaddrate = JsonUtils.Deserialize(strMSG); 79 | LandLordTable myt_canaddrate = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 80 | 81 | //默认AI 直接加倍 82 | if (myt_canaddrate != null) 83 | { 84 | myt_canaddrate.AddRate(myu._userid, true); //加倍 85 | } 86 | break; 87 | case "sc_addrate_ll_n": 88 | break; 89 | case "sc_candiscard_ll_n": 90 | Thread.Sleep(700); 91 | sc_candiscard_ll_n _candiscard = JsonUtils.Deserialize(strMSG); 92 | LandLordTable myt_candiscard = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 93 | 94 | //默认AI 直接抢庄 95 | if (myt_candiscard != null) 96 | { 97 | if (_candiscard.pos == myu._Pos && !_candiscard.closefun) 98 | { 99 | List _DiscardMine = AIGetPai(myu, _candiscard._lastcard, myt_candiscard._judge._lastDiscardPos); 100 | if (!myt_candiscard.DisCard(myu._userid, _DiscardMine)) 101 | { 102 | TraceLogEx.Error("201702212024 fetal error " + JsonUtils.Serialize(_DiscardMine)); 103 | } 104 | } 105 | } 106 | break; 107 | case "sc_discard_ll_n": 108 | break; 109 | case "sc_end_ll_n": 110 | Thread.Sleep(1400); 111 | LandLordTable myt0014 = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 112 | if (myt0014 != null) myt0014.GetReady(myu._userid); // 113 | break; 114 | case "sc_applyexittable_n"://AI 都同意所有游戏解散 115 | Thread.Sleep(900); 116 | sc_applyexittable_n _applyExit = JsonUtils.Deserialize(strMSG); 117 | LandLordTable _applyexitTable = LandLordLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID); 118 | if (_applyexitTable != null) _applyexitTable.DealExitTable(myu._userid, true); 119 | break; 120 | case "sc_dealexittable_n": break; 121 | case "sc_exittable_n"://AI 在有人退出的情况下,全都退出 122 | 123 | break; 124 | case "sc_one_exittable_n": break; 125 | case "sc_chat_n": break; 126 | case "sc_disconnect_n": break; 127 | case "sc_warning_n": break; 128 | case "020": //此桌结束了,正常结束 129 | break; 130 | default: 131 | TraceLogEx.Error("201206190957BF AI 未处理,strSID:" + _csdata.fn); 132 | break; 133 | } 134 | } 135 | 136 | private static List AIGetPai(LandLordUser myu, List _lastDiscard, int _lastpos) 137 | { 138 | List _ret = new List(); 139 | List _lastDiscardtemp = new List(_lastDiscard); 140 | if (_lastDiscardtemp == null) _lastDiscardtemp = new List(); 141 | if (_lastpos == myu._Pos) _lastDiscardtemp = new List(); 142 | 143 | _ret = LandLord.GetTipList(myu._shouPaiArr, _lastDiscard); 144 | if (_ret.Count != 0) 145 | { 146 | LordPokerTypeEnum _ltype = LandLord.GetLordType(_ret); 147 | if (_ltype == LordPokerTypeEnum.Error) 148 | { 149 | TraceLogEx.Error("201702212024 fetal error " + JsonUtils.Serialize(myu._shouPaiArr) + "tip for" + JsonUtils.Serialize(_lastDiscard) + " LordPokerTypeEnum.Error :" + JsonUtils.Serialize(_ret)); 150 | } 151 | } 152 | return _ret; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.Robot/Robot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace BetGame.DDZ { 6 | public class RobotRecordCard { 7 | 8 | private PlayerInfo[] players; 9 | /// 10 | /// 出牌记录 11 | /// 12 | public int playerIndex { get; } = 0; 13 | public int[] dipai { get; } 14 | public List pokers { get; } 15 | public int[] initPokers { get; } 16 | 17 | public RobotRecordCard(PlayerInfo[] players, int playerIndex, IEnumerable pokers, IEnumerable dipai) { 18 | if (players == null || players.Length != 3) throw new ArgumentException("players 参数错误,长度必须为 3"); 19 | if (playerIndex < 0 || playerIndex > 2) throw new ArgumentException("playerIndex 参数错误,必须为 0,1,2"); 20 | for (var a = 0; a < players.Length; a++) players[a].playerIndex = a; 21 | this.players = players; 22 | this.playerIndex = playerIndex; 23 | this.pokers = new List(pokers); 24 | this.initPokers = pokers.ToArray(); 25 | this.dipai = dipai.ToArray(); 26 | } 27 | 28 | /// 29 | /// 计算外面的牌 30 | /// 31 | public List GetOutsideCard() { 32 | var allpokers = new List(); 33 | for (int a = 0; a < 54; a++) allpokers.Add(a); 34 | 35 | //除开自己手上的牌 36 | foreach (var p in this.pokers) allpokers.Remove(p); 37 | //除开已经打出的牌 38 | for (var a = 0; a < this.players.Length; a++) 39 | foreach (var cp in this.players[a].chupai) 40 | foreach (var p in cp.result.value) allpokers.Remove(p); 41 | return allpokers; 42 | } 43 | 44 | /// 45 | /// 计算对手可能有的牌 46 | /// 47 | /// 48 | /// 49 | public void GetPlayerProbableCard() { 50 | var ret = new Dictionary>(); 51 | var index = this.playerIndex; 52 | GetPlayerProbableCardPlayerInfo player1 = new GetPlayerProbableCardPlayerInfo { player = this.players[(++index) % 3] }; 53 | GetPlayerProbableCardPlayerInfo player2 = new GetPlayerProbableCardPlayerInfo { player = this.players[(++index) % 3] }; 54 | var cards = this.GetOutsideCard(); //外面所有的牌 55 | 56 | Func checkOver = player => { 57 | if (player.player.pokerLength - player.pokers.Count == 0) { 58 | 59 | } 60 | return false; 61 | }; 62 | 63 | if (this.players[this.playerIndex].role == GamePlayerRole.农民) { 64 | //判断底牌,确定了的牌 65 | if (player1.player.role == GamePlayerRole.地主) { 66 | foreach (var dp in this.dipai) { 67 | if (cards.Remove(dp)) { 68 | player1.pokers.Add(dp); 69 | } 70 | } 71 | } 72 | if (player2.player.role == GamePlayerRole.地主) { 73 | foreach (var dp in this.dipai) { 74 | if (cards.Remove(dp)) { 75 | player2.pokers.Add(dp); 76 | } 77 | } 78 | } 79 | } 80 | 81 | var dizhu = this.players.Where(a => a.role == GamePlayerRole.地主).First(); 82 | for(var a = 0; a < dizhu.chupai.Count; a++) { 83 | 84 | } 85 | 86 | if (this.players[this.playerIndex].role == GamePlayerRole.地主) { 87 | //我是地主,我的上家为了顶我出牌套路深,我的下家出牌逻辑较常规,可根据其计算剩余牌型 88 | } 89 | if (player1.player.role == GamePlayerRole.地主) { 90 | //我的下家是地主,地主出牌最没套路,我的上家出牌也没套路 91 | } 92 | if (player2.player.role == GamePlayerRole.地主) { 93 | //我的上家是地主,地主出牌最没牌路,我的下家(也是地主的上家)出牌会顶地主套路深 94 | 95 | } 96 | } 97 | class GetPlayerProbableCardPlayerInfo { 98 | public List pokers { get; } = new List(); 99 | public PlayerInfo player { get; set; } 100 | } 101 | 102 | /// 103 | /// 组合牌型,当机器人是地主时 104 | /// 105 | /// 106 | public List AnalysisPlan1() { 107 | //组合牌型,当机器人是地主,主动出牌时,怎么出牌能收回,或者怎么扔小牌最小合理 108 | //组合牌型,当机器人是地主,被动出牌时,怎么压死牌最合理 109 | 110 | //组合牌型,当机器人上家是地主,主动出牌时,下家能顶什么牌,地主不要什么牌 111 | //组合牌型,当机器人上家是地主,被动出牌时 112 | 113 | //组合牌型,当机器人下家是地主,主动出牌时,如果牌不好,则防止出牌让地主拖牌,否则自己逃走 114 | //组合牌型,当机器人下家是地主,被动出牌时,怎么出牌不让地主拖牌 115 | 116 | var gb = Utils.GroupByPoker(this.pokers.ToArray()).OrderBy(a => a.key).ToList(); 117 | 118 | var pks = new List(this.pokers); 119 | var hands = new List(); 120 | HandPokerComplieResult hand = null; 121 | var cards = this.GetOutsideCard(); //外面所有的牌 122 | var gbOutsize = Utils.GroupByPoker(cards.ToArray()).OrderBy(a => a.key).ToList(); 123 | 124 | var gbjks = gb.Where(a => a.count == 1 && a.key == 16 || a.key == 17).ToArray(); //王炸作为一手牌 125 | if (gbjks.Length == 2) { 126 | hand = Utils.ComplierHandPoker(gbjks); 127 | hands.Add(hand); 128 | foreach (var v in hand.value) pks.Remove(v); 129 | } 130 | 131 | //var gb1 = gb.Where(a => a.count == 1 && a.key < 15).ToList(); //所有单张 132 | //var gb2 = gb.Where(a => a.count == 2 && a.key < 15).ToList(); //所有两张 133 | //var gb3 = gb.Where(a => a.count == 3 && a.key < 15).ToList(); //所有三张 134 | 135 | //var gbLow2 = new List(); 136 | //var gbTop2 = new List(); 137 | //var gbLow2Index = gb2.Count - 1; 138 | //for (var a = gb2.Count - 1; a >= 0; a--) { 139 | // if (gbOutsize.Where(z => z.count >= 2).Any()) { 140 | // gbLow2Index = a; 141 | // break; 142 | // } 143 | // gbTop2.Add(gb2[a]); 144 | //} 145 | //gbTop2.Sort((x, y) => y.key.CompareTo(x.key)); 146 | //for (var a = 0; a < gbLow2Index; a++) { 147 | // gbLow2.Add(gb2[a]); 148 | //} 149 | 150 | 151 | //var gbLow1 = gb.Where(a => a.count == 1 && a.key < 10).ToArray(); //单张小牌,10以下 152 | //var gbLow2 = gb.Where(a => a.count == 2 && a.key < 8).ToArray(); //对子小牌,8以下 153 | //var gbMid1 = gb.Where(a => a.count == 1 && a.key >= 10 && a.key < 15).ToArray(); //单张中牌,10-A,可以穿牌 154 | //var gbMid2 = gb.Where(a => a.count == 2 && a.key >= 8 && a.key < 14).ToArray(); //对子小牌,8-K,可以穿牌 155 | 156 | //var gbHard1 = gb.Where(a => (a.count == 1 && a.key >= 10 && a.key < 15) || a.count < 4 && a.key >= 15).OrderBy(a => a.key).ToArray(); //单张硬牌,10以上 157 | //var gbHard2 = gb.Where(a => a.count == 2 && a.key >= 10).OrderBy(a => a.key).ToArray(); 158 | //var gb1 = gb.Where(a => a.count == 1 && a.key < 15).OrderBy(a => a.key).ToArray(); //所有单张 159 | //var gb2 = gb.Where(a => a.count == 2 && a.key < 15).OrderBy(a => a.key).ToArray(); //所有两张 160 | //var gb3 = gb.Where(a => a.count == 3 && a.key < 15).OrderBy(a => a.key).ToArray(); //所有三张 161 | //var gb4 = gb.Where(a => a.count == 4).OrderBy(a => a.key).ToArray(); 162 | //if (gb1.Length > 0) { //尝试组合三带一个 163 | 164 | //} 165 | 166 | //var gbseries = gb.Where(a => a.key < 15).OrderBy(a => a.key).ToArray(); 167 | //var gbseriesStartIndex = 0; 168 | //for (var a = 0; a < gbseries.Length; a++) { 169 | // var pkseries = new List(); 170 | // pkseries.AddRange(gbseries[a].poker); 171 | // for (var b = a + 1; b < gbseries.Length; b++) { 172 | // //if (gbseries[b].count < gbseries[a].count) 173 | // if (gbseries[b].key - a - 1 == gbseries[a].key) { 174 | 175 | // } 176 | // } 177 | //} 178 | //while (true) { 179 | // bool isbreak = false; 180 | // for (var a = gbseriesStartIndex + 1; a < gbseries.Length; a++) { 181 | // if (gbseries[a].key - 1 == gbseries[a - 1].key && gbseries[a].count == gbseries[a - 1].count) { 182 | // if (a == gbseries.Length - 1) { 183 | // isbreak = true; 184 | // break; 185 | // } 186 | // continue; 187 | // } 188 | // if (gbseries[a].count == 2 && a - gbseriesStartIndex >= 2) { //连对 189 | 190 | // } 191 | // if (gbseries[a].count == 1 && a - gbseriesStartIndex >= 4) { //顺子 192 | 193 | // } 194 | // gbseriesStartIndex = a; 195 | // } 196 | // if (isbreak) { 197 | 198 | // } 199 | //} 200 | //for (var a = 1; a < gbseries.Length; a++) { 201 | // if (gbseries[a].key - 1 == gbseries[a - 1].key) { 202 | 203 | // } 204 | //} 205 | 206 | var gbseries = gb.Where(a => a.key < 15).OrderBy(a => a.key).ToArray(); 207 | var gbseriesStartIndex = 0; 208 | for (var a = 1; a < gbseries.Length; a++) { 209 | if (gbseries[a].key - 1 == gbseries[a - 1].key) continue; 210 | if (a - gbseriesStartIndex >= 4) { 211 | var gbs = gb.Where((x, y) => y >= gbseriesStartIndex && y < a).ToArray(); 212 | if (gbs.Where(x => x.count == 1).Count() > gbs.Length / 2) { //顺子 213 | 214 | } 215 | } 216 | gbseriesStartIndex = a; 217 | } 218 | 219 | var gb4 = gb.Where(a => a.count == 4).ToArray(); 220 | foreach(var g4 in gb4) { 221 | hand = Utils.ComplierHandPoker(new[] { g4 }); //炸弹作为一手牌 222 | hands.Add(hand); 223 | foreach (var v in hand.value) pks.Remove(v); 224 | } 225 | var hand33 = new Stack(); //飞机 226 | var hand3 = new Stack(); //三条 227 | var gb3 = gb.Where(a => a.count == 3 && a.key < 15).OrderBy(a => a.key).ToList(); 228 | var gb3seriesStartIndex = 0; 229 | for (var a = 1; a < gb3.Count; a++) { 230 | if (Utils.IsSeries(gb3.Where((x, y) => y <= a).Select(x => x.key)) == false || a == gb3.Count - 1) { 231 | hand = Utils.ComplierHandPoker(gb3.Where((x, y) => y >= gb3seriesStartIndex && y < a)); 232 | if (hand.type == HandPokerType.飞机) hand33.Push(hand); 233 | if (hand.type == HandPokerType.三条) hand3.Push(hand); 234 | foreach (var v in hand.value) pks.Remove(v); 235 | gb3seriesStartIndex = a; 236 | } 237 | } 238 | hand = Utils.ComplierHandPoker(gb.Where(a => a.count == 3 && a.key == 15)); //三条2 239 | if (hand != null) { 240 | hand3.Push(hand); 241 | foreach (var v in hand.value) pks.Remove(v); 242 | } 243 | if (hand33.Any()) hands.AddRange(hand33.ToArray()); 244 | if (hand3.Any()) hands.AddRange(hand3.ToArray()); 245 | 246 | var hand22 = new Stack(); //连对 247 | var hand2 = new Stack(); //对 248 | var gb2 = gb.Where(a => a.count == 2 && a.key < 15).OrderBy(a => a.key).ToList(); 249 | var gb2seriesStartIndex = 0; 250 | for (var a = 2; a < gb2.Count; a++) { 251 | if (Utils.IsSeries(gb2.Where((x, y) => y <= a).Select(x => x.key)) == false || a == gb2.Count - 1) { 252 | if (a - gb2seriesStartIndex >= 3) { 253 | hand = Utils.ComplierHandPoker(gb2.Where((x, y) => y >= gb2seriesStartIndex && y < a)); 254 | hand22.Push(hand); 255 | foreach (var v in hand.value) pks.Remove(v); 256 | } else { 257 | for (var b = gb2seriesStartIndex; b < a; b++) { 258 | hand = Utils.ComplierHandPoker(new[] { gb2[b] }); 259 | hand2.Push(hand); 260 | foreach (var v in hand.value) pks.Remove(v); 261 | } 262 | } 263 | gb2seriesStartIndex = a; 264 | } 265 | } 266 | hand = Utils.ComplierHandPoker(gb.Where(a => a.count == 2 && a.key == 15)); //对2 267 | if (hand != null) { 268 | hand2.Push(hand); 269 | foreach (var v in hand.value) pks.Remove(v); 270 | } 271 | if (hand22.Any()) hands.AddRange(hand22.ToArray()); 272 | if (hand2.Any()) hands.AddRange(hand2.ToArray()); 273 | 274 | var hand11 = new Stack(); //顺子 275 | var hand1 = new Stack(); //个 276 | var gb1 = gb.Where(a => a.count == 1 && a.key < 15).OrderBy(a => a.key).ToList(); 277 | var gb1seriesStartIndex = 0; 278 | for (var a = 4; a < gb1.Count; a++) { 279 | if (Utils.IsSeries(gb1.Where((x, y) => y <= a).Select(x => x.key)) == false || a == gb1.Count - 1) { 280 | if (a - gb1seriesStartIndex >= 3) { 281 | hand = Utils.ComplierHandPoker(gb1.Where((x, y) => y >= gb1seriesStartIndex && y < a)); 282 | hand11.Push(hand); 283 | foreach (var v in hand.value) pks.Remove(v); 284 | } else { 285 | for (var b = gb1seriesStartIndex; b < a; b++) { 286 | hand = Utils.ComplierHandPoker(new[] { gb1[b] }); 287 | hand1.Push(hand); 288 | foreach (var v in hand.value) pks.Remove(v); 289 | } 290 | } 291 | gb1seriesStartIndex = a; 292 | } 293 | } 294 | hand = Utils.ComplierHandPoker(gb.Where(a => a.count == 1 && a.key == 15)); //个2 295 | if (hand != null) { 296 | hand1.Push(hand); 297 | foreach (var v in hand.value) pks.Remove(v); 298 | } 299 | if (hand11.Any()) hands.AddRange(hand11.ToArray()); 300 | if (hand1.Any()) hands.AddRange(hand1.ToArray()); 301 | 302 | return hands; 303 | } 304 | 305 | public class PlayerInfo { 306 | internal int playerIndex { get; set; } 307 | public GamePlayerRole role { get; } 308 | public List chupai { get; } = new List(); 309 | public int pokerLength { get; internal set; } 310 | 311 | public PlayerInfo(GamePlayerRole role) { 312 | this.role = role; 313 | this.pokerLength = role == GamePlayerRole.农民 ? 17 : 20; 314 | } 315 | } 316 | } 317 | 318 | public class RobotRecordChpai { 319 | 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.Tests/BetGame.DDZ.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.Tests/GamePlayTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.Tests/GamePlayTest.cs -------------------------------------------------------------------------------- /src/BetGame.DDZ.Tests/UtilsTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.Tests/UtilsTest.cs -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 |
-------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/BetGame.DDZ.WasmClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | 3.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Model/APIReturn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Text.Json; 6 | using System.Text.Json.Serialization; 7 | 8 | namespace BetGame.DDZ.WasmClient.Model 9 | { 10 | public class APIReturn 11 | { 12 | [JsonPropertyName("code")] public int Code { get; set; } 13 | [JsonPropertyName("message")] public string Message { get; set; } 14 | [JsonPropertyName("data")] public Dictionary Data { get; set; } 15 | [JsonPropertyName("success")] public bool Success { get { return this.Code == 0; } } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Model/ClientDefaults.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace BetGame.DDZ.WasmClient.Model 7 | { 8 | public class ClientDefaults 9 | { 10 | public const string playerId = "playerId"; 11 | public const string ApiHost = null; //"http://127.0.0.1:61243/";// "http://173.82.155.64:18091/"; 12 | public const string formcontentType = "application/x-www-form-urlencoded"; 13 | public const string jsoncontentType = "application/json"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Model/GameInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace BetGame.DDZ.WasmClient.Model 6 | { 7 | public class GameInfo 8 | { 9 | /// 10 | /// 打多大(普通基数)结算:multiple * (multipleAddition + Bong) 11 | /// 12 | public decimal multiple { get; set; } 13 | /// 14 | /// 附加倍数,抢地主环节 15 | /// 16 | public decimal multipleAddition { get; set; } 17 | /// 18 | /// 设定最大附加倍数 19 | /// 20 | public decimal multipleAdditionMax { get; set; } 21 | /// 22 | /// 炸弹次数 23 | /// 24 | public decimal bong { get; set; } 25 | /// 26 | /// 游戏玩家 27 | /// 28 | public List players { get; set; } 29 | /// 30 | /// 轮到哪位玩家操作 31 | /// 32 | public int playerIndex { get; set; } 33 | /// 34 | /// 底牌 35 | /// 36 | public int[] dipai { get; set; } 37 | public string[] dipaiText { get; set; } 38 | /// 39 | /// 出牌历史 40 | /// 41 | public List chupai { get; set; } 42 | /// 43 | /// 当前游戏阶段 44 | /// 45 | public string stage { get; set; } 46 | public string operationTimeout { get; set; } 47 | public int operationTimeoutSeconds { get; set; } 48 | } 49 | 50 | 51 | public class GamePlayer 52 | { 53 | public string id { get; set; } 54 | /// 55 | /// 玩家 56 | /// 57 | //public Player player { get; set; } 58 | /// 59 | /// 玩家手上的牌 60 | /// 61 | public List poker { get; set; } 62 | public string[] pokerText { get; set; } 63 | /// 64 | /// 玩家最初的牌 65 | /// 66 | public List pokerInit { get; set; } 67 | /// 68 | /// 玩家角色 69 | /// 70 | public string role { get; set; } 71 | /// 72 | /// 计算结果 73 | /// 74 | public long score { get; set; } 75 | 76 | public string status { get; set; } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Model/HandPokerInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BetGame.DDZ.WasmClient.Model 4 | { 5 | public class HandPokerInfo { 6 | /// 7 | /// 出牌时间 8 | /// 9 | public DateTime time { get; set; } 10 | /// 11 | /// 这手牌出自哪位玩家 12 | /// 13 | public int playerIndex { get; set; } 14 | /// 15 | /// 牌编译结果 16 | /// 17 | public HandPokerComplieResult result { get; set; } 18 | } 19 | 20 | public class HandPokerComplieResult { 21 | public string type { get; set; } 22 | /// 23 | /// 相同类型比较大小 24 | /// 25 | public int compareValue { get; set; } 26 | /// 27 | /// 牌 28 | /// 29 | public int[] value { get; set; } 30 | /// 31 | /// 牌面字符串 32 | /// 33 | public string[] text { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Model/Player.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.Json; 4 | 5 | namespace BetGame.DDZ.WasmClient.Model 6 | { 7 | /// 8 | /// 玩家 9 | /// 10 | public class Player 11 | { 12 | public string Id { get; set; } 13 | /// 14 | /// 昵称 15 | /// 16 | public string Nick { get; set; } 17 | /// 18 | /// 积分 19 | /// 20 | public long Score { get; set; } 21 | public int Balance { get; set; } 22 | public bool IsOnline { get; set; } 23 | public string GameState { get; set; } 24 | } 25 | 26 | /// 27 | /// 桌位 28 | /// 29 | public class Desk 30 | { 31 | public int Id { get; set; } 32 | public int Sort { get; set; } 33 | public string Title { get; set; } 34 | public Player player1 { get; set; } 35 | public Player player2 { get; set; } 36 | public Player player3 { get; set; } 37 | } 38 | public class currentChannel 39 | { 40 | public string chan { get; set; } 41 | public List msgs { get; set; } 42 | } 43 | public class inputChannelMsg 44 | { 45 | public string type { get; set; } 46 | public string content { get; set; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Program.cs: -------------------------------------------------------------------------------- 1 | using BetGame.DDZ.WasmClient.Services; 2 | using Microsoft.AspNetCore.Components.Authorization; 3 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | using System.Net.Http; 7 | using System.Net.WebSockets; 8 | using System.Threading.Tasks; 9 | 10 | namespace BetGame.DDZ.WasmClient 11 | { 12 | public class Program 13 | { 14 | public static async Task Main(string[] args) 15 | { 16 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 17 | 18 | builder.Services.AddScoped(); 19 | builder.Services.AddScoped(); 20 | builder.Services.AddScoped(); 21 | builder.Services.AddScoped(); 22 | builder.Services.AddScoped(s => s.GetRequiredService()); 23 | //在wasm中没有默认配置,所以需要设置一下 24 | builder.Services.AddOptions(); 25 | builder.Services.AddAuthorizationCore(); 26 | //builder.Services.AddAuthorizationCore(c=> { 27 | // c.AddPolicy("default", a => a.RequireAuthenticatedUser()); 28 | // c.DefaultPolicy = c.GetPolicy("default"); 29 | //}); 30 | builder.Services.AddScoped(sp=>new ClientWebSocket()); 31 | 32 | builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 33 | builder.RootComponents.Add("app"); 34 | 35 | await builder.Build().RunAsync(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:52094/", 7 | "sslPort": 44380 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "BetGame.DDZ.WasmClient": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:52094;" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/ApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Net.WebSockets; 6 | using System.Text.Json; 7 | using System.Threading.Tasks; 8 | using BetGame.DDZ.WasmClient.Model; 9 | using Microsoft.AspNetCore.Components; 10 | 11 | namespace BetGame.DDZ.WasmClient.Services 12 | { 13 | public class ApiService 14 | { 15 | LocalStorage _localStorage; 16 | HttpClient _httpclient; 17 | FunctionHelper _functionHelper; 18 | //ClientWebSocket _clientWebSocket; 19 | public ApiService(HttpClient httpclient, LocalStorage localStorage, FunctionHelper functionHelper/*, ClientWebSocket clientWebSocket*/) 20 | { 21 | if (!string.IsNullOrWhiteSpace(ClientDefaults.ApiHost)) 22 | httpclient.BaseAddress = new Uri(ClientDefaults.ApiHost); 23 | // httpclient.DefaultRequestHeaders.Add("content-type", ClientDefaults.formcontentType); 24 | _httpclient = httpclient; 25 | _localStorage = localStorage; 26 | _functionHelper = functionHelper; 27 | //_clientWebSocket = clientWebSocket; 28 | } 29 | private string playerId; 30 | public async Task GetPlayer() 31 | { 32 | try 33 | { 34 | 35 | playerId = await _localStorage.GetAsync(ClientDefaults.playerId); 36 | if (string.IsNullOrWhiteSpace(playerId) || playerId == "undefined") 37 | { 38 | return default; 39 | } 40 | else 41 | { 42 | var apireturn = await _httpclient.PostFormAsync("/ddz/GetPlayer", $"playerId={playerId}"); 43 | if (apireturn != null && !apireturn.Success) 44 | { 45 | await _functionHelper.Alert(apireturn.Message); 46 | return default; 47 | } 48 | if (apireturn != null && apireturn.Data != null && apireturn.Data.Any() && apireturn.Data.TryGetValue("player", out var playerstr)) 49 | { 50 | var player = JsonSerializer.Deserialize(playerstr.ToString()); 51 | if (player != null && !string.IsNullOrWhiteSpace(player.Nick)) 52 | { 53 | playerId = player?.Id; 54 | if(string.IsNullOrWhiteSpace(playerId)) 55 | await _localStorage.DeleteAsync(ClientDefaults.playerId); 56 | return player; 57 | } 58 | } 59 | } 60 | return default; 61 | } 62 | catch 63 | { 64 | await _localStorage.DeleteAsync(ClientDefaults.playerId); 65 | return default; 66 | } 67 | } 68 | public async Task GetOrAddPlayer(string nick) 69 | { 70 | 71 | var apireturn = await _httpclient.PostFormAsync("/ddz/GetOrAddPlayer", $"nick={nick}"); 72 | if (apireturn != null && !apireturn.Success) 73 | { 74 | await _functionHelper.Alert(apireturn.Message); 75 | return default; 76 | } 77 | if (apireturn != null && apireturn.Data != null && apireturn.Data.Any() && apireturn.Data.TryGetValue("player", out object playerstr)) 78 | { 79 | Console.WriteLine(playerstr.ToString()); 80 | var player = JsonSerializer.Deserialize(playerstr.ToString()); 81 | await _localStorage.SetAsync(ClientDefaults.playerId, player.Id); 82 | this.playerId = player.Id; 83 | return player; 84 | } 85 | return default; 86 | } 87 | public async Task> GetDesks() 88 | { 89 | var apireturn = await _httpclient.PostFormAsync("/ddz/GetDesks", $"playerId={playerId}"); 90 | if (apireturn != null && !apireturn.Success) 91 | { 92 | await _functionHelper.Alert(apireturn.Message); 93 | return default; 94 | } 95 | if (apireturn.Data.TryGetValue("desks", out var playerstr)) 96 | { 97 | return JsonSerializer.Deserialize>(playerstr.ToString()); 98 | } 99 | return default; 100 | 101 | } 102 | public async Task ConnectWebsocket() 103 | { 104 | var apireturn = await _httpclient.PostFormAsync("/ddz/PrevConnectWebsocket", $"playerId={playerId}"); 105 | if (apireturn != null && !apireturn.Success) 106 | { 107 | await _functionHelper.Alert(apireturn.Message); 108 | return default; 109 | } 110 | if (apireturn != null && apireturn.Data != null && apireturn.Data.Any() && apireturn.Data.TryGetValue("server", out var server)) 111 | { 112 | return server.ToString(); 113 | } 114 | return default; 115 | } 116 | 117 | public async Task Sitdown(int deskId, int pos) 118 | { 119 | var apireturn = await _httpclient.PostFormAsync("/ddz/Sitdown", $"playerId={playerId}&deskId={deskId}&pos={pos}"); 120 | if (apireturn != null && !apireturn.Success) 121 | { 122 | await _functionHelper.Alert(apireturn.Message); 123 | } 124 | } 125 | 126 | public async Task Standup() 127 | { 128 | var apireturn = await _httpclient.PostFormAsync("/ddz/Standup", $"playerId={playerId}"); 129 | if (apireturn != null && !apireturn.Success) 130 | { 131 | await _functionHelper.Alert(apireturn.Message); 132 | } 133 | else await _functionHelper.Alert("你已离开坐位"); 134 | 135 | } 136 | public async Task SendChannelMsg(inputChannelMsg msg, string sender, string senderNick, string chan) 137 | { 138 | var data = new { type = "chanmsg", sender, senderNick, chan, time = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds, msg }; 139 | await _httpclient.PostFormAsync("/ddz/SendChannelMsg", $"playerId={sender}&channel={chan}&message={JsonSerializer.Serialize(data) }"); 140 | } 141 | public async Task SelectLandlord(string ddzid, string playerId, decimal multiple) 142 | { 143 | var apireturn = await _httpclient.PostFormAsync("/ddz/SelectLandlord", $"id={ddzid}&playerId={playerId}&multiple={multiple}"); 144 | if (apireturn != null && !apireturn.Success) 145 | { 146 | await _functionHelper.Alert(apireturn.Message); 147 | } 148 | } 149 | public async Task SelectFarmer(string ddzid, string playerId) 150 | { 151 | var apireturn = await _httpclient.PostFormAsync("/ddz/SelectFarmer", $"id={ddzid}&playerId={playerId}"); 152 | if (apireturn != null && !apireturn.Success) 153 | { 154 | await _functionHelper.Alert(apireturn.Message); 155 | } 156 | } 157 | 158 | public async Task Play(string ddzid, string playerId, IEnumerable poker) 159 | { 160 | if (poker.Count() == 0) 161 | { 162 | await _functionHelper.Alert("请选择要出的牌"); 163 | } 164 | else 165 | { 166 | string pokers = ""; 167 | foreach (var p in poker) 168 | { 169 | pokers += $"&poker={p}"; 170 | } 171 | var apireturn = await _httpclient.PostFormAsync("/ddz/Play", $"id={ddzid}&playerId={playerId}{pokers}"); 172 | if (apireturn != null && !apireturn.Success) 173 | { 174 | await _functionHelper.Alert(apireturn.Message); 175 | } 176 | } 177 | } 178 | 179 | public async Task Pass(string ddzid, string playerId) 180 | { 181 | var apireturn = await _httpclient.PostFormAsync("/ddz/Pass", $"id={ddzid}&playerId={playerId}"); 182 | if (apireturn != null && !apireturn.Success) 183 | { 184 | await _functionHelper.Alert(apireturn.Message); 185 | } 186 | } 187 | 188 | public async Task> PlayTips(string ddzid, string playerId) 189 | { 190 | var apireturn = await _httpclient.PostFormAsync("/ddz/PlayTips", $"id={ddzid}&playerId={playerId}"); 191 | if (apireturn != null && !apireturn.Success) 192 | { 193 | await _functionHelper.Alert(apireturn.Message); 194 | } 195 | if (apireturn != null && apireturn.Data != null && apireturn.Data.Any() && apireturn.Data.TryGetValue("tips", out var server)) 196 | { 197 | return JsonSerializer.Deserialize>(server.ToString()); 198 | } 199 | return default; 200 | } 201 | 202 | public async Task CancelAutoPlay(string ddzid, string playerId) 203 | { 204 | var apireturn = await _httpclient.PostFormAsync("/ddz/CancelAutoPlay", $"id={ddzid}&playerId={playerId}"); 205 | if (apireturn != null && !apireturn.Success) 206 | { 207 | await _functionHelper.Alert(apireturn.Message); 208 | } 209 | } 210 | 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/CustomAuthStateProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Security.Claims; 6 | using System.Threading.Tasks; 7 | using BetGame.DDZ.WasmClient.Model; 8 | using Microsoft.AspNetCore.Components.Authorization; 9 | 10 | namespace BetGame.DDZ.WasmClient.Services 11 | { 12 | public class CustomAuthStateProvider : AuthenticationStateProvider 13 | { 14 | ApiService _apiService; 15 | Player _playerCache; 16 | public CustomAuthStateProvider(ApiService apiService) 17 | { 18 | _apiService = apiService; 19 | } 20 | 21 | public override async Task GetAuthenticationStateAsync() 22 | { 23 | var player = _playerCache??= await _apiService.GetPlayer(); 24 | 25 | if (player == null) 26 | { 27 | return new AuthenticationState(new ClaimsPrincipal()); 28 | } 29 | else 30 | { 31 | var user = Utils.GetClaimsIdentity(player); 32 | 33 | return new AuthenticationState(user); 34 | } 35 | 36 | } 37 | public void NotifyAuthenticationState() 38 | { 39 | NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); 40 | } 41 | public void NotifyAuthenticationState(Player player) 42 | { 43 | _playerCache = player; 44 | NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/FunctionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.JSInterop; 6 | 7 | namespace BetGame.DDZ.WasmClient.Services 8 | { 9 | public class FunctionHelper 10 | { 11 | private readonly IJSRuntime _jsRuntime; 12 | 13 | public FunctionHelper(IJSRuntime jsRuntime) 14 | { 15 | _jsRuntime = jsRuntime; 16 | } 17 | 18 | public ValueTask Alert(object message) 19 | { 20 | return _jsRuntime.InvokeVoidAsync("alert", message); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/HttpClientExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Text; 6 | using System.Text.Json; 7 | using System.Threading.Tasks; 8 | using BetGame.DDZ.WasmClient.Model; 9 | 10 | namespace BetGame.DDZ.WasmClient.Services 11 | { 12 | public static class HttpClientExtensions 13 | { 14 | static JsonSerializerOptions settings = new JsonSerializerOptions 15 | { 16 | PropertyNameCaseInsensitive = true 17 | }; 18 | public static async Task PostFormAsync(this HttpClient httpClient, string requestUri, string content) 19 | { 20 | HttpContent httpcontent = new StringContent(content ?? "", Encoding.UTF8); 21 | httpcontent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ClientDefaults.formcontentType); 22 | 23 | using HttpResponseMessage responseMessage = await httpClient.PostAsync(requestUri, httpcontent); 24 | 25 | return await JsonSerializer.DeserializeAsync(await responseMessage.Content.ReadAsStreamAsync(), settings); 26 | } 27 | public static async Task PostFormAsync(this HttpClient httpClient, string requestUri, string content) 28 | { 29 | HttpContent httpcontent = new StringContent(content ?? "", Encoding.UTF8); 30 | httpcontent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ClientDefaults.formcontentType); 31 | 32 | await httpClient.PostAsync(requestUri, httpcontent); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/LocalStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text.Json; 5 | using System.Threading.Tasks; 6 | using Microsoft.JSInterop; 7 | 8 | namespace BetGame.DDZ.WasmClient.Services 9 | { 10 | public class LocalStorage 11 | { 12 | private readonly IJSRuntime _jsRuntime; 13 | private readonly static JsonSerializerOptions SerializerOptions = new JsonSerializerOptions(); 14 | 15 | public LocalStorage(IJSRuntime jsRuntime) 16 | { 17 | _jsRuntime = jsRuntime; 18 | } 19 | public ValueTask SetAsync(string key, object value) 20 | { 21 | 22 | if (string.IsNullOrEmpty(key)) 23 | { 24 | throw new ArgumentException("Cannot be null or empty", nameof(key)); 25 | } 26 | 27 | var json = JsonSerializer.Serialize(value, options: SerializerOptions); 28 | 29 | return _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, json); 30 | } 31 | public async ValueTask GetAsync(string key) 32 | { 33 | 34 | if (string.IsNullOrEmpty(key)) 35 | { 36 | throw new ArgumentException("Cannot be null or empty", nameof(key)); 37 | } 38 | 39 | 40 | var json =await _jsRuntime.InvokeAsync("localStorage.getItem", key); 41 | if (json == null) 42 | { 43 | return default; 44 | } 45 | 46 | return JsonSerializer.Deserialize(json, options: SerializerOptions); 47 | } 48 | public ValueTask DeleteAsync(string key) 49 | { 50 | return _jsRuntime.InvokeVoidAsync( 51 | $"localStorage.removeItem",key); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Services/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Threading.Tasks; 6 | using BetGame.DDZ.WasmClient.Model; 7 | 8 | namespace BetGame.DDZ.WasmClient.Services 9 | { 10 | public class Utils 11 | { 12 | public static ClaimsPrincipal GetClaimsIdentity(Player player) 13 | { 14 | var identity = new ClaimsIdentity(new[] 15 | { 16 | new Claim(nameof(player.Balance), player.Balance.ToString()), 17 | new Claim(nameof(player.Score), player.Score.ToString()), 18 | new Claim(nameof(player.GameState), player.GameState??""), 19 | new Claim(nameof(player.IsOnline), player.IsOnline.ToString()), 20 | new Claim(nameof(player.Nick), player.Nick), 21 | new Claim(nameof(player.Id), player.Id), 22 | }, "Fake authentication type"); 23 | 24 | return new ClaimsPrincipal(identity); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | @Body 3 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Components.Forms 3 | @using Microsoft.AspNetCore.Components.Routing 4 | @using Microsoft.AspNetCore.Components.Web 5 | @using Microsoft.JSInterop 6 | @using BetGame.DDZ.WasmClient 7 | @using BetGame.DDZ.WasmClient.Shared 8 | @using System.Net.WebSockets; 9 | @using Microsoft.AspNetCore; 10 | @using BetGame.DDZ.WasmClient.Services 11 | @using Microsoft.AspNetCore.Components.Authorization 12 | @using Microsoft.AspNetCore.Authorization 13 | @using System.Security.Claims 14 | @using System.Text.Json 15 | @using System 16 | @using System.Text 17 | @using BetGame.DDZ.WasmClient.Model; 18 | @using BetGame.DDZ 19 | @using System.Threading 20 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/bootstrap/dist/css/bootstrap-reboot.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v4.3.1 (https://getbootstrap.com/) 3 | * Copyright 2011-2019 The Bootstrap Authors 4 | * Copyright 2011-2019 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | html { 15 | font-family: sans-serif; 16 | line-height: 1.15; 17 | -webkit-text-size-adjust: 100%; 18 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 19 | } 20 | 21 | article, aside, figcaption, figure, footer, header, hgroup, main, nav, section { 22 | display: block; 23 | } 24 | 25 | body { 26 | margin: 0; 27 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 28 | font-size: 1rem; 29 | font-weight: 400; 30 | line-height: 1.5; 31 | color: #212529; 32 | text-align: left; 33 | background-color: #fff; 34 | } 35 | 36 | [tabindex="-1"]:focus { 37 | outline: 0 !important; 38 | } 39 | 40 | hr { 41 | box-sizing: content-box; 42 | height: 0; 43 | overflow: visible; 44 | } 45 | 46 | h1, h2, h3, h4, h5, h6 { 47 | margin-top: 0; 48 | margin-bottom: 0.5rem; 49 | } 50 | 51 | p { 52 | margin-top: 0; 53 | margin-bottom: 1rem; 54 | } 55 | 56 | abbr[title], 57 | abbr[data-original-title] { 58 | text-decoration: underline; 59 | -webkit-text-decoration: underline dotted; 60 | text-decoration: underline dotted; 61 | cursor: help; 62 | border-bottom: 0; 63 | -webkit-text-decoration-skip-ink: none; 64 | text-decoration-skip-ink: none; 65 | } 66 | 67 | address { 68 | margin-bottom: 1rem; 69 | font-style: normal; 70 | line-height: inherit; 71 | } 72 | 73 | ol, 74 | ul, 75 | dl { 76 | margin-top: 0; 77 | margin-bottom: 1rem; 78 | } 79 | 80 | ol ol, 81 | ul ul, 82 | ol ul, 83 | ul ol { 84 | margin-bottom: 0; 85 | } 86 | 87 | dt { 88 | font-weight: 700; 89 | } 90 | 91 | dd { 92 | margin-bottom: .5rem; 93 | margin-left: 0; 94 | } 95 | 96 | blockquote { 97 | margin: 0 0 1rem; 98 | } 99 | 100 | b, 101 | strong { 102 | font-weight: bolder; 103 | } 104 | 105 | small { 106 | font-size: 80%; 107 | } 108 | 109 | sub, 110 | sup { 111 | position: relative; 112 | font-size: 75%; 113 | line-height: 0; 114 | vertical-align: baseline; 115 | } 116 | 117 | sub { 118 | bottom: -.25em; 119 | } 120 | 121 | sup { 122 | top: -.5em; 123 | } 124 | 125 | a { 126 | color: #007bff; 127 | text-decoration: none; 128 | background-color: transparent; 129 | } 130 | 131 | a:hover { 132 | color: #0056b3; 133 | text-decoration: underline; 134 | } 135 | 136 | a:not([href]):not([tabindex]) { 137 | color: inherit; 138 | text-decoration: none; 139 | } 140 | 141 | a:not([href]):not([tabindex]):hover, a:not([href]):not([tabindex]):focus { 142 | color: inherit; 143 | text-decoration: none; 144 | } 145 | 146 | a:not([href]):not([tabindex]):focus { 147 | outline: 0; 148 | } 149 | 150 | pre, 151 | code, 152 | kbd, 153 | samp { 154 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 155 | font-size: 1em; 156 | } 157 | 158 | pre { 159 | margin-top: 0; 160 | margin-bottom: 1rem; 161 | overflow: auto; 162 | } 163 | 164 | figure { 165 | margin: 0 0 1rem; 166 | } 167 | 168 | img { 169 | vertical-align: middle; 170 | border-style: none; 171 | } 172 | 173 | svg { 174 | overflow: hidden; 175 | vertical-align: middle; 176 | } 177 | 178 | table { 179 | border-collapse: collapse; 180 | } 181 | 182 | caption { 183 | padding-top: 0.75rem; 184 | padding-bottom: 0.75rem; 185 | color: #6c757d; 186 | text-align: left; 187 | caption-side: bottom; 188 | } 189 | 190 | th { 191 | text-align: inherit; 192 | } 193 | 194 | label { 195 | display: inline-block; 196 | margin-bottom: 0.5rem; 197 | } 198 | 199 | button { 200 | border-radius: 0; 201 | } 202 | 203 | button:focus { 204 | outline: 1px dotted; 205 | outline: 5px auto -webkit-focus-ring-color; 206 | } 207 | 208 | input, 209 | button, 210 | select, 211 | optgroup, 212 | textarea { 213 | margin: 0; 214 | font-family: inherit; 215 | font-size: inherit; 216 | line-height: inherit; 217 | } 218 | 219 | button, 220 | input { 221 | overflow: visible; 222 | } 223 | 224 | button, 225 | select { 226 | text-transform: none; 227 | } 228 | 229 | select { 230 | word-wrap: normal; 231 | } 232 | 233 | button, 234 | [type="button"], 235 | [type="reset"], 236 | [type="submit"] { 237 | -webkit-appearance: button; 238 | } 239 | 240 | button:not(:disabled), 241 | [type="button"]:not(:disabled), 242 | [type="reset"]:not(:disabled), 243 | [type="submit"]:not(:disabled) { 244 | cursor: pointer; 245 | } 246 | 247 | button::-moz-focus-inner, 248 | [type="button"]::-moz-focus-inner, 249 | [type="reset"]::-moz-focus-inner, 250 | [type="submit"]::-moz-focus-inner { 251 | padding: 0; 252 | border-style: none; 253 | } 254 | 255 | input[type="radio"], 256 | input[type="checkbox"] { 257 | box-sizing: border-box; 258 | padding: 0; 259 | } 260 | 261 | input[type="date"], 262 | input[type="time"], 263 | input[type="datetime-local"], 264 | input[type="month"] { 265 | -webkit-appearance: listbox; 266 | } 267 | 268 | textarea { 269 | overflow: auto; 270 | resize: vertical; 271 | } 272 | 273 | fieldset { 274 | min-width: 0; 275 | padding: 0; 276 | margin: 0; 277 | border: 0; 278 | } 279 | 280 | legend { 281 | display: block; 282 | width: 100%; 283 | max-width: 100%; 284 | padding: 0; 285 | margin-bottom: .5rem; 286 | font-size: 1.5rem; 287 | line-height: inherit; 288 | color: inherit; 289 | white-space: normal; 290 | } 291 | 292 | progress { 293 | vertical-align: baseline; 294 | } 295 | 296 | [type="number"]::-webkit-inner-spin-button, 297 | [type="number"]::-webkit-outer-spin-button { 298 | height: auto; 299 | } 300 | 301 | [type="search"] { 302 | outline-offset: -2px; 303 | -webkit-appearance: none; 304 | } 305 | 306 | [type="search"]::-webkit-search-decoration { 307 | -webkit-appearance: none; 308 | } 309 | 310 | ::-webkit-file-upload-button { 311 | font: inherit; 312 | -webkit-appearance: button; 313 | } 314 | 315 | output { 316 | display: inline-block; 317 | } 318 | 319 | summary { 320 | display: list-item; 321 | cursor: pointer; 322 | } 323 | 324 | template { 325 | display: none; 326 | } 327 | 328 | [hidden] { 329 | display: none !important; 330 | } 331 | /*# sourceMappingURL=bootstrap-reboot.css.map */ -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/bootstrap/dist/css/bootstrap-reboot.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v4.3.1 (https://getbootstrap.com/) 3 | * Copyright 2011-2019 The Bootstrap Authors 4 | * Copyright 2011-2019 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff}[tabindex="-1"]:focus{outline:0!important}hr{box-sizing:content-box;height:0;overflow:visible}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem}p{margin-top:0;margin-bottom:1rem}abbr[data-original-title],abbr[title]{text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;border-bottom:0;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#007bff;text-decoration:none;background-color:transparent}a:hover{color:#0056b3;text-decoration:underline}a:not([href]):not([tabindex]){color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus,a:not([href]):not([tabindex]):hover{color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus{outline:0}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em}pre{margin-top:0;margin-bottom:1rem;overflow:auto}figure{margin:0 0 1rem}img{vertical-align:middle;border-style:none}svg{overflow:hidden;vertical-align:middle}table{border-collapse:collapse}caption{padding-top:.75rem;padding-bottom:.75rem;color:#6c757d;text-align:left;caption-side:bottom}th{text-align:inherit}label{display:inline-block;margin-bottom:.5rem}button{border-radius:0}button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}select{word-wrap:normal}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{padding:0;border-style:none}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=date],input[type=datetime-local],input[type=month],input[type=time]{-webkit-appearance:listbox}textarea{overflow:auto;resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;max-width:100%;padding:0;margin-bottom:.5rem;font-size:1.5rem;line-height:inherit;color:inherit;white-space:normal}progress{vertical-align:baseline}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:none}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}summary{display:list-item;cursor:pointer}template{display:none}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.min.css.map */ -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](http://useiconic.com/open) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WasmClient/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | /* Provide sufficient contrast against white background */ 11 | a { 12 | color: #0366d6; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 22 | color: #fff; 23 | background-color: #1b6ec2; 24 | border-color: #1861ac; 25 | } 26 | 27 | /* Sticky footer styles 28 | -------------------------------------------------- */ 29 | html { 30 | font-size: 14px; 31 | } 32 | 33 | @media (min-width: 768px) { 34 | html { 35 | font-size: 16px; 36 | } 37 | } 38 | 39 | .border-top { 40 | border-top: 1px solid #e5e5e5; 41 | } 42 | 43 | .border-bottom { 44 | border-bottom: 1px solid #e5e5e5; 45 | } 46 | 47 | .box-shadow { 48 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 49 | } 50 | 51 | button.accept-policy { 52 | font-size: 1rem; 53 | line-height: inherit; 54 | } 55 | 56 | /* Sticky footer styles 57 | -------------------------------------------------- */ 58 | html { 59 | position: relative; 60 | min-height: 100%; 61 | } 62 | 63 | body { 64 | /* Margin bottom by footer height */ 65 | margin-bottom: 60px; 66 | } 67 | 68 | .footer { 69 | position: absolute; 70 | bottom: 0; 71 | width: 100%; 72 | white-space: nowrap; 73 | line-height: 60px; /* Vertically center the text there */ 74 | } 75 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Blazor(WebAssembly) + .NETCore 斗地主 8 | 9 | 10 | 11 | 57 | 58 | 59 | 60 |
61 | Loading... 62 |
63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/js/websockethelper.js: -------------------------------------------------------------------------------- 1 | var gsocket = null; 2 | var gsocketTimeId = null; 3 | function newWebSocket(url, dotnetHelper) 4 | { 5 | console.log('newWebSocket'); 6 | if (gsocket) gsocket.close(); 7 | gsocket = null; 8 | gsocket = new WebSocket(url); 9 | gsocket.onopen = function (e) { 10 | console.log('websocket connect'); 11 | dotnetHelper.invokeMethodAsync('onopen') 12 | }; 13 | gsocket.onclose = function (e) { 14 | console.log('websocket disconnect'); 15 | dotnetHelper.invokeMethodAsync('onclose') 16 | gsocket = null; 17 | clearTimeout(gsocketTimeId); 18 | gsocketTimeId = setTimeout(function () { 19 | console.log('websocket onclose ConnectWebsocket'); 20 | dotnetHelper.invokeMethodAsync('ConnectWebsocket'); 21 | //_self.ConnectWebsocket.call(_self); 22 | }, 5000); 23 | }; 24 | gsocket.onmessage = function (e) { 25 | try { 26 | console.log('websocket onmessage'); 27 | var msg = JSON.parse(e.data); 28 | dotnetHelper.invokeMethodAsync('onmessage', msg); 29 | //_self.onmessage.call(_self, msg); 30 | } catch (e) { 31 | console.log(e); 32 | return; 33 | } 34 | }; 35 | gsocket.onerror = function (e) { 36 | console.log('websocket error'); 37 | gsocket = null; 38 | clearTimeout(gsocketTimeId); 39 | gsocketTimeId = setTimeout(function () { 40 | console.log('websocket onerror ConnectWebsocket'); 41 | dotnetHelper.invokeMethodAsync('ConnectWebsocket'); 42 | //_self.ConnectWebsocket.call(_self); 43 | }, 5000); 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/poker.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WasmClient/wwwroot/poker.ttf -------------------------------------------------------------------------------- /src/BetGame.DDZ.WasmClient/wwwroot/sample-data/weather.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2018-05-06", 4 | "temperatureC": 1, 5 | "summary": "Freezing", 6 | "temperatureF": 33 7 | }, 8 | { 9 | "date": "2018-05-07", 10 | "temperatureC": 14, 11 | "summary": "Bracing", 12 | "temperatureF": 57 13 | }, 14 | { 15 | "date": "2018-05-08", 16 | "temperatureC": -13, 17 | "summary": "Freezing", 18 | "temperatureF": 9 19 | }, 20 | { 21 | "date": "2018-05-09", 22 | "temperatureC": -16, 23 | "summary": "Balmy", 24 | "temperatureF": 4 25 | }, 26 | { 27 | "date": "2018-05-10", 28 | "temperatureC": -2, 29 | "summary": "Chilly", 30 | "temperatureF": 29 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/BetGame.DDZ.WebHost.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 3 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Common/APIReturn.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | [JsonObject(MemberSerialization.OptIn)] 10 | public partial class APIReturn : ContentResult { 11 | [JsonProperty("code")] public int Code { get; protected set; } 12 | [JsonProperty("message")] public string Message { get; protected set; } 13 | [JsonProperty("data")] public Hashtable Data { get; protected set; } = new Hashtable(); 14 | [JsonProperty("success")] public bool Success { get { return this.Code == 0; } } 15 | 16 | public APIReturn() { } 17 | public APIReturn(int code) { this.SetCode(code); } 18 | public APIReturn(string message) { this.SetMessage(message); } 19 | public APIReturn(int code, string message, params object[] data) { this.SetCode(code).SetMessage(message).AppendData(data); } 20 | 21 | public APIReturn SetCode(int value) { this.Code = value; return this; } 22 | public APIReturn SetMessage(string value) { this.Message = value; return this; } 23 | public APIReturn SetData(params object[] value) { 24 | this.Data.Clear(); 25 | return this.AppendData(value); 26 | } 27 | public APIReturn AppendData(params object[] value) { 28 | if (value == null || value.Length < 2 || value[0] == null) return this; 29 | for (int a = 0; a < value.Length; a += 2) { 30 | if (value[a] == null) continue; 31 | this.Data[value[a]] = a + 1 < value.Length ? value[a + 1] : null; 32 | } 33 | return this; 34 | } 35 | #region form 表单 target=iframe 提交回调处理 36 | private void Jsonp(ActionContext context) { 37 | string __callback = context.HttpContext.Request.HasFormContentType ? context.HttpContext.Request.Form["__callback"].ToString() : null; 38 | if (string.IsNullOrEmpty(__callback)) { 39 | this.ContentType = "text/json;charset=utf-8;"; 40 | this.Content = JsonConvert.SerializeObject(this); 41 | } else { 42 | this.ContentType = "text/html;charset=utf-8"; 43 | this.Content = $""; 44 | } 45 | } 46 | public override void ExecuteResult(ActionContext context) { 47 | Jsonp(context); 48 | base.ExecuteResult(context); 49 | } 50 | public override Task ExecuteResultAsync(ActionContext context) { 51 | Jsonp(context); 52 | return base.ExecuteResultAsync(context); 53 | } 54 | #endregion 55 | 56 | public static APIReturn 成功 { get { return new APIReturn(0, "成功"); } } 57 | public static APIReturn 失败 { get { return new APIReturn(99, "失败"); } } 58 | public static APIReturn 记录不存在_或者没有权限 { get { return new APIReturn(98, "记录不存在,或者没有权限"); } } 59 | public static APIReturn 参数格式不正确 { get { return new APIReturn(97, "参数格式不正确"); } } 60 | } 61 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Common/CustomExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Logging; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Security.Cryptography; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | public class CustomExceptionFilter : Attribute, IExceptionFilter { 14 | 15 | private ILogger _logger = null; 16 | private IConfiguration _cfg = null; 17 | private IHostingEnvironment _env = null; 18 | 19 | public CustomExceptionFilter(ILogger logger, IConfiguration cfg, IHostingEnvironment env) { 20 | _logger = logger; 21 | _cfg = cfg; 22 | _env = env; 23 | } 24 | 25 | public void OnException(ExceptionContext context) { 26 | //在这里记录错误日志,context.Exception 为异常对象 27 | context.Result = APIReturn.失败.SetMessage(context.Exception.Message); //返回给调用方 28 | var innerLog = context.Exception.InnerException != null ? $" \r\n{context.Exception.InnerException.Message} \r\n{ context.Exception.InnerException.StackTrace}" : ""; 29 | _logger.LogError($"=============错误:{context.Exception.Message} \r\n{context.Exception.StackTrace}{innerLog}"); 30 | context.ExceptionHandled = true; 31 | } 32 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Common/GlobalExtensions.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | public static class GlobalExtensions { 6 | public static object Json(this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper html, object obj) { 7 | string str = JsonConvert.SerializeObject(obj); 8 | if (!string.IsNullOrEmpty(str)) str = Regex.Replace(str, @"<(/?script[\s>])", "<\"+\"$1", RegexOptions.IgnoreCase); 9 | if (html == null) return str; 10 | return html.Raw(str); 11 | } 12 | 13 | /// 14 | /// 转格林时间,并以ISO8601格式化字符串 15 | /// 16 | /// 17 | /// 18 | public static string ToGmtISO8601(this DateTime time) { 19 | return time.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); 20 | } 21 | 22 | /// 23 | /// 获取时间戳,按1970-1-1 24 | /// 25 | /// 26 | /// 27 | public static long GetTime(this DateTime time) { 28 | return (long)time.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds; 29 | } 30 | 31 | /// 32 | /// 获取时间戳毫秒数,按1970-1-1 33 | /// 34 | /// 35 | /// 36 | public static long GetTimeMilliseconds(this DateTime time) { 37 | return (long)time.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Controllers/DDZGamePlayController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using BetGame.DDZ; 8 | 9 | namespace BetGame.DDZ.WebHost.Controllers 10 | { 11 | [Route("ddz"), ServiceFilter(typeof(CustomExceptionFilter))] 12 | public class DDZGamePlayController : Controller 13 | { 14 | GamePlay DDZCreate(string[] playerIds, decimal multiple) { 15 | var ddz = GamePlay.Create(playerIds, multiple, 3); 16 | return ddz; 17 | } 18 | GamePlay DDZGet(string id) { 19 | var ddz = GamePlay.GetById(id); 20 | return ddz; 21 | } 22 | void DDZOnShuffle(string id, GameInfo data) { 23 | 24 | } 25 | void DDZOnNextSelect(string id, GameInfo data) { 26 | 27 | } 28 | void DDZOnNextPlay(string id, GameInfo data) { 29 | 30 | } 31 | void DDZOnGameOver(string id, GameInfo data) { 32 | 33 | } 34 | 35 | [HttpPost("StartAndShuffle")] 36 | public APIReturn 开始并洗牌([FromForm] decimal multiple, [FromForm] string[] playerIds) { 37 | var ddz = DDZCreate(playerIds, multiple); 38 | ddz.Shuffle(); 39 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data); 40 | } 41 | 42 | [HttpPost("SelectLandlord")] 43 | public APIReturn 叫地主([FromForm] string id, [FromForm] string playerId, [FromForm] decimal multiple) { 44 | var ddz = DDZGet(id); 45 | ddz.SelectLandlord(playerId, multiple); 46 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data); 47 | } 48 | [HttpPost("SelectFarmer")] 49 | public APIReturn 不叫([FromForm] string id, [FromForm] string playerId) { 50 | var ddz = DDZGet(id); 51 | ddz.SelectFarmer(playerId); 52 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data); 53 | } 54 | 55 | [HttpPost("PlayTips")] 56 | public APIReturn 出牌提示([FromForm] string id, [FromForm] string playerId) { 57 | var ddz = DDZGet(id); 58 | var tips = ddz.PlayTips(playerId); 59 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data, "tips", tips); 60 | } 61 | [HttpPost("Play")] 62 | public APIReturn 出牌([FromForm] string id, [FromForm] string playerId, [FromForm] int[] poker) { 63 | var ddz = DDZGet(id); 64 | ddz.Play(playerId, poker); 65 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data); 66 | } 67 | [HttpPost("Pass")] 68 | public APIReturn 不要([FromForm] string id, [FromForm] string playerId) { 69 | var ddz = DDZGet(id); 70 | ddz.Pass(playerId); 71 | return APIReturn.成功.SetData("id", ddz.Id, "data", ddz.Data); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace BetGame.DDZ.WebHost 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:59310/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "BetGame.DDZ.WebHost": { 12 | "commandName": "Project", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | }, 17 | "applicationUrl": "http://localhost:59313/" 18 | }, 19 | "IIS Express": { 20 | "commandName": "IISExpress", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.HttpsPolicy; 9 | using Microsoft.AspNetCore.Mvc; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | 13 | namespace BetGame.DDZ.WebHost 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | 21 | Newtonsoft.Json.JsonConvert.DefaultSettings = () => { 22 | var st = new Newtonsoft.Json.JsonSerializerSettings(); 23 | st.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); 24 | st.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat; 25 | st.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.RoundtripKind; 26 | return st; 27 | }; 28 | 29 | RedisHelper.Initialization(new CSRedis.CSRedisClient(configuration["redis"])); 30 | } 31 | 32 | public IConfiguration Configuration { get; } 33 | 34 | public void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddScoped(); 37 | services.AddControllersWithViews(); 38 | services.AddRazorPages(); 39 | } 40 | 41 | public void Configure(IApplicationBuilder app) 42 | { 43 | app.UseDeveloperExceptionPage(); 44 | 45 | app.UseRouting(); 46 | app.UseEndpoints(config => config.MapControllers()); 47 | app.UseDefaultFiles(); 48 | app.UseStaticFiles(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | }, 9 | "redis": "127.0.0.1:6379,password=,defaultDatabase=11,poolsize=20" 10 | } 11 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | 11 | "redis": "127.0.0.1:6379,password=,defaultDatabase=11,poolsize=10,preheat=1" 12 | } 13 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | h5斗地主 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 |
22 | 23 |

.NETCore斗地主服务端 + HTML5前端

24 |
25 |

本项目最终目标为AI斗地主,机器人最优方案对打。

26 | 27 |

声明:本项目谥在学习,任何用于违法用途的行为与作者无关。

28 | 29 |

如果对本项目感兴趣,欢迎加入QQ讨论群:8578575

30 | 31 |

目前尚处于研阶段,为了方便测试,HTML5做成了单机方式运行,但这并不影响后期部署成多端游戏。

32 | 33 |

github: https://github.com/2881099/FightLandlord

34 | 35 |

 

36 |

 

37 |
38 |

39 |

40 |

41 |

42 | 47 |

48 |

 

49 |

50 | 54 |

55 |
56 |
57 | 58 |
59 |
60 |
61 |
72 |
73 | 74 |
75 |
76 |
77 |
78 |
79 |

{{player.id}} 【{{player.role}}】

80 | 81 |

82 | 86 | 87 |

88 | 89 |

90 | 91 | 92 | 93 |

94 |
95 |
96 |
97 |
98 | 99 |
100 | 101 |

底牌

102 |

103 | {{'CpPcDqQdErReFsSfGtTgHuUhIvViJwWjKxXkLyYlMzZmAnNaBoOb??'[ddzdata.dipai[pkIndex]]}} 106 | 107 | 108 | {{'CpPcDqQdErReFsSfGtTgHuUhIvViJwWjKxXkLyYlMzZmAnNaBoOb??'[ddzdata.chupai[ddzdata.chupai.length - 1].result.value[pkIndex]]}} 111 | 112 | 113 | 114 | 游戏结束, 【{{ddzdata.players[ddzdata.chupai[ddzdata.chupai.length - 1].playerIndex].role}}】 胜利, 115 | 116 | 炸弹: {{ddzdata.bong}}, 倍数: {{ddzdata.multipleAddition}}, 金额: {{(ddzdata.bong + 1) * ddzdata.multipleAddition * ddzdata.multiple}}。 117 | 118 | 119 | 游戏结束,没有人当【地主】。 120 | 121 |

122 |
123 |
124 |
125 | 126 | 164 | 530 | 531 | 532 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost/wwwroot/poker.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WebHost/wwwroot/poker.ttf -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "3.1.0", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/BetGame.DDZ.WebHost2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Always 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Common/APIReturn.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | [JsonObject(MemberSerialization.OptIn)] 10 | public partial class APIReturn : ContentResult { 11 | [JsonProperty("code")] public int Code { get; protected set; } 12 | [JsonProperty("message")] public string Message { get; protected set; } 13 | [JsonProperty("data")] public Hashtable Data { get; protected set; } = new Hashtable(); 14 | [JsonProperty("success")] public bool Success { get { return this.Code == 0; } } 15 | 16 | public APIReturn() { } 17 | public APIReturn(int code) { this.SetCode(code); } 18 | public APIReturn(string message) { this.SetMessage(message); } 19 | public APIReturn(int code, string message, params object[] data) { this.SetCode(code).SetMessage(message).AppendData(data); } 20 | 21 | public APIReturn SetCode(int value) { this.Code = value; return this; } 22 | public APIReturn SetMessage(string value) { this.Message = value; return this; } 23 | public APIReturn SetData(params object[] value) { 24 | this.Data.Clear(); 25 | return this.AppendData(value); 26 | } 27 | public APIReturn AppendData(params object[] value) { 28 | if (value == null || value.Length < 2 || value[0] == null) return this; 29 | for (int a = 0; a < value.Length; a += 2) { 30 | if (value[a] == null) continue; 31 | this.Data[value[a]] = a + 1 < value.Length ? value[a + 1] : null; 32 | } 33 | return this; 34 | } 35 | #region form 表单 target=iframe 提交回调处理 36 | private void Jsonp(ActionContext context) { 37 | string __callback = context.HttpContext.Request.HasFormContentType ? context.HttpContext.Request.Form["__callback"].ToString() : null; 38 | if (string.IsNullOrEmpty(__callback)) { 39 | this.ContentType = "text/json;charset=utf-8;"; 40 | this.Content = JsonConvert.SerializeObject(this); 41 | } else { 42 | this.ContentType = "text/html;charset=utf-8"; 43 | this.Content = $""; 44 | } 45 | } 46 | public override void ExecuteResult(ActionContext context) { 47 | Jsonp(context); 48 | base.ExecuteResult(context); 49 | } 50 | public override Task ExecuteResultAsync(ActionContext context) { 51 | Jsonp(context); 52 | return base.ExecuteResultAsync(context); 53 | } 54 | #endregion 55 | 56 | public static APIReturn 成功 { get { return new APIReturn(0, "成功"); } } 57 | public static APIReturn 失败 { get { return new APIReturn(99, "失败"); } } 58 | public static APIReturn 记录不存在_或者没有权限 { get { return new APIReturn(98, "记录不存在,或者没有权限"); } } 59 | public static APIReturn 参数格式不正确 { get { return new APIReturn(97, "参数格式不正确"); } } 60 | } 61 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Common/CustomExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Logging; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Security.Cryptography; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | public class CustomExceptionFilter : Attribute, IExceptionFilter { 14 | 15 | private ILogger _logger = null; 16 | private IConfiguration _cfg = null; 17 | 18 | public CustomExceptionFilter(ILogger logger, IConfiguration cfg) { 19 | _logger = logger; 20 | _cfg = cfg; 21 | } 22 | 23 | public void OnException(ExceptionContext context) { 24 | //在这里记录错误日志,context.Exception 为异常对象 25 | context.Result = APIReturn.失败.SetMessage(context.Exception.Message); //返回给调用方 26 | var innerLog = context.Exception.InnerException != null ? $" \r\n{context.Exception.InnerException.Message} \r\n{ context.Exception.InnerException.StackTrace}" : ""; 27 | _logger.LogError($"=============错误:{context.Exception.Message} \r\n{context.Exception.StackTrace}{innerLog}"); 28 | context.ExceptionHandled = true; 29 | } 30 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Common/GlobalExtensions.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | public static class GlobalExtensions { 6 | public static object Json(this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper html, object obj) { 7 | string str = JsonConvert.SerializeObject(obj); 8 | if (!string.IsNullOrEmpty(str)) str = Regex.Replace(str, @"<(/?script[\s>])", "<\"+\"$1", RegexOptions.IgnoreCase); 9 | if (html == null) return str; 10 | return html.Raw(str); 11 | } 12 | 13 | /// 14 | /// 转格林时间,并以ISO8601格式化字符串 15 | /// 16 | /// 17 | /// 18 | public static string ToGmtISO8601(this DateTime time) { 19 | return time.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); 20 | } 21 | 22 | /// 23 | /// 获取时间戳,按1970-1-1 24 | /// 25 | /// 26 | /// 27 | public static long GetTime(this DateTime time) { 28 | return (long)time.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds; 29 | } 30 | 31 | /// 32 | /// 获取时间戳毫秒数,按1970-1-1 33 | /// 34 | /// 35 | /// 36 | public static long GetTimeMilliseconds(this DateTime time) { 37 | return (long)time.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Controllers/DDZGamePlayController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Concurrent; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using BetGame.DDZ; 9 | using BetGame.DDZ.WebHost2.Model; 10 | using Microsoft.AspNetCore.Mvc.Filters; 11 | using System.Threading; 12 | using FreeSql; 13 | 14 | namespace BetGame.DDZ.WebHost2.Controllers 15 | { 16 | [Route("ddz"), ServiceFilter(typeof(CustomExceptionFilter))] 17 | public class DDZGamePlayController : Controller 18 | { 19 | 20 | static Timer timer; 21 | static DDZGamePlayController() 22 | { 23 | ConcurrentDictionary offlineSitdownDic = new ConcurrentDictionary(); 24 | timer = new Timer(state => 25 | { 26 | foreach (var k in offlineSitdownDic.Keys) 27 | { 28 | if (offlineSitdownDic.TryGetValue(k, out var tryval) && DateTime.Now.Subtract(tryval.Item2).TotalSeconds > 4) 29 | { 30 | try 31 | { 32 | var ddzid = RedisHelper.HGet("ddz_gameplay_player_ht", tryval.Item1.Id.ToString()); 33 | if (!string.IsNullOrEmpty(ddzid)) 34 | { 35 | var ddz = GamePlay.GetById(ddzid); 36 | foreach (var pl in ddz.Data.players) 37 | { 38 | if (pl.id == tryval.Item1.Nick) 39 | { 40 | pl.score = ddz.Data.multiple * (ddz.Data.multipleAddition + ddz.Data.bong) * -2; 41 | pl.status = GamePlayerStatus.逃跑; 42 | } 43 | else 44 | pl.score = ddz.Data.multiple * (ddz.Data.multipleAddition + ddz.Data.bong); 45 | } 46 | ddz.Data.stage = GameStage.游戏结束; 47 | ddz.SaveData(); 48 | } 49 | StandupStatic(tryval.Item1).Wait(); 50 | } 51 | catch { } 52 | } 53 | } 54 | }, null, 2000, 2000); 55 | 56 | ImHelper.EventBus( 57 | t => 58 | { 59 | Console.WriteLine(t.clientId + "上线了"); 60 | try 61 | { 62 | var onlineUids = ImHelper.GetClientListByOnline(); 63 | ImHelper.SendMessage(t.clientId, onlineUids, $"用户{t.clientId}上线了"); 64 | if (offlineSitdownDic.TryRemove(t.clientId, out var oldval)) 65 | { 66 | var ddzid = RedisHelper.HGet("ddz_gameplay_player_ht", t.clientId.ToString()); 67 | if (!string.IsNullOrEmpty(ddzid)) 68 | { 69 | var ddz = GamePlay.GetById(ddzid); 70 | var player = Player.Find(t.clientId); 71 | SendGameMessage(ddz, new[] { player }); 72 | } 73 | } 74 | } 75 | catch 76 | { 77 | } 78 | }, 79 | t => 80 | { 81 | Console.WriteLine(t.clientId + "下线了"); 82 | try 83 | { 84 | //用户离线后4秒,才退出座位 85 | if (RedisHelper.HExists("sitdown_player_ht", t.clientId.ToString())) 86 | { 87 | var player = Player.Find(t.clientId); 88 | if (player != null) 89 | offlineSitdownDic.TryAdd(t.clientId, (player, DateTime.Now)); 90 | } 91 | } 92 | catch 93 | { 94 | } 95 | }); 96 | 97 | GamePlay.OnGameOver = game => OnGameOver(game); 98 | GamePlay.OnOperatorTimeout = game => SendGameMessage(game, null); 99 | 100 | RedisHelper.Del("sitdown_ht", "sitdown_player_ht"); 101 | } 102 | [FromForm(Name = "playerId")] 103 | public Guid PlayerId { get; set; } 104 | public Player CurrentPlayer { get; set; } 105 | 106 | async Task CheckPlayer(bool notExistsThrow = true) 107 | { 108 | if (PlayerId != Guid.Empty) 109 | CurrentPlayer = await Player.FindAsync(PlayerId); 110 | if (notExistsThrow && CurrentPlayer == null) 111 | throw new Exception("From 参数 playerId 错误,找不到用户"); 112 | } 113 | 114 | [HttpPost("GetPlayer")] 115 | async public Task GetPlayer() 116 | { 117 | await CheckPlayer(false); 118 | return APIReturn.成功.SetData("player", CurrentPlayer); 119 | } 120 | [HttpPost("GetOrAddPlayer")] 121 | async public Task GetOrAddPlayer([FromForm] string nick) 122 | { 123 | nick = nick?.Trim(); 124 | if (string.IsNullOrEmpty(nick)) throw new ArgumentException(nameof(nick)); 125 | 126 | await CheckPlayer(false); 127 | if (CurrentPlayer == null) 128 | { 129 | if (await Player.Where(a => a.Nick == nick).AnyAsync()) 130 | return APIReturn.失败.SetMessage("玩家名已存在"); 131 | 132 | CurrentPlayer = await new Player { Id = PlayerId, Nick = nick, Score = 1000 }.InsertAsync(); 133 | } 134 | else 135 | { 136 | CurrentPlayer.Nick = nick; 137 | await CurrentPlayer.SaveAsync(); 138 | } 139 | return APIReturn.成功.SetData("player", CurrentPlayer); 140 | } 141 | 142 | [HttpPost("PrevConnectWebsocket")] 143 | async public Task PrevConnectWebsocket() 144 | { 145 | await CheckPlayer(); 146 | if (ImHelper.HasOnline(CurrentPlayer.Id)) return APIReturn.失败.SetMessage($"用户 {CurrentPlayer.Nick} 已在线,测试请使用多种浏览器模拟真实场景"); 147 | var wsserver = ImHelper.PrevConnectServer(CurrentPlayer.Id, "nil"); 148 | ImHelper.JoinChan(CurrentPlayer.Id, "ddz_chan"); 149 | return APIReturn.成功.SetData("server", wsserver); 150 | } 151 | 152 | [HttpPost("SendChannelMsg")] 153 | async public Task SendChannelMsg([FromForm] string channel, [FromForm] string message) 154 | { 155 | await CheckPlayer(); 156 | ImHelper.SendChanMessage(CurrentPlayer.Id, channel, message); 157 | return APIReturn.成功; 158 | } 159 | 160 | [HttpPost("GetDesks")] 161 | async public Task GetDesks() 162 | { 163 | await CheckPlayer(); 164 | var desks = await Desk.Select.OrderBy(a => a.Sort).ToListAsync(); 165 | var keys = desks.Select(a => new[] { $"{a.Id}_1", $"{a.Id}_2", $"{a.Id}_3" }).SelectMany(a => a).ToArray(); 166 | var vals = RedisHelper.HMGet("sitdown_ht", keys); 167 | var ret = desks.Select((a, b) => new 168 | { 169 | a.Id, 170 | a.Title, 171 | player1 = vals[b * 3], 172 | player2 = vals[b * 3 + 1], 173 | player3 = vals[b * 3 + 2] 174 | }); 175 | return APIReturn.成功.SetData("desks", ret); 176 | } 177 | 178 | async public static Task StandupStatic(Player player) 179 | { 180 | var sitdownKey = RedisHelper.HGet("sitdown_player_ht", player.Id.ToString()); 181 | if (!string.IsNullOrEmpty(sitdownKey)) 182 | { 183 | RedisHelper.StartPipe(a => a.HDel("sitdown_player_ht", player.Id.ToString()).HDel("sitdown_ht", sitdownKey)); 184 | //通知消息,坐位有用户离开 185 | var dp = sitdownKey.Split('_'); 186 | var deskId = int.Parse(dp[0]); 187 | var desk = await Desk.FindAsync(deskId); 188 | ImHelper.SendChanMessage(Guid.Empty, "ddz_chan", new 189 | { 190 | type = "Standup", 191 | deskId = desk.Id, 192 | pos = int.Parse(dp[1]), 193 | msg = $"{player.Nick} 离开了座位 ({desk.Title}, POS:{dp[1]})" 194 | }); 195 | } 196 | } 197 | [HttpPost("Standup")] 198 | async public Task Standup() 199 | { 200 | await CheckPlayer(); 201 | await StandupStatic(CurrentPlayer); 202 | return APIReturn.成功; 203 | } 204 | [HttpPost("Sitdown")] 205 | async public Task Sitdown([FromForm] int deskId, [FromForm] int pos) 206 | { 207 | await CheckPlayer(); 208 | var desk = await Desk.FindAsync(deskId); 209 | if (desk == null || pos < 1 || pos > 3) throw new Exception("桌位或座位不存在"); 210 | await Standup(); 211 | var sitdowned = RedisHelper.HGet("sitdown_ht", $"{desk.Id}_{pos}"); 212 | if (sitdowned != null && sitdowned.Id != CurrentPlayer.Id) throw new Exception("该桌位已被其他用户坐下"); 213 | if (!RedisHelper.HSetNx("sitdown_ht", $"{desk.Id}_{pos}", CurrentPlayer)) throw new Exception("该桌位已被其他用户坐下"); 214 | RedisHelper.HSet("sitdown_player_ht", CurrentPlayer.Id.ToString(), $"{desk.Id}_{pos}"); 215 | //通知消息,坐位有用户坐下 216 | ImHelper.SendChanMessage(Guid.Empty, "ddz_chan", new 217 | { 218 | type = "Sitdown", 219 | deskId = desk.Id, 220 | pos = pos, 221 | player = CurrentPlayer, 222 | msg = $"{CurrentPlayer.Nick} 坐下了座位 ({desk.Title}, POS:{pos})" 223 | }); 224 | //判断三人都在,游戏开始 225 | var players = RedisHelper.HMGet("sitdown_ht", new[] { $"{desk.Id}_1", $"{desk.Id}_2", $"{desk.Id}_3" }); 226 | if (players.Where(a => a == null).Any() == false) 227 | { 228 | var ddz = GamePlay.Create(players.Select(a => a.Nick).ToArray(), 1, 3); 229 | ddz.Shuffle(); 230 | ImHelper.JoinChan(players[0].Id, desk.Title); 231 | ImHelper.JoinChan(players[1].Id, desk.Title); 232 | ImHelper.JoinChan(players[2].Id, desk.Title); 233 | ImHelper.SendChanMessage(Guid.Empty, "ddz_chan", new 234 | { 235 | type = "GameStarted", 236 | deskId = desk.Id, 237 | players = players, 238 | msg = $"{desk.Title} 三人就位,游戏开始,{players[0].Nick} VS {players[1].Nick} VS {players[2].Nick}" 239 | }); 240 | RedisHelper.StartPipe(a => a 241 | .HMSet($"ddz_gameplay_ht{ddz.Id}", "players", players, "desk", desk) 242 | .HMSet("ddz_gameplay_player_ht", players[0].Id.ToString(), ddz.Id, players[1].Id.ToString(), ddz.Id, players[2].Id.ToString(), ddz.Id, 243 | players[0].Nick, ddz.Id, players[1].Nick, ddz.Id, players[2].Nick, ddz.Id)); 244 | SendGameMessage(ddz, players); 245 | } 246 | return APIReturn.成功; 247 | } 248 | 249 | //游戏环节 250 | public static void SendGameMessage(GamePlay game, Player[] players) 251 | { 252 | if (players == null) 253 | players = RedisHelper.HGet($"ddz_gameplay_ht{game.Id}", "players"); 254 | 255 | foreach (var player in players) 256 | { 257 | ImHelper.SendMessage(Guid.Empty, new[] { player.Id }, new 258 | { 259 | type = "GamePlay", 260 | ddzid = game.Id, 261 | data = game.Data.CloneToPlayer(player.Nick) 262 | }); 263 | } 264 | } 265 | 266 | static object updateScoreLock = new object(); 267 | public static void OnGameOver(GamePlay game) 268 | { 269 | var gpdb = RedisHelper.StartPipe(a => a 270 | .HGet($"ddz_gameplay_ht{game.Id}", "players") 271 | .HGet($"ddz_gameplay_ht{game.Id}", "desk")); 272 | var players = gpdb[0] as Player[]; 273 | var desk = gpdb[1] as Desk; 274 | ImHelper.LeaveChan(players[0].Id, desk.Title); 275 | ImHelper.LeaveChan(players[1].Id, desk.Title); 276 | ImHelper.LeaveChan(players[2].Id, desk.Title); 277 | RedisHelper.StartPipe(a => a 278 | .HDel($"ddz_gameplay_ht{game.Id}", "players", "desk") 279 | .HDel("ddz_gameplay_player_ht", players[0].Id.ToString(), players[1].Id.ToString(), players[2].Id.ToString(), 280 | players[0].Nick, players[1].Nick, players[2].Nick) 281 | .HDel("sitdown_ht", new[] { $"{desk.Id}_1", $"{desk.Id}_2", $"{desk.Id}_3" }) 282 | .HDel("sitdown_player_ht", players[0].Id.ToString(), players[1].Id.ToString(), players[2].Id.ToString())); 283 | 284 | Func getPlayerStats = pl => $"{pl.id}({pl.score})"; 285 | 286 | var playerScoreIncr = game.Data.players.Select(a => (long)a.score).ToArray(); 287 | lock (updateScoreLock) 288 | { 289 | BaseEntity.Orm.Update(players[0]).Set(a => a.Score + playerScoreIncr[0]).ExecuteAffrows(); 290 | BaseEntity.Orm.Update(players[1]).Set(a => a.Score + playerScoreIncr[1]).ExecuteAffrows(); 291 | BaseEntity.Orm.Update(players[2]).Set(a => a.Score + playerScoreIncr[2]).ExecuteAffrows(); 292 | } 293 | players[0].Score += playerScoreIncr[0]; 294 | players[1].Score += playerScoreIncr[1]; 295 | players[2].Score += playerScoreIncr[2]; 296 | 297 | ImHelper.SendChanMessage(Guid.Empty, "ddz_chan", new 298 | { 299 | type = "GameOvered", 300 | deskId = desk.Id, 301 | players = players, 302 | msg = $"{desk.Title} 【游戏结束】,本局炸弹 {game.Data.bong}个,{game.Data.players[0].id}({game.Data.players[0].score}),{game.Data.players[1].id}({game.Data.players[1].score}),{game.Data.players[2].id}({game.Data.players[2].score})" 303 | }); 304 | SendGameMessage(game, players); 305 | } 306 | 307 | [HttpPost("CancelAutoPlay")] 308 | public APIReturn CancelAutoPlay([FromForm] string id, [FromForm] string playerId) 309 | { 310 | var ddz = DDZGet(id); 311 | foreach(var pl in ddz.Data.players) 312 | if (pl.id == playerId) 313 | { 314 | if (pl.status == GamePlayerStatus.托管) 315 | { 316 | pl.status = GamePlayerStatus.正常; 317 | ddz.SaveData(); 318 | SendGameMessage(ddz, null); 319 | } 320 | break; 321 | } 322 | return APIReturn.成功; 323 | } 324 | 325 | GamePlay DDZGet(string id) { 326 | var ddz = GamePlay.GetById(id); 327 | return ddz; 328 | } 329 | 330 | [HttpPost("SelectLandlord")] 331 | public APIReturn 叫地主([FromForm] string id, [FromForm] string playerId, [FromForm] decimal multiple) { 332 | var ddz = DDZGet(id); 333 | ddz.SelectLandlord(playerId, multiple); 334 | SendGameMessage(ddz, null); 335 | return APIReturn.成功; 336 | } 337 | [HttpPost("SelectFarmer")] 338 | public APIReturn 不叫([FromForm] string id, [FromForm] string playerId) { 339 | var ddz = DDZGet(id); 340 | ddz.SelectFarmer(playerId); 341 | SendGameMessage(ddz, null); 342 | return APIReturn.成功; 343 | } 344 | 345 | [HttpPost("PlayTips")] 346 | public APIReturn 出牌提示([FromForm] string id, [FromForm] string playerId) { 347 | var ddz = DDZGet(id); 348 | var tips = ddz.PlayTips(playerId); 349 | return APIReturn.成功.SetData("tips", tips); 350 | } 351 | [HttpPost("Play")] 352 | public APIReturn 出牌([FromForm] string id, [FromForm] string playerId, [FromForm] int[] poker) { 353 | var ddz = DDZGet(id); 354 | ddz.Play(playerId, poker); 355 | 356 | var gpdb = RedisHelper.StartPipe(a => a 357 | .HGet($"ddz_gameplay_ht{ddz.Id}", "players") 358 | .HGet($"ddz_gameplay_ht{ddz.Id}", "desk")); 359 | var players = gpdb[0] as Player[]; 360 | var desk = gpdb[1] as Desk; 361 | SendGameMessage(ddz, gpdb[0] as Player[]); 362 | if (ddz.Data.stage == GameStage.游戏结束) 363 | { 364 | ImHelper.LeaveChan(players[0].Id, desk.Title); 365 | ImHelper.LeaveChan(players[1].Id, desk.Title); 366 | ImHelper.LeaveChan(players[2].Id, desk.Title); 367 | } 368 | return APIReturn.成功; 369 | } 370 | [HttpPost("Pass")] 371 | public APIReturn 不要([FromForm] string id, [FromForm] string playerId) { 372 | var ddz = DDZGet(id); 373 | ddz.Pass(playerId); 374 | SendGameMessage(ddz, null); 375 | return APIReturn.成功; 376 | } 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.0-bionic 2 | WORKDIR /app 3 | EXPOSE 80 4 | COPY . . 5 | ENTRYPOINT ["dotnet", "BetGame.DDZ.WebHost2.dll"] -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Model/Player.cs: -------------------------------------------------------------------------------- 1 | using FreeSql; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace BetGame.DDZ.WebHost2.Model 8 | { 9 | /// 10 | /// 玩家 11 | /// 12 | public class Player : BaseEntity 13 | { 14 | /// 15 | /// 昵称 16 | /// 17 | public string Nick { get; set; } 18 | /// 19 | /// 积分 20 | /// 21 | public long Score { get; set; } 22 | } 23 | 24 | /// 25 | /// 桌位 26 | /// 27 | public class Desk : BaseEntity 28 | { 29 | static Desk() 30 | { 31 | if (!Desk.Select.Any()) 32 | { 33 | for (var a = 1; a <= 20; a++) 34 | { 35 | new Desk { Title = $"{a}桌", Sort = a }.Insert(); 36 | } 37 | } 38 | } 39 | 40 | public string Title { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace BetGame.DDZ.WebHost2 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | FileSystem 9 | FileSystem 10 | Release 11 | Any CPU 12 | 13 | True 14 | False 15 | e910a384-9c4b-40dc-b40f-b2ff8162b374 16 | bin\Release\netcoreapp3.1\publish\ 17 | True 18 | netcoreapp3.1 19 | win-x64 20 | true 21 | 22 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:61244", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "BetGame.DDZ.WebHost2": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:61244" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/Startup.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WebHost2/Startup.cs -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "connectionString": "Data Source=webhost2.db;Pooling=true;Max Pool Size=3", 11 | "redis": "127.0.0.1:6397,defaultdatabase=10", 12 | "imserver": "127.0.0.1:61244" 13 | } 14 | -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/webhost2.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WebHost2/webhost2.db -------------------------------------------------------------------------------- /src/BetGame.DDZ.WebHost2/wwwroot.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saber-wang/FightLandlord/f1127147cb22f0de30cab7c4792740c1b2db12f7/src/BetGame.DDZ.WebHost2/wwwroot.zip -------------------------------------------------------------------------------- /src/BetGame.DDZ/BetGame.DDZ.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/BetGame.DDZ/GameInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace BetGame.DDZ { 6 | public class GameInfo { 7 | /// 8 | /// 打多大(普通基数)结算:multiple * (multipleAddition + Bong) 9 | /// 10 | public decimal multiple { get; set; } 11 | /// 12 | /// 附加倍数,抢地主环节 13 | /// 14 | public decimal multipleAddition { get; set; } 15 | /// 16 | /// 设定最大附加倍数 17 | /// 18 | public decimal multipleAdditionMax { get; set; } 19 | /// 20 | /// 炸弹次数 21 | /// 22 | public decimal bong { get; set; } 23 | /// 24 | /// 游戏玩家 25 | /// 26 | public List players { get; set; } 27 | /// 28 | /// 轮到哪位玩家操作 29 | /// 30 | public int playerIndex { get; set; } 31 | /// 32 | /// 底牌 33 | /// 34 | public int[] dipai { get; set; } 35 | public string[] dipaiText => Utils.GetPokerText(this.dipai); 36 | /// 37 | /// 出牌历史 38 | /// 39 | public List chupai { get; set; } 40 | /// 41 | /// 当前游戏阶段 42 | /// 43 | public GameStage stage { get; set; } 44 | 45 | /// 46 | /// 超时未操作,使用它与当前时间(utc)作对比判断,可惩罚 playerIndex 47 | /// 48 | public DateTime operationTimeout { get; set; } 49 | public int operationTimeoutSeconds => (int)operationTimeout.Subtract(DateTime.UtcNow).TotalSeconds; 50 | 51 | public GameInfo CloneToPlayer(string playerId) 52 | { 53 | var game = new GameInfo 54 | { 55 | multiple = multiple, 56 | multipleAddition = multipleAddition, 57 | multipleAdditionMax = multipleAdditionMax, 58 | bong = bong, 59 | playerIndex = playerIndex, 60 | chupai = chupai, 61 | stage = stage, 62 | operationTimeout = operationTimeout 63 | }; 64 | game.players = new List(); 65 | for (var a = 0; a < players.Count; a++) 66 | { 67 | var gp = new GamePlayer 68 | { 69 | id = players[a].id, 70 | poker = players[a].poker, 71 | pokerInit = players[a].pokerInit, 72 | role = players[a].role, 73 | score = players[a].score, 74 | status = players[a].status 75 | }; 76 | game.players.Add(gp); 77 | if (players[a].id != playerId) 78 | { 79 | gp.poker = gp.poker.Select(x => 54).ToList(); 80 | gp.pokerInit = gp.pokerInit.Select(x => 54).ToList(); 81 | } 82 | } 83 | game.dipai = dipai; 84 | switch (stage) 85 | { 86 | case GameStage.未开始: 87 | case GameStage.叫地主: 88 | game.dipai = game.dipai.Select(a => 54).ToArray(); 89 | break; 90 | } 91 | return game; 92 | } 93 | } 94 | 95 | public enum GameStage { 未开始, 叫地主, 斗地主, 游戏结束 } 96 | 97 | public class GamePlayer { 98 | /// 99 | /// 玩家 100 | /// 101 | public string id { get; set; } 102 | /// 103 | /// 玩家手上的牌 104 | /// 105 | public List poker { get; set; } 106 | public string[] pokerText => Utils.GetPokerText(this.poker); 107 | /// 108 | /// 玩家最初的牌 109 | /// 110 | public List pokerInit { get; set; } 111 | /// 112 | /// 玩家角色 113 | /// 114 | public GamePlayerRole role { get; set; } 115 | 116 | /// 117 | /// 计算结果 118 | /// 119 | public decimal score { get; set; } 120 | 121 | /// 122 | /// 状态 123 | /// 124 | public GamePlayerStatus status { get; set; } 125 | } 126 | 127 | public enum GamePlayerRole { 未知, 地主, 农民 } 128 | public enum GamePlayerStatus { 正常, 托管, 逃跑 } 129 | } 130 | -------------------------------------------------------------------------------- /src/BetGame.DDZ/GamePlay.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Collections.Concurrent; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | 10 | namespace BetGame.DDZ 11 | { 12 | public class GamePlay { 13 | /// 14 | /// 唯一标识 15 | /// 16 | public string Id { get; } 17 | public GameInfo Data { get; } 18 | 19 | public static Action OnSaveData; 20 | public static Func OnGetData; 21 | /// 22 | /// 洗牌后作二次分析,在这里可以重新洗牌、重新定庄家 23 | /// 24 | public static Action OnShuffle; 25 | /// 26 | /// 叫地主阶段,下一位,在这里可以处理机器人自动叫地主、选择农民 27 | /// 28 | public static Action OnNextSelect; 29 | /// 30 | /// 斗地主阶段,下一位,在这里可以处理机器人自动出牌 31 | /// 32 | public static Action OnNextPlay; 33 | /// 34 | /// 游戏结束,通知前端 35 | /// 36 | public static Action OnGameOver; 37 | /// 38 | /// 玩家超时未操作,自动托管,并且已经执行了操作 39 | /// 40 | public static Action OnOperatorTimeout; 41 | 42 | private static readonly ThreadLocal rnd = new ThreadLocal(() => new Random()); 43 | private static ConcurrentDictionary operatorTimeoutDic = new ConcurrentDictionary(); 44 | private static Timer timer2s = new Timer(timer2sCallback, null, 2000, 2000); 45 | private static void timer2sCallback(object state) 46 | { 47 | timer2s.Change(60000, 60000); 48 | try 49 | { 50 | foreach (var k in operatorTimeoutDic.Keys) 51 | { 52 | if (operatorTimeoutDic.TryGetValue(k, out var val) == false) continue; 53 | if (val.Data.stage == GameStage.游戏结束) 54 | { 55 | operatorTimeoutDic.TryRemove(k, out var old); 56 | continue; 57 | } 58 | 59 | if (DateTime.UtcNow.Subtract(val.Data.operationTimeout).TotalSeconds > 1) 60 | { 61 | operatorTimeoutDic.TryRemove(k, out var old); 62 | val.Data.players[val.Data.playerIndex].status = GamePlayerStatus.托管; 63 | NextAutoOperator(val); 64 | OnOperatorTimeout?.Invoke(val); 65 | continue; 66 | } 67 | } 68 | } 69 | catch { } 70 | timer2s.Change(2000, 2000); 71 | } 72 | /// 73 | /// 托管后自动处理 74 | /// 75 | /// 76 | private static void NextAutoOperator(GamePlay game) 77 | { 78 | if (game.Data.stage == GameStage.游戏结束) return; 79 | var player = game.Data.players[game.Data.playerIndex]; 80 | if (player.status != GamePlayerStatus.托管) return; 81 | switch (game.Data.stage) 82 | { 83 | case GameStage.叫地主: 84 | game.SelectFarmer(player.id); 85 | break; 86 | case GameStage.斗地主: 87 | var pks = game.PlayTips(player.id); 88 | if (pks.Any() == false) 89 | game.Pass(player.id); 90 | else 91 | game.Play(player.id, pks[0]); 92 | break; 93 | } 94 | } 95 | 96 | private GamePlay(string id) { 97 | if (string.IsNullOrEmpty(id) == false) { 98 | this.Data = this.EventGetData(id); 99 | if (this.Data == null) throw new ArgumentException("根据 id 参数找不到斗地主数据"); 100 | this.Id = id; 101 | } else { 102 | this.Data = new GameInfo(); 103 | this.Id = Guid.NewGuid().ToString(); 104 | } 105 | } 106 | public void SaveData() { 107 | if (this.Data.stage == GameStage.游戏结束) 108 | { 109 | operatorTimeoutDic.TryRemove(this.Id, out var old); 110 | OnGameOver?.Invoke(this); 111 | } 112 | else 113 | operatorTimeoutDic.AddOrUpdate(this.Id, this, (k, old) => this); 114 | if (OnSaveData != null) { 115 | OnSaveData(this.Id, this.Data); 116 | return; 117 | } 118 | RedisHelper.HSet($"DDZrdb", this.Id, this.Data); 119 | } 120 | private GameInfo EventGetData(string id) { 121 | if (OnGetData != null) { 122 | return OnGetData(id); 123 | } 124 | return RedisHelper.HGet("DDZrdb", id); 125 | } 126 | 127 | /// 128 | /// 创建一局游戏 129 | /// 130 | /// 131 | /// 132 | /// 133 | /// 134 | public static GamePlay Create(string[] playerIds, decimal multiple = 1, decimal multipleAdditionMax = 3) { 135 | if (playerIds == null) throw new ArgumentException("players 参数不能为空"); 136 | if (playerIds.Length != 3) throw new ArgumentException("players 参数长度必须 3"); 137 | 138 | var fl = new GamePlay(null); 139 | fl.Data.multiple = multiple; 140 | fl.Data.multipleAdditionMax = multipleAdditionMax; 141 | fl.Data.dipai = new int[3]; 142 | fl.Data.chupai = new List(); 143 | fl.Data.stage = GameStage.未开始; 144 | fl.Data.players = new List(); 145 | 146 | for (var a = 0; a < playerIds.Length; a++) 147 | fl.Data.players.Add(new GamePlayer { id = playerIds[a], poker = new List(), pokerInit = new List(), role = GamePlayerRole.未知 }); 148 | 149 | fl.Data.operationTimeout = DateTime.UtcNow.AddSeconds(60); 150 | fl.SaveData(); 151 | return fl; 152 | } 153 | /// 154 | /// 查找一局游戏 155 | /// 156 | /// 157 | /// 158 | public static GamePlay GetById(string id) { 159 | if (string.IsNullOrEmpty(id)) throw new ArgumentException("id 参数不能为空"); 160 | return new GamePlay(id); 161 | } 162 | 163 | /// 164 | /// 洗牌 165 | /// 166 | public void Shuffle() { 167 | if (this.Data.stage != GameStage.未开始) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 168 | 169 | this.Data.multipleAddition = 0; 170 | this.Data.bong = 0; 171 | this.Data.stage = GameStage.叫地主; 172 | 173 | //洗牌 174 | var tmppks = Utils.GetNewPoker(); 175 | var pks = new byte[tmppks.Count]; 176 | for (var a = 0; a < pks.Length; a++) { 177 | pks[a] = (byte)tmppks[rnd.Value.Next(tmppks.Count)]; 178 | tmppks.Remove(pks[a]); 179 | } 180 | //确定庄家,谁先拿牌 181 | this.Data.playerIndex = rnd.Value.Next(this.Data.players.Count); 182 | ///分牌 183 | this.Data.dipai[0] = pks[51]; 184 | this.Data.dipai[1] = pks[52]; 185 | this.Data.dipai[2] = pks[53]; 186 | for (int a = 0, b = this.Data.playerIndex; a < 51; a++) { 187 | this.Data.players[b].poker.Add(pks[a]); 188 | this.Data.players[b].pokerInit.Add(pks[a]); 189 | if (++b >= this.Data.players.Count) b = 0; 190 | } 191 | OnShuffle?.Invoke(this); //在此做AI分析 192 | for (var a = 0; a < this.Data.players.Count; a++) { 193 | this.Data.players[a].poker.Sort((x, y) => y.CompareTo(x)); 194 | } 195 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(15); 196 | this.SaveData(); 197 | WriteLog($"【洗牌分牌】完毕,进入【叫地主】环节,轮到庄家 {this.Data.players[this.Data.playerIndex].id} 先叫"); 198 | OnNextSelect?.Invoke(this); 199 | } 200 | void WriteLog(object obj) { 201 | Trace.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] {JsonConvert.SerializeObject(obj).Trim('"')}\r\n{this.Id}: {JsonConvert.SerializeObject(this.Data)}"); 202 | } 203 | 204 | /// 205 | /// 叫地主 206 | /// 207 | /// 208 | /// 209 | public void SelectLandlord(string playerId, decimal multiple) { 210 | if (this.Data.stage != GameStage.叫地主) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 211 | var playerIndex = this.Data.players.FindIndex(a => a.id == playerId); 212 | if (playerIndex == -1) throw new ArgumentException($"{playerId} 不在本局游戏"); 213 | if (playerIndex != this.Data.playerIndex) throw new ArgumentException($"还没有轮到 {playerId} 叫地主"); 214 | if (multiple <= this.Data.multipleAddition) throw new ArgumentException($"multiple 参数应该 > 当前附加倍数 {this.Data.multipleAddition}"); 215 | if (multiple > this.Data.multipleAdditionMax) throw new ArgumentException($"multiple 参数应该 <= 设定最大附加倍数 {this.Data.multipleAdditionMax}"); 216 | this.Data.multipleAddition = multiple; 217 | if (this.Data.multipleAddition == this.Data.multipleAdditionMax) { 218 | this.Data.players[this.Data.playerIndex].role = GamePlayerRole.地主; 219 | this.Data.players[this.Data.playerIndex].poker.AddRange(this.Data.dipai); 220 | this.Data.players[this.Data.playerIndex].poker.Sort((x, y) => y.CompareTo(x)); 221 | for (var a = 0; a < this.Data.players.Count; a++) if (this.Data.players[a].role == GamePlayerRole.未知) this.Data.players[a].role = GamePlayerRole.农民; 222 | this.Data.stage = GameStage.斗地主; 223 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(30); 224 | this.SaveData(); 225 | WriteLog($"{this.Data.players[this.Data.playerIndex].id} 以设定最大附加倍数【叫地主】成功,进入【斗地主】环节,轮到庄家 {this.Data.players[this.Data.playerIndex].id} 出牌"); 226 | OnNextPlay?.Invoke(this); 227 | } else { 228 | while (true) { 229 | if (++this.Data.playerIndex >= this.Data.players.Count) this.Data.playerIndex = 0; 230 | if (this.Data.players[this.Data.playerIndex].role == GamePlayerRole.未知) break; //跳过已确定的农民 231 | } 232 | if (this.Data.playerIndex == playerIndex) { 233 | this.Data.players[this.Data.playerIndex].role = GamePlayerRole.地主; 234 | this.Data.players[this.Data.playerIndex].poker.AddRange(this.Data.dipai); 235 | this.Data.players[this.Data.playerIndex].poker.Sort((x, y) => y.CompareTo(x)); 236 | this.Data.stage = GameStage.斗地主; 237 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(30); 238 | this.SaveData(); 239 | WriteLog($"{this.Data.players[this.Data.playerIndex].id} 附加倍数{multiple}【叫地主】成功,进入【斗地主】环节,轮到庄家 {this.Data.players[this.Data.playerIndex].id} 出牌"); 240 | OnNextSelect?.Invoke(this); 241 | } else { 242 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(15); 243 | this.SaveData(); 244 | WriteLog($"{this.Data.players[playerIndex].id} 【叫地主】 +{this.Data.multipleAddition}倍,轮到 {this.Data.players[this.Data.playerIndex].id} 叫地主"); 245 | OnNextSelect?.Invoke(this); 246 | } 247 | } 248 | NextAutoOperator(this); 249 | } 250 | /// 251 | /// 不叫地主,选择农民 252 | /// 253 | /// 254 | public void SelectFarmer(string playerId) { 255 | if (this.Data.stage != GameStage.叫地主) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 256 | var playerIndex = this.Data.players.FindIndex(a => a.id == playerId); 257 | if (playerIndex == -1) throw new ArgumentException($"{playerId} 不在本局游戏"); 258 | if (playerIndex != this.Data.playerIndex) throw new ArgumentException($"还没有轮到 {playerId} 操作"); 259 | this.Data.players[playerIndex].role = GamePlayerRole.农民; 260 | var unkonws = this.Data.players.Where(a => a.role == GamePlayerRole.未知).Count(); 261 | if (unkonws == 1 && this.Data.multipleAddition > 0) { 262 | this.Data.playerIndex = this.Data.players.FindIndex(a => a.role == GamePlayerRole.未知); 263 | this.Data.players[this.Data.playerIndex].role = GamePlayerRole.地主; 264 | this.Data.players[this.Data.playerIndex].poker.AddRange(this.Data.dipai); 265 | this.Data.players[this.Data.playerIndex].poker.Sort((x, y) => y.CompareTo(x)); 266 | for (var a = 0; a < this.Data.players.Count; a++) if (this.Data.players[a].role == GamePlayerRole.未知) this.Data.players[a].role = GamePlayerRole.农民; 267 | this.Data.stage = GameStage.斗地主; 268 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(30); 269 | this.SaveData(); 270 | WriteLog($"{this.Data.players[playerIndex].id} 选择农民,{this.Data.players[this.Data.playerIndex].id} 【叫地主】成功,进入【斗地主】环节,轮到庄家 {this.Data.players[this.Data.playerIndex].id} 出牌"); 271 | OnNextPlay?.Invoke(this); 272 | } else if (unkonws == 0) { 273 | this.Data.stage = GameStage.游戏结束; 274 | this.SaveData(); 275 | WriteLog($"所有玩家选择农民,【游戏结束】"); 276 | } else { 277 | while (true) { 278 | if (++this.Data.playerIndex >= this.Data.players.Count) this.Data.playerIndex = 0; 279 | if (this.Data.players[this.Data.playerIndex].role == GamePlayerRole.未知) break; //跳过已确定的农民 280 | } 281 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(15); 282 | this.SaveData(); 283 | WriteLog($"{this.Data.players[playerIndex].id} 选择农民,轮到 {this.Data.players[this.Data.playerIndex].id} 叫地主"); 284 | OnNextSelect?.Invoke(this); 285 | } 286 | NextAutoOperator(this); 287 | } 288 | 289 | /// 290 | /// 提示出牌 291 | /// 292 | /// 293 | /// 294 | public List PlayTips(string playerId) { 295 | if (this.Data.stage != GameStage.斗地主) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 296 | var playerIndex = this.Data.players.FindIndex(a => a.id == playerId); 297 | if (playerIndex == -1) throw new ArgumentException($"{playerId} 不在本局游戏"); 298 | if (playerIndex != this.Data.playerIndex) throw new ArgumentException($"还没有轮到 {playerId} 出牌"); 299 | var uphand = this.Data.chupai.LastOrDefault(); 300 | if (uphand?.playerIndex == this.Data.playerIndex) uphand = null; 301 | return Utils.GetAllTips(this.Data.players[this.Data.playerIndex].poker, uphand); 302 | } 303 | 304 | /// 305 | /// 出牌 306 | /// 307 | /// 308 | /// 309 | public void Play(string playerId, int[] poker) { 310 | if (this.Data.stage != GameStage.斗地主) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 311 | var playerIndex = this.Data.players.FindIndex(a => a.id == playerId); 312 | if (playerIndex == -1) throw new ArgumentException($"{playerId} 不在本局游戏"); 313 | if (playerIndex != this.Data.playerIndex) throw new ArgumentException($"还没有轮到 {playerId} 出牌"); 314 | if (poker == null || poker.Length == 0) throw new ArgumentException("poker 不能为空"); 315 | foreach (var pk in poker) if (this.Data.players[this.Data.playerIndex].poker.Contains(pk) == false) throw new ArgumentException($"{playerId} 手上没有这手牌"); 316 | var hand = new HandPokerInfo { time = DateTime.Now, playerIndex = this.Data.playerIndex, result = Utils.ComplierHandPoker(Utils.GroupByPoker(poker)) }; 317 | if (hand.result == null) throw new ArgumentException("poker 不是有效的一手牌"); 318 | var uphand = this.Data.chupai.LastOrDefault(); 319 | if (uphand != null && uphand.playerIndex != this.Data.playerIndex && Utils.CompareHandPoker(hand, uphand) <= 0) throw new ArgumentException("poker 打不过上一手牌"); 320 | this.Data.chupai.Add(hand); 321 | foreach (var pk in poker) this.Data.players[this.Data.playerIndex].poker.Remove(pk); 322 | 323 | if (hand.result.type == HandPokerType.四条炸 || hand.result.type == HandPokerType.王炸) this.Data.bong += 1; 324 | 325 | if (this.Data.players[this.Data.playerIndex].poker.Count == 0) { 326 | var wealth = this.Data.multiple * (this.Data.multipleAddition + this.Data.bong); 327 | var dizhuWinner = this.Data.players[this.Data.playerIndex].role == GamePlayerRole.地主; 328 | this.Data.stage = GameStage.游戏结束; 329 | foreach (var player in this.Data.players) 330 | { 331 | if (dizhuWinner) player.score = player.role == GamePlayerRole.地主 ? 2 * wealth : -wealth; 332 | else player.score = player.role == GamePlayerRole.地主 ? 2 * -wealth : wealth; 333 | } 334 | this.SaveData(); 335 | WriteLog($"{this.Data.players[playerIndex].id} 出牌 {hand.result.text},【游戏结束】,{(dizhuWinner ? GamePlayerRole.地主 : GamePlayerRole.农民)} 获得了胜利,本局炸弹 {this.Data.bong}个,结算金额 {wealth}"); 336 | } else { 337 | if (++this.Data.playerIndex >= this.Data.players.Count) this.Data.playerIndex = 0; 338 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(30); 339 | this.SaveData(); 340 | WriteLog($"{this.Data.players[playerIndex].id} 出牌 {hand.result.text},轮到 {this.Data.players[this.Data.playerIndex].id} 出牌"); 341 | OnNextPlay?.Invoke(this); 342 | } 343 | NextAutoOperator(this); 344 | } 345 | 346 | /// 347 | /// 不要 348 | /// 349 | /// 350 | public void Pass(string playerId) { 351 | if (this.Data.stage != GameStage.斗地主) throw new ArgumentException($"游戏阶段错误,当前阶段:{this.Data.stage}"); 352 | var playerIndex = this.Data.players.FindIndex(a => a.id == playerId); 353 | if (playerIndex == -1) throw new ArgumentException($"{playerId} 不在本局游戏"); 354 | if (playerIndex != this.Data.playerIndex) throw new ArgumentException($"还没有轮到 {playerId} 出牌"); 355 | var uphand = this.Data.chupai.LastOrDefault(); 356 | if (uphand == null) throw new ArgumentException("第一手牌不能 Pass"); 357 | if (uphand.playerIndex == this.Data.playerIndex) throw new ArgumentException("此时应该出牌,不能 Pass"); 358 | if (++this.Data.playerIndex >= this.Data.players.Count) this.Data.playerIndex = 0; 359 | this.Data.operationTimeout = DateTime.UtcNow.AddSeconds(30); 360 | this.SaveData(); 361 | WriteLog($"{this.Data.players[playerIndex].id} 不要,轮到 {this.Data.players[this.Data.playerIndex].id} 出牌"); 362 | OnNextPlay?.Invoke(this); 363 | NextAutoOperator(this); 364 | } 365 | } 366 | } 367 | -------------------------------------------------------------------------------- /src/BetGame.DDZ/HandPokerInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BetGame.DDZ { 4 | public class HandPokerInfo { 5 | /// 6 | /// 出牌时间 7 | /// 8 | public DateTime time { get; set; } 9 | /// 10 | /// 这手牌出自哪位玩家 11 | /// 12 | public int playerIndex { get; set; } 13 | /// 14 | /// 牌编译结果 15 | /// 16 | public HandPokerComplieResult result { get; set; } 17 | } 18 | 19 | public enum HandPokerType { 个, 对, 三条, 三条带一个, 三条带一对, 顺子, 连对, 飞机, 飞机带N个, 飞机带N对, 炸带二个, 炸带二对, 四条炸, 王炸 } 20 | 21 | public class HandPokerComplieResult { 22 | public HandPokerType type { get; set; } 23 | /// 24 | /// 相同类型比较大小 25 | /// 26 | public int compareValue { get; set; } 27 | /// 28 | /// 牌 29 | /// 30 | public int[] value { get; set; } 31 | /// 32 | /// 牌面字符串 33 | /// 34 | public string[] text { get; set; } 35 | } 36 | } 37 | --------------------------------------------------------------------------------