├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── Models ├── Air.fbx ├── Darkness.fbx ├── HorisontalWall.fbx ├── Path.fbx ├── Player.fbx └── VerticalWall.fbx ├── README.md ├── imgs ├── Demo130816_1.jpg ├── Demo130816_2.jpg ├── Demo130816_3.jpg ├── Demo130816_4.jpg ├── Demo130816_5.jpg └── demo.gif ├── libs └── LibBinary │ ├── Microsoft.AspNetCore.SignalR.Messaging.dll │ ├── Microsoft.AspNetCore.SignalR.Messaging.dll.nuspec │ ├── Microsoft.AspNetCore.SignalR.Server.dll │ └── Microsoft.AspNetCore.SignalR.Server.dll.nuspec └── src ├── Game.Console ├── Game.Console.xproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── project.fragment.lock.json └── project.json ├── Game.Server ├── Game.Server.csproj ├── Hubs │ └── ServerHub.cs ├── Identification │ ├── IdentityConfig.cs │ ├── IdentityModels.cs │ └── Startup.Auth.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Service References │ └── Application Insights │ │ └── ConnectedService.json ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config ├── LandSky.sln ├── Server ├── Controllers │ └── ValuesController.cs ├── Program.cs ├── Project_Readme.html ├── Properties │ └── launchSettings.json ├── Server.xproj ├── Startup.cs ├── appsettings.json ├── project.fragment.lock.json ├── project.json ├── web.config └── wwwroot │ ├── index.html │ └── palyerHub.js ├── WebApp ├── package.json └── tsconfig.json ├── core.Portable ├── AsciiTexture.cs ├── Commands │ ├── BaseCommand.cs │ ├── GeneratePathCommand.cs │ ├── GenerateRoomsCommand.cs │ ├── MoveCommand.cs │ ├── ScreenToJsonCommand.cs │ └── ScrollCommand.cs ├── Components │ ├── Cell.cs │ ├── Component.cs │ ├── InfinitePlane.cs │ ├── Path.cs │ ├── Player.cs │ ├── Room.cs │ └── Walls.cs ├── Controls.cs ├── DebugItems │ └── DebugMessage.cs ├── DotNetExt │ ├── ConsoleKeyInfo.cs │ └── IMyConsoleKeyInfo.cs ├── Engine.cs ├── IClient.cs ├── IServer.cs ├── MyEnums │ └── Enums.cs ├── MyEventArgs │ └── ScreenChangedArgs.cs ├── MyMath │ ├── FastMath.cs │ ├── Interolator.cs │ ├── Monom.cs │ ├── Monom3D.cs │ ├── Point.cs │ ├── PointWithLifetime.cs │ ├── Polinom3D.cs │ ├── Rectangle.cs │ ├── Seeds.cs │ └── Size.cs ├── Properties │ └── AssemblyInfo.cs ├── Screen │ ├── ConnectToRemoteServerScreen.cs │ ├── DebugScreen.cs │ ├── HelpScreen.cs │ ├── MainMenuScreen.cs │ ├── SandboxMapScreen.cs │ └── Screen.cs ├── UIComponents │ ├── Button.cs │ ├── TextBox.cs │ ├── UIComponentBase.cs │ └── UIComponentsCollection.cs ├── core.Portable.csproj ├── core.Portable.xproj └── project.json └── global.json /.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 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | GameXenko/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | 144 | # TODO: Un-comment the next line if you do not want to checkin 145 | # your web deploy settings because they may include unencrypted 146 | # passwords 147 | #*.pubxml 148 | *.publishproj 149 | 150 | # NuGet Packages 151 | *.nupkg 152 | # The packages folder can be ignored because of Package Restore 153 | **/packages/* 154 | # except build/, which is used as an MSBuild target. 155 | !**/packages/build/ 156 | # Uncomment if necessary however generally it will be regenerated when needed 157 | #!**/packages/repositories.config 158 | # NuGet v3's project.json files produces more ignoreable files 159 | *.nuget.props 160 | *.nuget.targets 161 | 162 | # Microsoft Azure Build Output 163 | csx/ 164 | *.build.csdef 165 | 166 | # Microsoft Azure Emulator 167 | ecf/ 168 | rcf/ 169 | 170 | # Microsoft Azure ApplicationInsights config file 171 | ApplicationInsights.config 172 | 173 | # Windows Store app package directory 174 | AppPackages/ 175 | BundleArtifacts/ 176 | 177 | # Visual Studio cache files 178 | # files ending in .cache can be ignored 179 | *.[Cc]ache 180 | # but keep track of directories ending in .cache 181 | !*.[Cc]ache/ 182 | 183 | # Others 184 | ClientBin/ 185 | [Ss]tyle[Cc]op.* 186 | ~$* 187 | *~ 188 | *.dbmdl 189 | *.dbproj.schemaview 190 | *.pfx 191 | *.publishsettings 192 | node_modules/ 193 | orleans.codegen.cs 194 | 195 | # RIA/Silverlight projects 196 | Generated_Code/ 197 | 198 | # Backup & report files from converting an old project file 199 | # to a newer Visual Studio version. Backup files are not needed, 200 | # because we have git ;-) 201 | _UpgradeReport_Files/ 202 | Backup*/ 203 | UpgradeLog*.XML 204 | UpgradeLog*.htm 205 | 206 | # SQL Server files 207 | *.mdf 208 | *.ldf 209 | 210 | # Business Intelligence projects 211 | *.rdl.data 212 | *.bim.layout 213 | *.bim_*.settings 214 | 215 | # Microsoft Fakes 216 | FakesAssemblies/ 217 | 218 | # GhostDoc plugin setting file 219 | *.GhostDoc.xml 220 | 221 | # Node.js Tools for Visual Studio 222 | .ntvs_analysis.dat 223 | 224 | # Visual Studio 6 build log 225 | *.plg 226 | 227 | # Visual Studio 6 workspace options file 228 | *.opt 229 | 230 | # Visual Studio LightSwitch build output 231 | **/*.HTMLClient/GeneratedArtifacts 232 | **/*.DesktopClient/GeneratedArtifacts 233 | **/*.DesktopClient/ModelManifest.xml 234 | **/*.Server/GeneratedArtifacts 235 | **/*.Server/ModelManifest.xml 236 | _Pvt_Extensions 237 | 238 | # LightSwitch generated files 239 | GeneratedArtifacts/ 240 | ModelManifest.xml 241 | 242 | # Paket dependency manager 243 | .paket/paket.exe 244 | 245 | # FAKE - F# Make 246 | .fake/ 247 | /src/.build 248 | /libs/.build 249 | /libs/SignalR-Server/ 250 | /src/Game.Server/scripts 251 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | addons: 3 | apt: 4 | packages: 5 | - gettext 6 | - libcurl4-openssl-dev 7 | - libicu-dev 8 | - libssl-dev 9 | - libunwind8 10 | - zlib1g 11 | 12 | os: linux 13 | dist: trusty # Ubuntu 14.04 14 | sudo: required 15 | env: CONFIGURATION=Debug FRAMEWORK=netcoreapp1.0 16 | 17 | before_install: 18 | # Install OpenSSL 19 | - if test "$TRAVIS_OS_NAME" == "osx"; then 20 | brew install openssl; 21 | brew link --force openssl; 22 | export DOTNET_SDK_URL="https://go.microsoft.com/fwlink/?LinkID=809128"; 23 | else 24 | export DOTNET_SDK_URL="https://go.microsoft.com/fwlink/?LinkID=809129"; 25 | fi 26 | - export DOTNET_INSTALL_DIR="$PWD/.dotnetcli" 27 | # Install .NET CLI 28 | - mkdir $DOTNET_INSTALL_DIR 29 | - curl -L $DOTNET_SDK_URL -o dotnet_package 30 | - tar -xvzf dotnet_package -C $DOTNET_INSTALL_DIR 31 | # Add dotnet to PATH 32 | - export PATH="$DOTNET_INSTALL_DIR:$PATH" 33 | install: 34 | # Display dotnet version info 35 | - which dotnet; 36 | if [ $? -eq 0 ]; then 37 | echo "Using dotnet:"; 38 | dotnet --info 39 | else 40 | echo "dotnet.exe not found" 41 | exit 1; 42 | fi 43 | # Restore dependencies and build core 44 | - dotnet restore src/core.Portable; 45 | - dotnet build src/core.Portable; 46 | # Restore dependencies and build Console game 47 | - dotnet restore src/Game.Console 48 | - dotnet build src/Game.Console 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 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 2016 Branimir Ričko 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 | -------------------------------------------------------------------------------- /Models/Air.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/Air.fbx -------------------------------------------------------------------------------- /Models/Darkness.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/Darkness.fbx -------------------------------------------------------------------------------- /Models/HorisontalWall.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/HorisontalWall.fbx -------------------------------------------------------------------------------- /Models/Path.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/Path.fbx -------------------------------------------------------------------------------- /Models/Player.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/Player.fbx -------------------------------------------------------------------------------- /Models/VerticalWall.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/Models/VerticalWall.fbx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Land sky

2 | 3 |

Roguelike NetHacklike multiplayer game

4 | 5 | Land sky project is an attempt at building a multiplayer version of Roguelike NetHacklike game. 6 | 7 | [![Build Status](https://travis-ci.org/branc116/LandSky.svg?branch=master)](https://travis-ci.org/branc116/LandSky) 8 | 9 | #### Goal include: 10 | * ***It should be multiplayer*** 11 | * ***It should be sandbox*** 12 | * ***It should be open source*** 13 | * ***It should be fun as original game was*** 14 | * ***It should be written in statically typed language***. 15 | Reason for this is that is easier for new developers to get into, I choose C#. 16 | 17 | #### Get started: 18 | * ``` >git clone https://github.com/branc116/LandSky ``` 19 | * ***Windows***: 20 | * Just install [Visual studio](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx) 21 | * open src/LandSky.sln 22 | * Build and/or start hacking 23 | * Start it inside Visual studio or run ``` src/core/bin/Debug/LandSky.exe ``` 24 | * ***Linux and OS X (Maybe, most likely will not work, but I'll try to make it work)*** 25 | * Hack with your favorite C# IDE 26 | * Install [Mono](http://www.mono-project.com/download/) 27 | * ``` >xbuild src/LandSky.sln ``` 28 | * ``` >mono src/core/bin/Debug/LandSky.exe ``` 29 | 30 | #### Design decisions 31 | Here are some of the design decisions: 32 | * ***Add as many comments as possible***. Just so that other people can jump in code and see what you've done. 33 | * ***Don't write you name on top of every file you make***. This is team effort, not a competition. 34 | * ***Naming convention***: Namespaces - PascalCase, classes - PascalCase, public properies - PascalCase, private properies - mPascalCase, other stuff is not really important 35 | * ***JSON***. Whenever you have to serialize object to save it, send it, ... use JSON 36 | 37 | #### Current state 38 | This project is in a very early stage and needs a lot of work. Everything that works should be more optimised. 39 | 40 | What works: 41 | * Room generation 42 | * Path generating 43 | * Controls 44 | * Rendering 45 | * Maybe someting else... 46 | 47 | #### TODO list 48 | This is the list of stuff that need to be made. I'm always open to suggestions if you have an idea. 49 | - [ ] Implement real time database for multyplayer stuff 50 | - [ ] Implement sql or nosql database for saving player status and game states 51 | - [ ] Implement more screens 52 | - [ ] Make the drawing process faster 53 | - [ ] Make gameplay features 54 | - [ ] A lot more 55 | 56 | #### Demo 57 | ![Alt text](imgs/Demo130816_3.jpg) 58 | 59 | #### Main author 60 | * Branimir Ričko 61 | * Mail: rickobranimir@gmail.com 62 | 63 | #### Licence 64 | This project is licensed under [Apache License Version 2.0](LICENSE.md) 65 | -------------------------------------------------------------------------------- /imgs/Demo130816_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/Demo130816_1.jpg -------------------------------------------------------------------------------- /imgs/Demo130816_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/Demo130816_2.jpg -------------------------------------------------------------------------------- /imgs/Demo130816_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/Demo130816_3.jpg -------------------------------------------------------------------------------- /imgs/Demo130816_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/Demo130816_4.jpg -------------------------------------------------------------------------------- /imgs/Demo130816_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/Demo130816_5.jpg -------------------------------------------------------------------------------- /imgs/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/imgs/demo.gif -------------------------------------------------------------------------------- /libs/LibBinary/Microsoft.AspNetCore.SignalR.Messaging.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/libs/LibBinary/Microsoft.AspNetCore.SignalR.Messaging.dll -------------------------------------------------------------------------------- /libs/LibBinary/Microsoft.AspNetCore.SignalR.Messaging.dll.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.AspNetCore.SignalR.Messaging.dll 5 | 1.0.0 6 | Branimir 7 | Branimir 8 | http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE 9 | http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE 10 | http://ICON_URL_HERE_OR_DELETE_THIS_LINE 11 | false 12 | Package description 13 | Summary of changes made in this release of the package. 14 | Copyright 2016 15 | Tag1 Tag2 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /libs/LibBinary/Microsoft.AspNetCore.SignalR.Server.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/branc116/LandSky/f7736e283f5740b8d45dffaf22f951e375cea038/libs/LibBinary/Microsoft.AspNetCore.SignalR.Server.dll -------------------------------------------------------------------------------- /libs/LibBinary/Microsoft.AspNetCore.SignalR.Server.dll.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.AspNetCore.SignalR.Server.dll 5 | 1.0.0 6 | Branimir 7 | Branimir 8 | http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE 9 | http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE 10 | http://ICON_URL_HERE_OR_DELETE_THIS_LINE 11 | false 12 | Package description 13 | Summary of changes made in this release of the package. 14 | Copyright 2016 15 | Tag1 Tag2 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Game.Console/Game.Console.xproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 520fc5c5-4ea6-4ff7-b008-ea72e256a539 10 | LandSky.Game.Cns 11 | .\obj 12 | .\bin\ 13 | v4.6.1 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Game.Console/Program.cs: -------------------------------------------------------------------------------- 1 | using LandSky.Components; 2 | using LandSky.DotNetExt; 3 | using LandSky.Screen; 4 | using System; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace LandSky.Game.Cns 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | Console.WriteLine("Enter Seed"); 15 | var seed = Console.ReadLine(); 16 | var Map = new SandboxMap(0, 0); 17 | var Engine = new Engine("MyEngine"); 18 | var Me = new Player("Branimir"); 19 | var InfPlain = new InfinitePlane(seed, "MyPlayn"); 20 | 21 | Engine.Connect("localhost:52062"); 22 | Engine.PushNewScreenOnTop(Map); 23 | Engine.PushNewComponentOnActiveScreen(Me); 24 | Engine.PushNewComponentOnActiveScreen(InfPlain); 25 | 26 | Task.Factory.StartNew(() => 27 | { 28 | while (true) 29 | { 30 | var a = System.Console.ReadKey(true); 31 | Engine.InputNextCommand(new MyConsoleKeyInfo(a.KeyChar), "Branimir"); 32 | } 33 | }); 34 | 35 | try 36 | { 37 | Console.CursorVisible = false; 38 | } 39 | catch { } 40 | Console.Clear(); 41 | Task.Factory.StartNew(() => 42 | { 43 | while (true) 44 | { 45 | Engine.SetActiveComponent(Me, Console.WindowWidth - 10, Console.WindowHeight - 10); 46 | 47 | var threadSafely = Engine.RenderAroundComponent(); 48 | System.Console.Clear(); 49 | System.Console.Write(threadSafely); 50 | Thread.Sleep(100); 51 | } 52 | }); 53 | Thread.Sleep(int.MaxValue); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/Game.Console/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("Game.Console")] 10 | [assembly: AssemblyTrademark("")] 11 | 12 | // Setting ComVisible to false makes the types in this assembly not visible 13 | // to COM components. If you need to access a type in this assembly from 14 | // COM, set the ComVisible attribute to true on that type. 15 | [assembly: ComVisible(false)] 16 | 17 | // The following GUID is for the ID of the typelib if this project is exposed to COM 18 | [assembly: Guid("520fc5c5-4ea6-4ff7-b008-ea72e256a539")] -------------------------------------------------------------------------------- /src/Game.Console/project.fragment.lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "exports": { 4 | "core.Portable/1.0.0": { 5 | "type": "project", 6 | "framework": ".NETStandard,Version=v1.3", 7 | "compile": { 8 | "bin/Debug/LandSky.dll": {} 9 | }, 10 | "runtime": { 11 | "bin/Debug/LandSky.dll": {} 12 | }, 13 | "contentFiles": { 14 | "bin/Debug/LandSky.pdb": { 15 | "buildAction": "None", 16 | "codeLanguage": "any", 17 | "copyToOutput": true 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Game.Console/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "LandSky", 3 | "description": "Roguelike", 4 | "version": "1.0.0-*", 5 | "buildOptions": { 6 | "emitEntryPoint": true 7 | }, 8 | "dependencies": { 9 | "Microsoft.NETCore.App": { 10 | "type": "platform", 11 | "version": "1.0.0", 12 | "include": "all" 13 | } 14 | }, 15 | "frameworks": { 16 | "netcoreapp1.1": { 17 | "imports": "netcore45", 18 | "dependencies": { 19 | "core.Portable": { 20 | "target": "project" 21 | }, 22 | "Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027" 23 | } 24 | } 25 | }, 26 | "configurations": { 27 | "DebugConsoleAndServer": {} 28 | } 29 | } -------------------------------------------------------------------------------- /src/Game.Server/Hubs/ServerHub.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.SignalR; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | using System.Threading.Tasks; 7 | using LandSky; 8 | using LandSky.MyEnums; 9 | using Microsoft.AspNet.SignalR.Hubs; 10 | 11 | namespace Game.Server.Hubs 12 | { 13 | [HubName("ServerHub")] 14 | public class ServerHub : Hub, IServer 15 | { 16 | private static Engine _engine; 17 | 18 | public void Login(string MailOrUsername, string Password) 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | 23 | public void Logout() 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | 28 | public void NewCommand(Comands Command, string Token) 29 | { 30 | throw new NotImplementedException(); 31 | } 32 | 33 | public override Task OnConnected() 34 | { 35 | return base.OnConnected(); 36 | } 37 | 38 | public void Register(string Mail, string Password, string Username) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/Game.Server/Identification/IdentityConfig.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | using Microsoft.AspNet.Identity.EntityFramework; 3 | using Microsoft.AspNet.Identity.Owin; 4 | using Microsoft.Owin; 5 | using Microsoft.Owin.Security; 6 | using System; 7 | using System.Security.Claims; 8 | using System.Threading.Tasks; 9 | 10 | namespace Game.Server 11 | { 12 | public class EmailService : IIdentityMessageService 13 | { 14 | public Task SendAsync(IdentityMessage message) 15 | { 16 | // Plug in your email service here to send an email. 17 | return Task.FromResult(0); 18 | } 19 | } 20 | 21 | public class SmsService : IIdentityMessageService 22 | { 23 | public Task SendAsync(IdentityMessage message) 24 | { 25 | // Plug in your SMS service here to send a text message. 26 | return Task.FromResult(0); 27 | } 28 | } 29 | 30 | // Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application. 31 | public class ApplicationUserManager : UserManager 32 | { 33 | public ApplicationUserManager(IUserStore store) 34 | : base(store) 35 | { 36 | } 37 | 38 | public static ApplicationUserManager Create(IdentityFactoryOptions options, IOwinContext context) 39 | { 40 | var manager = new ApplicationUserManager(new UserStore(context.Get())); 41 | // Configure validation logic for usernames 42 | manager.UserValidator = new UserValidator(manager) 43 | { 44 | AllowOnlyAlphanumericUserNames = false, 45 | RequireUniqueEmail = true 46 | }; 47 | 48 | // Configure validation logic for passwords 49 | manager.PasswordValidator = new PasswordValidator 50 | { 51 | RequiredLength = 6, 52 | RequireNonLetterOrDigit = true, 53 | RequireDigit = true, 54 | RequireLowercase = true, 55 | RequireUppercase = true, 56 | }; 57 | 58 | // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user 59 | // You can write your own provider and plug it in here. 60 | manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider 61 | { 62 | MessageFormat = "Your security code is {0}" 63 | }); 64 | manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider 65 | { 66 | Subject = "Security Code", 67 | BodyFormat = "Your security code is {0}" 68 | }); 69 | 70 | // Configure user lockout defaults 71 | manager.UserLockoutEnabledByDefault = true; 72 | manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); 73 | manager.MaxFailedAccessAttemptsBeforeLockout = 5; 74 | 75 | manager.EmailService = new EmailService(); 76 | manager.SmsService = new SmsService(); 77 | var dataProtectionProvider = options.DataProtectionProvider; 78 | if (dataProtectionProvider != null) 79 | { 80 | manager.UserTokenProvider = new DataProtectorTokenProvider(dataProtectionProvider.Create("ASP.NET Identity")); 81 | } 82 | return manager; 83 | } 84 | } 85 | 86 | public class ApplicationSignInManager : SignInManager 87 | { 88 | public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager) : 89 | base(userManager, authenticationManager) 90 | { } 91 | 92 | public override Task CreateUserIdentityAsync(ApplicationUser user) 93 | { 94 | return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager); 95 | } 96 | 97 | public static ApplicationSignInManager Create(IdentityFactoryOptions options, IOwinContext context) 98 | { 99 | return new ApplicationSignInManager(context.GetUserManager(), context.Authentication); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /src/Game.Server/Identification/IdentityModels.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | using Microsoft.AspNet.Identity.EntityFramework; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Security.Claims; 6 | using System.Threading.Tasks; 7 | using System.Web; 8 | using Owin; 9 | 10 | 11 | namespace Game.Server 12 | { 13 | public class ApplicationUser : IdentityUser 14 | { 15 | 16 | 17 | public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager) 18 | { 19 | // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 20 | var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie); 21 | 22 | // Add custom user claims here 23 | return userIdentity; 24 | } 25 | 26 | public Task GenerateUserIdentityAsync(ApplicationUserManager manager) 27 | { 28 | return Task.FromResult(GenerateUserIdentity(manager)); 29 | } 30 | } 31 | 32 | public class ApplicationDbContext : IdentityDbContext 33 | { 34 | public ApplicationDbContext() 35 | : base("DefaultConnection", throwIfV1Schema: false) 36 | { 37 | } 38 | 39 | public static ApplicationDbContext Create() 40 | { 41 | return new ApplicationDbContext(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Game.Server/Identification/Startup.Auth.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | using Microsoft.AspNet.Identity.Owin; 3 | using Microsoft.Owin; 4 | using Microsoft.Owin.Security.Cookies; 5 | using Owin; 6 | using System; 7 | 8 | namespace Game.Server 9 | { 10 | public partial class Startup 11 | { 12 | // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883 13 | public void ConfigureAuth(IAppBuilder app) 14 | { 15 | // Configure the db context, user manager and signin manager to use a single instance per request 16 | app.CreatePerOwinContext(ApplicationDbContext.Create); 17 | app.CreatePerOwinContext(ApplicationUserManager.Create); 18 | app.CreatePerOwinContext(ApplicationSignInManager.Create); 19 | 20 | // Enable the application to use a cookie to store information for the signed in user 21 | // and to use a cookie to temporarily store information about a user logging in with a third party login provider 22 | // Configure the sign in cookie 23 | app.UseCookieAuthentication(new CookieAuthenticationOptions 24 | { 25 | AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 26 | LoginPath = new PathString("/Account/Login"), 27 | Provider = new CookieAuthenticationProvider 28 | { 29 | OnValidateIdentity = SecurityStampValidator.OnValidateIdentity( 30 | validateInterval: TimeSpan.FromMinutes(30), 31 | regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) 32 | } 33 | }); 34 | // Use a cookie to temporarily store information about a user logging in with a third party login provider 35 | app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 36 | 37 | // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. 38 | app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 39 | 40 | // Enables the application to remember the second login verification factor such as phone or email. 41 | // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. 42 | // This is similar to the RememberMe option when you log in. 43 | app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); 44 | 45 | // Uncomment the following lines to enable logging in with third party login providers 46 | //app.UseMicrosoftAccountAuthentication( 47 | // clientId: "", 48 | // clientSecret: ""); 49 | 50 | //app.UseTwitterAuthentication( 51 | // consumerKey: "", 52 | // consumerSecret: ""); 53 | 54 | //app.UseFacebookAuthentication( 55 | // appId: "", 56 | // appSecret: ""); 57 | 58 | //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() 59 | //{ 60 | // ClientId = "", 61 | // ClientSecret = "" 62 | //}); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /src/Game.Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Owin; 2 | using Owin; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Web; 7 | 8 | [assembly: OwinStartup(typeof(Game.Server.Startup))] 9 | 10 | namespace Game.Server 11 | { 12 | 13 | public partial class Startup 14 | { 15 | public void Configuration(IAppBuilder app) 16 | { 17 | 18 | app.MapSignalR(); 19 | ConfigureAuth(app); 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/Game.Server/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Game.Server")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Game.Server")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("38666445-b638-4dc6-a2e5-fa1d84fd92a9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/Game.Server/Service References/Application Insights/ConnectedService.json: -------------------------------------------------------------------------------- 1 | { 2 | "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider", 3 | "Version": "7.7.10922.3", 4 | "GettingStartedDocument": { 5 | "Uri": "https://go.microsoft.com/fwlink/?LinkID=613413" 6 | } 7 | } -------------------------------------------------------------------------------- /src/Game.Server/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /src/Game.Server/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /src/Game.Server/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/Game.Server/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/LandSky.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Server", "Server\Server.xproj", "{DCDF1ECD-9066-4D42-AAFE-E5BACE8F1590}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{92B6A376-61FA-4BC4-99D2-B68D988F7544}" 9 | ProjectSection(SolutionItems) = preProject 10 | global.json = global.json 11 | EndProjectSection 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "core.Portable", "core.Portable\core.Portable.csproj", "{661DC64D-6282-422C-A6AF-60E3C8A63BCC}" 14 | EndProject 15 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Game.Console", "Game.Console\Game.Console.xproj", "{520FC5C5-4EA6-4FF7-B008-EA72E256A539}" 16 | ProjectSection(ProjectDependencies) = postProject 17 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC} = {661DC64D-6282-422C-A6AF-60E3C8A63BCC} 18 | EndProjectSection 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game.Server", "Game.Server\Game.Server.csproj", "{38666445-B638-4DC6-A2E5-FA1D84FD92A9}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | DebugConsoleAndServer|Any CPU = DebugConsoleAndServer|Any CPU 26 | Release|Any CPU = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {DCDF1ECD-9066-4D42-AAFE-E5BACE8F1590}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {DCDF1ECD-9066-4D42-AAFE-E5BACE8F1590}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {DCDF1ECD-9066-4D42-AAFE-E5BACE8F1590}.DebugConsoleAndServer|Any CPU.ActiveCfg = DebugConsoleAndServer|Any CPU 32 | {DCDF1ECD-9066-4D42-AAFE-E5BACE8F1590}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.DebugConsoleAndServer|Any CPU.ActiveCfg = Debug|Any CPU 36 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.DebugConsoleAndServer|Any CPU.Build.0 = Debug|Any CPU 37 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {661DC64D-6282-422C-A6AF-60E3C8A63BCC}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.DebugConsoleAndServer|Any CPU.ActiveCfg = DebugConsoleAndServer|Any CPU 42 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.DebugConsoleAndServer|Any CPU.Build.0 = DebugConsoleAndServer|Any CPU 43 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {520FC5C5-4EA6-4FF7-B008-EA72E256A539}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.DebugConsoleAndServer|Any CPU.ActiveCfg = DebugConsoleAndServer|Any CPU 48 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.DebugConsoleAndServer|Any CPU.Build.0 = DebugConsoleAndServer|Any CPU 49 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {38666445-B638-4DC6-A2E5-FA1D84FD92A9}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /src/Server/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using LandSky; 2 | using LandSky.Commands; 3 | using LandSky.Components; 4 | using LandSky.DotNetExt; 5 | using LandSky.Screen; 6 | using Microsoft.AspNetCore.SignalR; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | namespace Server.Controllers 13 | { 14 | public class Players// : IEnumerable> 15 | { 16 | static private SortedList _Users = new SortedList(); 17 | static private Engine _Engine = new Engine("myEngine"); 18 | static private Random _Rand = new Random(); 19 | static private SandboxMap _Map = new SandboxMap(0, 0); 20 | 21 | public Players() 22 | { 23 | Task t = GeneratePath(3); 24 | _Engine.PushNewScreenOnTop(_Map); 25 | } 26 | 27 | public async Task GeneratePath(int N) 28 | { 29 | if (_Map.NumOfRooms < 3) 30 | await _Map.GenerateRandomRooms(200); 31 | _Map.GeneratePath(new GeneratePathCommand() { NumberOfPaths = N }); 32 | } 33 | 34 | public Player this[string userId] 35 | { 36 | get 37 | { 38 | return _Users[userId]; 39 | } 40 | 41 | set 42 | { 43 | _Users[userId] = value; 44 | } 45 | } 46 | 47 | public int Count 48 | { 49 | get 50 | { 51 | return _Users.Count; 52 | } 53 | } 54 | 55 | public bool IsReadOnly 56 | { 57 | get 58 | { 59 | return false; 60 | } 61 | } 62 | 63 | public bool Add(string UserId, Player item) 64 | { 65 | try 66 | { 67 | _Engine.PushNewComponentOnActiveScreen(new Player(item.Name) { LocalX = _Rand.Next(-10, 10), LocalY = _Rand.Next(-10, 10) }); 68 | _Users.Add(UserId, item); 69 | return true; 70 | } 71 | catch 72 | { 73 | return false; 74 | } 75 | } 76 | 77 | public void Clear() 78 | { 79 | _Users.Clear(); 80 | } 81 | 82 | public bool Contains(Player item) 83 | { 84 | return _Users.Any(i => i.Value == item); 85 | } 86 | 87 | public IEnumerator> GetEnumerator() 88 | { 89 | foreach (var _Player in _Users) 90 | { 91 | yield return _Player; 92 | } 93 | } 94 | 95 | public bool Remove(Player item) 96 | { 97 | _Engine.RemoveComponentFromActiveScreen(item); 98 | return _Users.Remove(item.Name); 99 | } 100 | 101 | public bool Remove(string UserID) 102 | { 103 | try 104 | { 105 | _Engine.RemoveComponentFromActiveScreen(_Users[UserID]); 106 | _Users.Remove(UserID); 107 | return true; 108 | } 109 | catch 110 | { 111 | return false; 112 | } 113 | } 114 | 115 | public string GetFrameForPlayer(string PlayerID) 116 | { 117 | return _Engine.RenderAroundComponent(_Users[PlayerID], 70, 30); 118 | } 119 | 120 | //IEnumerator> IEnumerable>.GetEnumerator() 121 | //{ 122 | // throw new NotImplementedException(); 123 | //} 124 | 125 | //IEnumerator IEnumerable.GetEnumerator() 126 | //{ 127 | // return _Users.GetEnumerator(); 128 | //} 129 | 130 | public void ParseControl(string caller, bool ctrl, bool alt, string character) 131 | { 132 | Player p = _Users[caller]; 133 | ConsoleKey ck; 134 | 135 | Enum.TryParse(character.ToUpper(), out ck); 136 | _Engine.InputNextCommand(new MyConsoleKeyInfo(character[0], alt, ctrl), p.Name); 137 | } 138 | } 139 | 140 | public class PlayerHub : Hub 141 | { 142 | private static Players _players = new Players(); 143 | 144 | public override Task OnConnected() 145 | { 146 | base.Clients.Caller.Respones(); 147 | return base.OnConnected(); 148 | } 149 | 150 | public override Task OnDisconnected(bool stopCalled) 151 | { 152 | var a = base.Context.ConnectionId; 153 | Task tt; 154 | if (_players.Remove(a)) 155 | tt = updateForAll(); 156 | return base.OnDisconnected(stopCalled); 157 | } 158 | 159 | public override Task OnReconnected() 160 | { 161 | return base.OnReconnected(); 162 | } 163 | 164 | public void InsertNew(string Name) 165 | { 166 | var a = base.Context.ConnectionId; 167 | var Ok = _players.Add(a, new Player(Name)); 168 | if (Ok == true) 169 | { 170 | Task t = updateForAll(); 171 | } 172 | base.Clients.Caller.NameOk(Ok, Name); 173 | } 174 | 175 | private static object LockUpdateAll = new object(); 176 | 177 | private async Task updateForAll() 178 | { 179 | await Task.Factory.StartNew(() => 180 | { 181 | foreach (var player in _players) 182 | { 183 | Task.Factory.StartNew(() => 184 | { 185 | base.Clients.Client(player.Key).UpdateFrame(_players.GetFrameForPlayer(player.Key)); 186 | }); 187 | } 188 | }); 189 | } 190 | 191 | public void Input(bool ctrl, bool alt, string Character) 192 | { 193 | var a = base.Context.ConnectionId; 194 | _players.ParseControl(a, ctrl, alt, Character); 195 | Task t = updateForAll(a); 196 | } 197 | 198 | private async Task updateForAll(string a) 199 | { 200 | await Task.Factory.StartNew(() => { base.Clients.All.UpdateFrame(_players.GetFrameForPlayer(a)); }); 201 | } 202 | } 203 | } -------------------------------------------------------------------------------- /src/Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using System.IO; 4 | 5 | namespace Server 6 | { 7 | public class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | var host = new WebHostBuilder() 12 | .UseKestrel() 13 | .UseUrls("http://0.0.0.0:5000") 14 | .UseContentRoot(Directory.GetCurrentDirectory()) 15 | .UseIISIntegration() 16 | .UseStartup() 17 | .Build(); 18 | 19 | host.Run(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Server/Project_Readme.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Welcome to ASP.NET Core 6 | 127 | 128 | 129 | 130 | 138 | 139 |
140 |
141 |

This application consists of:

142 |
    143 |
  • Sample pages using ASP.NET Core MVC
  • 144 |
  • Bower for managing client-side libraries
  • 145 |
  • Theming using Bootstrap
  • 146 |
147 |
148 | 160 | 172 |
173 |

Run & Deploy

174 | 179 |
180 | 181 | 184 |
185 | 186 | -------------------------------------------------------------------------------- /src/Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:6924/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "StartPage.html", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "Server": { 20 | "commandName": "Project", 21 | "commandLineArgs": "--server.urls http://0.0.0.0:5000", 22 | "launchBrowser": true, 23 | "launchUrl": "http://landsky.ddnsking.net/", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Server/Server.xproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | dcdf1ecd-9066-4d42-aafe-e5bace8f1590 10 | Server 11 | .\obj 12 | .\bin\ 13 | v4.6.1 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Server/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Logging; 6 | using System.Collections.Generic; 7 | 8 | namespace Server 9 | { 10 | public class Startup 11 | { 12 | public Startup(IHostingEnvironment env) 13 | { 14 | var builder = new ConfigurationBuilder() 15 | .SetBasePath(env.ContentRootPath) 16 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 17 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 18 | .AddEnvironmentVariables(); 19 | Configuration = builder.Build(); 20 | } 21 | 22 | public IConfigurationRoot Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | // Add framework services. 28 | services.AddMvc(); 29 | services.AddSignalR(); 30 | services.AddSwaggerGen(); 31 | } 32 | 33 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 34 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 35 | { 36 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 37 | loggerFactory.AddDebug(); 38 | 39 | app.UseMvc(); 40 | app.UseSignalR(); 41 | app.UseStaticFiles(); 42 | app.UseDefaultFiles(new DefaultFilesOptions() { DefaultFileNames = new List() { "index.html" } }); 43 | app.UseWebSockets(); 44 | app.UseSwagger(); 45 | app.UseSwaggerUi(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Server/project.fragment.lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "exports": { 4 | "core.Portable/1.0.0": { 5 | "type": "project", 6 | "framework": ".NETStandard,Version=v1.3", 7 | "compile": { 8 | "bin/Debug/LandSky.dll": {} 9 | }, 10 | "runtime": { 11 | "bin/Debug/LandSky.dll": {} 12 | }, 13 | "contentFiles": { 14 | "bin/Debug/LandSky.pdb": { 15 | "buildAction": "None", 16 | "codeLanguage": "any", 17 | "copyToOutput": true 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Server/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.NETCore.App": { 4 | "version": "1.0.0", 5 | "type": "platform" 6 | }, 7 | "Microsoft.AspNetCore.Mvc": "1.0.0", 8 | "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 9 | "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 10 | "Microsoft.AspNetCore.StaticFiles": "1.0.0", 11 | "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 12 | "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", 13 | "Microsoft.Extensions.Configuration.Json": "1.0.0", 14 | "Microsoft.Extensions.Logging.Console": "1.0.0", 15 | "Microsoft.Extensions.Logging.Debug": "1.0.0", 16 | "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 17 | "Swashbuckle": "6.0.0-beta902", 18 | "Microsoft.AspNetCore.WebSockets.Server": "0.1.0", 19 | "Microsoft.AspNetCore.WebUtilities": "1.0.0", 20 | "Microsoft.AspNetCore.WebSockets.Protocol": "0.1.0", 21 | "Microsoft.AspNetCore.SignalR.Server": "0.2.0-alpha1-22118", 22 | "Microsoft.AspNetCore.Antiforgery" : "1.0.0" 23 | }, 24 | 25 | "tools": { 26 | "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 27 | }, 28 | 29 | "frameworks": { 30 | "netcoreapp1.0": { 31 | "dependencies": { 32 | "core.Portable": { 33 | "target": "project" 34 | } 35 | }, 36 | "imports": [ 37 | "dotnet5.6", 38 | "portable-net45+win8" 39 | ] 40 | } 41 | }, 42 | 43 | "buildOptions": { 44 | "emitEntryPoint": true, 45 | "preserveCompilationContext": true 46 | }, 47 | 48 | "runtimeOptions": { 49 | "configProperties": { 50 | "System.GC.Server": true 51 | } 52 | }, 53 | 54 | "publishOptions": { 55 | "include": [ 56 | "wwwroot", 57 | "Views", 58 | "Areas/**/Views", 59 | "appsettings.json", 60 | "web.config" 61 | ] 62 | }, 63 | 64 | "scripts": { 65 | "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 66 | }, 67 | "configurations": { 68 | "DebugConsoleAndServer": {} 69 | } 70 | } -------------------------------------------------------------------------------- /src/Server/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Server/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Land Sky 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 |
17 | Enter name: 18 |
19 |
20 | 
21 | 


--------------------------------------------------------------------------------
/src/Server/wwwroot/palyerHub.js:
--------------------------------------------------------------------------------
 1 | //hitMe / hitUs : sends the server the current timestamp and the number of calls to make back to the client.  hitMe: just the callign client, hitUs: all clients on the hub.
 2 | //stepOne / stepAll : increments a counter
 3 | //doneOne / doneAll : prints # of messages and total duration.
 4 | 
 5 | $(function () {
 6 |     var playerHub = $.connection.playerHub;
 7 | 
 8 |     playerHub.client.updateFrame = function (newFrame) {
 9 |         $('#myScreen').text(newFrame);
10 |     };
11 | 
12 |     playerHub.client.nameOk = function (ok) {
13 |         if (true === ok) {
14 |             $("#submitForm").hide();
15 |             $(document).keypress(function (event) {
16 |                 playerHub.server.input(event.ctrlKey, event.altKey, event.key);
17 |             });
18 |         } else {
19 |             $('#inputName').css("background-color", "red");
20 |         }
21 |     };
22 | 
23 |     $.connection.hub.start(options, function () { console.log("Connected"); });
24 | 
25 |     $("#submitForm").submit(function (event) {
26 |         playerHub.server.insertNew($('#inputName').val());
27 |         return false;
28 |     });
29 | });


--------------------------------------------------------------------------------
/src/WebApp/package.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "name": "landsky",
 3 |   "version": "0.0.1",
 4 |   "description": "Rouguelike",
 5 |   "main": "index.js",
 6 |   "scripts": {
 7 |     "test": "echo \"Error: no test specified\" && exit 1"
 8 |   },
 9 |   "author": "rickobranimir@gmail.com",
10 |   "license": "ISC"
11 | }
12 | 


--------------------------------------------------------------------------------
/src/WebApp/tsconfig.json:
--------------------------------------------------------------------------------
 1 | {
 2 |     "compilerOptions": {
 3 |         "module": "commonjs",
 4 |         "target": "es5",
 5 |         "noImplicitAny": false,
 6 |         "sourceMap": false
 7 |     },
 8 |     "exclude": [
 9 |         "node_modules"
10 |     ]
11 | }


--------------------------------------------------------------------------------
/src/core.Portable/AsciiTexture.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using System.Collections.Generic;
 3 | 
 4 | namespace LandSky
 5 | {
 6 |     internal static class AsciiTexture
 7 |     {
 8 |         public static Dictionary AsciiTextures = new Dictionary()
 9 |         {
10 |             { Material.Air, '.'},
11 |             { Material.Fire, '~'},
12 |             { Material.Loot, '$'},
13 |             { Material.Npc, 'N'},
14 |             { Material.Path, '#'},
15 |             { Material.Player, '@'},
16 |             { Material.Trap, '.'},
17 |             { Material.HorisontalWall, '-'},
18 |             { Material.VerticalWall, '|'},
19 |             { Material.Water, '}'},
20 |             { Material.Darknes, ' '}
21 |         };
22 |     }
23 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/BaseCommand.cs:
--------------------------------------------------------------------------------
1 | namespace LandSky.Commands
2 | {
3 |     /// 
4 |     /// Every custom command should extend BaseCommand
5 |     /// 
6 |     public class BaseCommand
7 |     {
8 |     }
9 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/GeneratePathCommand.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.Commands
 2 | {
 3 |     /// 
 4 |     /// Command for creating paths
 5 |     /// 
 6 |     public class GeneratePathCommand : BaseCommand
 7 |     {
 8 |         public int NumberOfPaths { get; set; }
 9 |     }
10 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/GenerateRoomsCommand.cs:
--------------------------------------------------------------------------------
 1 | using System.Threading;
 2 | 
 3 | namespace LandSky.Commands
 4 | {
 5 |     /// 
 6 |     /// Command for generating rooms
 7 |     /// 
 8 |     internal class GenerateRoomsCommand : BaseCommand
 9 |     {
10 |         public int NumberOfRooms;
11 |         public static CancellationToken CancelGenerting;
12 |         private static CancellationTokenSource mMSource;
13 | 
14 |         public GenerateRoomsCommand(int N)
15 |         {
16 |             NumberOfRooms = N;
17 |             mMSource?.Cancel();
18 |             mMSource = new CancellationTokenSource();
19 |             CancelGenerting = mMSource.Token;
20 |         }
21 | 
22 |         public static GenerateRoomsCommand GenerateAlotOfRooms()
23 |         {
24 |             return new GenerateRoomsCommand(1000);
25 |         }
26 | 
27 |         public static GenerateRoomsCommand GenerateOneRoom()
28 |         {
29 |             return new GenerateRoomsCommand(1);
30 |         }
31 | 
32 |         public static void CancleGeneratingRooms()
33 |         {
34 |             mMSource?.Cancel();
35 |         }
36 |     }
37 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/MoveCommand.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.MyEnums;
  2 | using System;
  3 | using System.Threading;
  4 | 
  5 | namespace LandSky.Commands
  6 | {
  7 |     internal class MoveCommand : BaseCommand
  8 |     {
  9 |         public MoveDirection Direction;
 10 |         public int Steps;
 11 |         public static CancellationToken CancleMove;
 12 |         public static CancellationTokenSource InvokeCancle;
 13 | 
 14 |         public MoveCommand(MoveDirection Direction, int steps)
 15 |         {
 16 |             this.Direction = Direction;
 17 |             this.Steps = steps;
 18 |             InitToken();
 19 |         }
 20 | 
 21 |         public static void InitToken()
 22 |         {
 23 |             InvokeCancle?.Cancel();
 24 |             InvokeCancle = new CancellationTokenSource();
 25 |             CancleMove = InvokeCancle.Token;
 26 |         }
 27 | 
 28 |         public static MoveCommand Phrase(Comands MoveCommand)
 29 |         {
 30 |             switch (MoveCommand)
 31 |             {
 32 |                 case Comands.Left:
 33 |                     return Left(1);
 34 | 
 35 |                 case Comands.TenStepsLeft:
 36 |                     return Left(10);
 37 | 
 38 |                 case Comands.Right:
 39 |                     return Right(1);
 40 | 
 41 |                 case Comands.TenStepsRight:
 42 |                     return Right(10);
 43 | 
 44 |                 case Comands.Up:
 45 |                     return Up(1);
 46 | 
 47 |                 case Comands.TenStepsUp:
 48 |                     return Left(10);
 49 | 
 50 |                 case Comands.Down:
 51 |                     return Down(1);
 52 | 
 53 |                 case Comands.TenStepsDown:
 54 |                     return Down(10);
 55 | 
 56 |                 default:
 57 |                     throw new Exception($"Command {MoveCommand} not valid");
 58 |             }
 59 |         }
 60 | 
 61 |         public static MoveCommand Left(int steps)
 62 |         {
 63 |             return new MoveCommand(MoveDirection.Left, steps);
 64 |         }
 65 | 
 66 |         public static MoveCommand UpLeft(int steps)
 67 |         {
 68 |             return new MoveCommand(MoveDirection.UpLeft, steps);
 69 |         }
 70 | 
 71 |         public static MoveCommand Up(int steps)
 72 |         {
 73 |             return new MoveCommand(MoveDirection.Up, steps);
 74 |         }
 75 | 
 76 |         public static MoveCommand UpRight(int steps)
 77 |         {
 78 |             return new MoveCommand(MoveDirection.UpRight, steps);
 79 |         }
 80 | 
 81 |         public static MoveCommand Right(int steps)
 82 |         {
 83 |             return new MoveCommand(MoveDirection.Right, steps);
 84 |         }
 85 | 
 86 |         public static MoveCommand DownRight(int steps)
 87 |         {
 88 |             return new MoveCommand(MoveDirection.DownRight, steps);
 89 |         }
 90 | 
 91 |         public static MoveCommand Down(int steps)
 92 |         {
 93 |             return new MoveCommand(MoveDirection.Down, steps);
 94 |         }
 95 | 
 96 |         public static MoveCommand DownLeft(int steps)
 97 |         {
 98 |             return new MoveCommand(MoveDirection.DownLeft, steps);
 99 |         }
100 |     }
101 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/ScreenToJsonCommand.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.Commands
 2 | {
 3 |     internal class ScreenToJsonCommand : BaseCommand
 4 |     {
 5 |         public string FileName;
 6 | 
 7 |         public ScreenToJsonCommand(string FileName)
 8 |         {
 9 |             this.FileName = FileName;
10 |         }
11 |     }
12 | }


--------------------------------------------------------------------------------
/src/core.Portable/Commands/ScrollCommand.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.Commands
 2 | {
 3 |     /// 
 4 |     /// Command for scrolling body part of the screen
 5 |     /// 
 6 |     internal class ScrollCommand : BaseCommand
 7 |     {
 8 |         public int N;
 9 | 
10 |         public ScrollCommand(int N)
11 |         {
12 |             this.N = N;
13 |         }
14 | 
15 |         public static ScrollCommand Left()
16 |         {
17 |             return new ScrollCommand(-1);
18 |         }
19 | 
20 |         public static ScrollCommand Right()
21 |         {
22 |             return new ScrollCommand(1);
23 |         }
24 | 
25 |         public static ScrollCommand LeftTen()
26 |         {
27 |             return new ScrollCommand(-10);
28 |         }
29 | 
30 |         public static ScrollCommand RightTen()
31 |         {
32 |             return new ScrollCommand(10);
33 |         }
34 |     }
35 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/Cell.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | 
 3 | namespace LandSky.Components
 4 | {
 5 |     public class Cell : IComparable
 6 |     {
 7 |         public DateTime LastUsed;
 8 | 
 9 |         public int Priority { get; set; } = 0;
10 | 
11 |         public char Value
12 |         {
13 |             get
14 |             {
15 |                 LastUsed = DateTime.Now;
16 |                 return _value;
17 |             }
18 |             set
19 |             {
20 |                 LastUsed = DateTime.Now;
21 |                 _value = value;
22 |             }
23 |         }
24 | 
25 |         private char _value;
26 | 
27 |         public Cell(char Value)
28 |         {
29 |             this.Value = Value;
30 |         }
31 | 
32 |         public int CompareTo(object obj)
33 |         {
34 |             if (obj is Cell)
35 |                 return (LastUsed).CompareTo((obj as Cell).LastUsed);
36 |             throw new ArgumentException("obj needs to be Cell", "obj");
37 |         }
38 | 
39 |         public override string ToString()
40 |         {
41 |             return _value.ToString();
42 |         }
43 | 
44 |         public static Cell operator +(Cell a, Cell b) => b.Priority > a.Priority ? b : a;
45 |     }
46 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/InfinitePlane.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.MyEnums;
  2 | using LandSky.MyMath;
  3 | using System.Collections.Generic;
  4 | using static LandSky.AsciiTexture;
  5 | 
  6 | namespace LandSky.Components
  7 | {
  8 |     public class InfinitePlane : Component
  9 |     {
 10 |         private Seeds _seed;
 11 |         public Dictionary _table = new Dictionary();
 12 |         public Point CurentLocation { get; set; } = new Point(0, 0);
 13 | 
 14 |         public InfinitePlane(string Seed, string Name) : base(Name)
 15 |         {
 16 |             _seed = new Seeds(Seed);
 17 |             IsInfinity = true;
 18 |         }
 19 | 
 20 |         public Cell GetPoint(Point Location)
 21 |         {
 22 |             if (_table.ContainsKey(Location))
 23 |                 return _table[Location];
 24 |             var resoult = new Cell(_seed.IsOver(Location.X, Location.Y) ? AsciiTextures[Material.Air] : AsciiTextures[Material.Darknes]);
 25 |             resoult.Priority = ZValue;
 26 |             _table.Add(Location, resoult);
 27 |             return resoult;
 28 |         }
 29 | 
 30 |         public override Cell[][] GetRegin(Rectangle Rec)
 31 |         {
 32 |             Cell[][] Area = new Cell[Rec.Height][];
 33 |             for (int i = 0; i < Rec.Height; i++)
 34 |             {
 35 |                 Area[i] = new Cell[Rec.Width];
 36 |                 for (int j = 0; j < Rec.Width; j++)
 37 |                 {
 38 |                     Area[i][j] = GetPoint(new Point(j + Rec.LeftBound, Rec.TopBound - i));
 39 |                 }
 40 |             }
 41 |             return Area;
 42 |         }
 43 |     }
 44 | 
 45 |     //class Slice : IList>
 46 |     //{
 47 |     //    private Point Offset = new Point(0,0);
 48 | 
 49 |     //    private Rectangle CurrentSlice { get; set; } = new Rectangle(new Point(0, 0), 100, 100);
 50 | 
 51 |     //    private List> _currentSlice;
 52 | 
 53 |     //    public Size SliceSize { get; set; } = new Size(100, 100);
 54 | 
 55 |     //    public Size ChunkSize { get; set; } = new Size(20, 20);
 56 | 
 57 |     //    public string Seed { get; set; } = "Hello World Seed";
 58 | 
 59 |     //    public EventHandler ResetMe;
 60 | 
 61 |     //    public List this[int index]
 62 |     //    {
 63 |     //        get
 64 |     //        {
 65 |     //            return _currentSlice[index];
 66 |     //        }
 67 | 
 68 |     //        set
 69 |     //        {
 70 |     //            throw new NotImplementedException();
 71 |     //        }
 72 |     //    }
 73 | 
 74 |     //    public bool this[int X,int Y]
 75 |     //    {
 76 |     //        get
 77 |     //        {
 78 |     //            if (_currentSlice?[X - CurrentSlice.LeftBound]?[CurrentSlice.TopBound - Y] == null)
 79 |     //                ResetMe?.Invoke(this, EventArgs.Empty);
 80 |     //            return _currentSlice?[X - CurrentSlice.LeftBound]?[CurrentSlice.TopBound - Y] ?? false;
 81 |     //        }
 82 |     //        set
 83 |     //        {
 84 |     //            if (_currentSlice?[X - CurrentSlice.LeftBound]?[CurrentSlice.TopBound - Y] == null)
 85 |     //                ResetMe?.Invoke(this, EventArgs.Empty);
 86 |     //            else
 87 |     //                _currentSlice[X - CurrentSlice.LeftBound][CurrentSlice.TopBound - Y] = value;
 88 |     //        }
 89 |     //    }
 90 | 
 91 |     //    public int Count
 92 |     //    {
 93 |     //        get
 94 |     //        {
 95 |     //            return _currentSlice.Count;
 96 |     //        }
 97 |     //    }
 98 | 
 99 |     //    public bool IsReadOnly
100 |     //    {
101 |     //        get
102 |     //        {
103 |     //            return false;
104 |     //        }
105 |     //    }
106 | 
107 |     //    public void Add(List item)
108 |     //    {
109 |     //        _currentSlice.Add(item);
110 |     //    }
111 | 
112 |     //    public void Clear()
113 |     //    {
114 |     //        _currentSlice.Clear();
115 |     //    }
116 | 
117 |     //    public bool Contains(List item)
118 |     //    {
119 |     //        return _currentSlice.Contains(item);
120 |     //    }
121 | 
122 |     //    public void CopyTo(List[] array, int arrayIndex)
123 |     //    {
124 |     //        _currentSlice.CopyTo(array, arrayIndex);
125 |     //    }
126 | 
127 |     //    public IEnumerator> GetEnumerator()
128 |     //    {
129 |     //        foreach(var item in _currentSlice)
130 |     //        {
131 |     //            yield return item;
132 |     //        }
133 |     //    }
134 | 
135 |     //    public int IndexOf(List item)
136 |     //    {
137 |     //        return _currentSlice.IndexOf(item);
138 |     //    }
139 | 
140 |     //    public void Insert(int index, List item)
141 |     //    {
142 |     //        _currentSlice.Insert(index, item);
143 |     //    }
144 | 
145 |     //    public bool Remove(List item)
146 |     //    {
147 |     //        return _currentSlice.Remove(item);
148 |     //    }
149 | 
150 |     //    public void RemoveAt(int index)
151 |     //    {
152 |     //        _currentSlice.RemoveAt(index);
153 |     //    }
154 | 
155 |     //    IEnumerator IEnumerable.GetEnumerator()
156 |     //    {
157 |     //        return _currentSlice.GetEnumerator();
158 |     //    }
159 |     //}
160 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/Path.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.MyMath;
 3 | using System;
 4 | using System.Collections.Generic;
 5 | using System.Linq;
 6 | using static System.Math;
 7 | 
 8 | namespace LandSky.Components
 9 | {
10 |     /// 
11 |     /// Passable object that connects different rooms
12 |     /// 
13 |     public class Path : Component
14 |     {
15 |         public LinearInterpolator Poly;
16 |         public List ConnectedComponent;
17 | 
18 |         public Path(string name) : base(name)
19 |         {
20 |             Rand = new Random(DateTime.Now.Millisecond + (1 + DateTime.Now.Second) * 1009 + (1 + DateTime.Now.Minute) * 62761 + (1 + DateTime.Now.Hour) * 3832999);
21 |             ConnectedComponent = new List();
22 |             Poly = new LinearInterpolator();
23 |             IsPassable = true;
24 |             IsInfinity = true;
25 |         }
26 | 
27 |         public void GeneratePathThrueLocations(List Points)
28 |         {
29 |             Poly.Interpolate(Points, KindOfMonom.Line);
30 |         }
31 | 
32 |         public void GeneratePathThrueRandomChildren(Component C)
33 |         {
34 |             if (C.Controls.Count < 3) throw new Exception("You can't generate path in component that has less then 3 children... sorry :(");
35 |             int N = Math.Min(3, Rand.Next(C.Controls.Count / 4, C.Controls.Count));
36 |             var Points = new List(N + 1)
37 |             {
38 |                 C.Controls.ElementAt(Rand.Next(0, C.Controls.Count/7 - 1)).Value.LocalLocation
39 |             };
40 |             N--;
41 |             while (--N > 0)
42 |             {
43 |                 Points.Add(C.Controls.Where(I => I.Value.GetType() != typeof(Path) && I.Value.GetType() != typeof(Player))
44 |                                      .Where(K => Points.All(J => J.X != K.Value.LocalX))
45 |                                      .OrderBy(I => Points
46 |                                      .Sum(M => M.AbsDerivative(I.Value.LocalLocation)))
47 |                                      .First().Value.LocalLocation);
48 |             }
49 | 
50 |             GeneratePathThrueLocations(Points);
51 |         }
52 | 
53 |         public bool CanFindTheSameX(IEnumerable Points, Point Point)
54 |         {
55 |             return Points.Any(P => Math.Abs(P.X - Point.X) == 0 || Math.Abs((P.Y - Point.Y) / (P.X - Point.X)) > 2);
56 |         }
57 | 
58 |         public override Cell[][] GetRegin(Rectangle Rec)
59 |         {
60 |             var Area = new Cell[Rec.Height][];
61 |             for (int i = 0; i < Rec.Height; i++)
62 |             {
63 |                 Area[i] = new Cell[Rec.Width];
64 |                 for (int j = 0; j < Rec.Width; j++)
65 |                 {
66 |                     Area[i][j] = new Cell(AsciiTexture.AsciiTextures[Material.Darknes]);
67 |                 }
68 |             }
69 |             for (int i = 0; i < Rec.Width; i++)
70 |             {
71 |                 int from = (Poly.IntValueForX(Rec.LeftBound + i) + Abs(Poly.IntDerivativeForX(Rec.LeftBound + i)) - Rec.TopBound);
72 |                 int to = (Poly.IntValueForX(Rec.LeftBound + i) - Abs(Poly.IntDerivativeForX(Rec.LeftBound + i)) - Rec.TopBound);
73 |                 from = Max(0, Min(Area.Length - 1, from));
74 |                 to = Max(0, Min(Area.Length - 1, to));
75 |                 for (int j = from; j < to; j++)
76 |                 {
77 |                     Area[j][i] = new Cell(AsciiTexture.AsciiTextures[Material.Air]) { Priority = ZValue };
78 |                 }
79 |             }
80 |             return Area;
81 |         }
82 | 
83 |         public static bool operator &(Path One, Point Two)
84 |         {
85 |             return One.Poly.DerivativeForX(Two.X) + One.Poly.ValueForX(Two.X) + 2 > Two.Y && One.Poly.ValueForX(Two.X) - One.Poly.DerivativeForX(Two.X) - 2 < Two.Y;
86 |         }
87 | 
88 |         public bool IsOnPath(Point point)
89 |         {
90 |             return this & point;
91 |         }
92 |     }
93 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/Player.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.MyMath;
 3 | 
 4 | namespace LandSky.Components
 5 | {
 6 |     /// 
 7 |     /// Player with the location and texture
 8 |     /// 
 9 |     public class Player : Component
10 |     {
11 |         public PermissionsLevel PermissionsLevel { get; set; }
12 | 
13 |         public Player(string Name) : base($"{Name}")
14 |         {
15 |             this.ZValue = 5;
16 |             this.Bounds = Rectangle.DefineRectangleByWidthAndHeight(0, 0, 0, 0);
17 | 
18 |             MadeOf = Material.Player;
19 |         }
20 |     }
21 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/Room.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.MyMath;
 3 | using System;
 4 | using System.Linq;
 5 | 
 6 | namespace LandSky.Components
 7 | {
 8 |     /// 
 9 |     /// Passable area
10 |     /// 
11 |     public class Room : Component
12 |     {
13 |         public Room(string Name) : base(Name)
14 |         {
15 |             Rand = new Random(DateTime.Now.Millisecond + DateTime.Now.Second * 7187 + DateTime.Now.Minute * 8167);
16 |             IsPassable = true;
17 |         }
18 | 
19 |         public Room(string Name, Rectangle Bounds) : base(Name)
20 |         {
21 |             this.Bounds = Bounds;
22 |             Rand = new Random(DateTime.Now.Millisecond + DateTime.Now.Second * 7187 + DateTime.Now.Minute * 8167);
23 |             IsPassable = true;
24 |             GenerateWall();
25 |         }
26 | 
27 |         public void GenerateRandom(int Top, int Left, int Bottom, int Right)
28 |         {
29 |             if (Top < Bottom)
30 |             {
31 |                 int Temp = Top;
32 |                 Top = Bottom;
33 |                 Bottom = Temp;
34 |             }
35 |             if (Right < Left)
36 |             {
37 |                 int Temp = Left; Left = Right; Right = Temp;
38 |             }
39 | 
40 |             int L = Rand.Next(Left, Right);
41 |             int T = Rand.Next(Bottom, Top);
42 |             int B = Rand.Next(T - 20, T - 15);
43 |             int R = Rand.Next(L + 20, L + 70);
44 |             Bounds = new Rectangle(T, R, B, L);
45 |             MadeOf = Material.Air;
46 |         }
47 | 
48 |         public void GenerateRandom(Quadrant Quadrant, int Bound)
49 |         {
50 |             switch (Quadrant)
51 |             {
52 |                 case Quadrant.First:
53 |                     GenerateRandom(Bound, 0, 0, Bound);
54 |                     break;
55 | 
56 |                 case Quadrant.Second:
57 |                     GenerateRandom(Bound, -Bound, 0, 0);
58 |                     break;
59 | 
60 |                 case Quadrant.Third:
61 |                     GenerateRandom(0, -Bound, -Bound, 0);
62 |                     break;
63 | 
64 |                 case Quadrant.Fourth:
65 |                     GenerateRandom(0, 0, -Bound, Bound);
66 |                     break;
67 | 
68 |                 default:
69 |                     throw new ArgumentOutOfRangeException(nameof(Quadrant), Quadrant, null);
70 |             }
71 |         }
72 | 
73 |         public bool CollisionCheck(Room R)
74 |         {
75 |             return this.Parent.Controls.Any(N => N.Value.GetType() != typeof(Path) && N.Value & R);
76 |         }
77 | 
78 |         public void GenerateWall()
79 |         {
80 |             Wall WT = new Wall("TopWall", new Rectangle(Bounds.DistaceToTopBound, Bounds.DistaceToRightBound, Bounds.DistaceToTopBound, Bounds.DistaceToLeftBound));
81 |             Wall WB = new Wall("BottomWall", new Rectangle(Bounds.DistaceToBottomBound, Bounds.DistaceToRightBound, Bounds.DistaceToBottomBound, Bounds.DistaceToLeftBound));
82 |             Wall WL = new Wall("LeftWall", new Rectangle(Bounds.DistaceToTopBound, Bounds.DistaceToLeftBound, Bounds.DistaceToBottomBound, Bounds.DistaceToLeftBound));
83 |             Wall WR = new Wall("RightWall", new Rectangle(Bounds.DistaceToTopBound, Bounds.DistaceToRightBound, Bounds.DistaceToBottomBound, Bounds.DistaceToRightBound));
84 | 
85 |             WT.ZValue = ZValue + 1;
86 |             WB.ZValue = ZValue + 1;
87 |             WL.ZValue = ZValue + 1;
88 |             WR.ZValue = ZValue + 1;
89 |             this.Insert(WT);
90 |             this.Insert(WB);
91 |             this.Insert(WL);
92 |             this.Insert(WR);
93 |         }
94 |     }
95 | }


--------------------------------------------------------------------------------
/src/core.Portable/Components/Walls.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.MyMath;
 3 | 
 4 | namespace LandSky.Components
 5 | {
 6 |     public class Wall : Component
 7 |     {
 8 |         public Wall(string Name, Rectangle Bounds) : base(Name)
 9 |         {
10 |             MadeOf = Bounds.Width > Bounds.Height ? Material.HorisontalWall : Material.VerticalWall;
11 |             base.Bounds = Bounds;
12 |             IsPassable = false;
13 |         }
14 |     }
15 | }


--------------------------------------------------------------------------------
/src/core.Portable/Controls.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.Commands;
 2 | using LandSky.DotNetExt;
 3 | using LandSky.MyEnums;
 4 | using System.Collections.Generic;
 5 | 
 6 | namespace LandSky
 7 | {
 8 |     /// 
 9 |     /// Contains keymaps, and commandmaps
10 |     /// 
11 |     internal class CommandControls
12 |     {
13 |         public static Dictionary KeyMap = new Dictionary
14 |             {
15 |                 {new MyConsoleKeyInfo('h') , Comands.Left},
16 |                 {new MyConsoleKeyInfo('H'), Comands.TenStepsLeft},
17 |                 {new MyConsoleKeyInfo('l'), Comands.Right},
18 |                 {new MyConsoleKeyInfo('L'), Comands.TenStepsRight},
19 |                 {new MyConsoleKeyInfo('k'), Comands.Up},
20 |                 {new MyConsoleKeyInfo('K'), Comands.TenStepsUp},
21 |                 {new MyConsoleKeyInfo('j'), Comands.Down},
22 |                 {new MyConsoleKeyInfo('J'), Comands.TenStepsDown},
23 |                 {new MyConsoleKeyInfo('q'), Comands.ScrollLeft},
24 |                 {new MyConsoleKeyInfo('e'), Comands.ScrollRight},
25 |                 {new MyConsoleKeyInfo(','), Comands.ScrollLeft},
26 |                 {new MyConsoleKeyInfo('.'), Comands.ScrollRight},
27 |                 {new MyConsoleKeyInfo('r'), Comands.GenerateOneRoom},
28 |                 {new MyConsoleKeyInfo('R'), Comands.GenerateALotOfRooms},
29 |                 {new MyConsoleKeyInfo('P'), Comands.GenerateRandomPath},
30 |                 {new MyConsoleKeyInfo('d'), Comands.DequeMessage},
31 | 
32 |                 {new MyConsoleKeyInfo('s',true, false), Comands.ToJSON },
33 |                 {new MyConsoleKeyInfo((char)27), Comands.LastSceen},
34 |                 {new MyConsoleKeyInfo('?'), Comands.ShowHelp},
35 |                 {new MyConsoleKeyInfo('*'), Comands.ShowDebug},
36 |                 {new MyConsoleKeyInfo('1'), Comands.Option1},
37 |                 {new MyConsoleKeyInfo('2'), Comands.Option2},
38 |                 {new MyConsoleKeyInfo('3'), Comands.Option3},
39 |                 {new MyConsoleKeyInfo('4'), Comands.Option4},
40 |                 {new MyConsoleKeyInfo('5'), Comands.Option5},
41 |                 {new MyConsoleKeyInfo('6'), Comands.Option6},
42 |                 {new MyConsoleKeyInfo('7'), Comands.Option7},
43 |                 {new MyConsoleKeyInfo('8'), Comands.Option8},
44 |                 {new MyConsoleKeyInfo('9'), Comands.Option9}
45 |             };
46 | 
47 |         public static Dictionary InvokedBaseCommand = new Dictionary
48 |             {
49 |                 {Comands.GenerateOneRoom,     new GenerateRoomsCommand(1)},
50 |                 {Comands.GenerateALotOfRooms, new GenerateRoomsCommand(100)},
51 |                 {Comands.GenerateRandomPath,  new GeneratePathCommand() {NumberOfPaths = 1 } },
52 |                 {Comands.Left,                new MoveCommand(MoveDirection.Left, 1)},
53 |                 {Comands.TenStepsLeft,        new MoveCommand(MoveDirection.Left, 10)},
54 |                 {Comands.Right,               new MoveCommand(MoveDirection.Right, 1)},
55 |                 {Comands.TenStepsRight,       new MoveCommand(MoveDirection.Right, 10)},
56 |                 {Comands.Down,                new MoveCommand(MoveDirection.Down, 1)},
57 |                 {Comands.TenStepsDown,        new MoveCommand(MoveDirection.Down, 10)},
58 |                 {Comands.Up,                  new MoveCommand(MoveDirection.Up, 1)},
59 |                 {Comands.TenStepsUp,          new MoveCommand(MoveDirection.Up, 10)},
60 |                 {Comands.ScrollRight,         new ScrollCommand(1)},
61 |                 {Comands.ScrollLeft,          new ScrollCommand(-1)},
62 |                 {Comands.ShowHelp,            new BaseCommand()},
63 |                 {Comands.ShowDebug,           new BaseCommand()},
64 |                 {Comands.ToJSON,              new ScreenToJsonCommand("ScreenState")},
65 |                 {Comands.Option1,             new BaseCommand()},
66 |                 {Comands.Option2,             new BaseCommand()},
67 |                 {Comands.Option3,             new BaseCommand()},
68 |                 {Comands.Option4,             new BaseCommand()},
69 |                 {Comands.Option5,             new BaseCommand()},
70 |                 {Comands.Option6,             new BaseCommand()},
71 |                 {Comands.Option7,             new BaseCommand()},
72 |                 {Comands.Option8,             new BaseCommand()},
73 |                 {Comands.Option9,             new BaseCommand()},
74 |                 {Comands.LastSceen,           new BaseCommand()}
75 |             };
76 |     }
77 | }


--------------------------------------------------------------------------------
/src/core.Portable/DebugItems/DebugMessage.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | 
 3 | /// 
 4 | /// Debug tools go in here
 5 | /// 
 6 | namespace LandSky.DebugItems
 7 | {
 8 |     /// 
 9 |     /// This call is used to create debug messages
10 |     /// 
11 |     public class DebugMessage
12 |     {
13 |         public DateTime CreateTime;
14 |         public string Message;
15 | 
16 |         public DebugMessage(string Message)
17 |         {
18 |             this.Message = Message;
19 |             CreateTime = DateTime.Now;
20 |         }
21 | 
22 |         public override string ToString()
23 |         {
24 |             return $"({CreateTime})>{Message}";
25 |         }
26 |     }
27 | }


--------------------------------------------------------------------------------
/src/core.Portable/DotNetExt/ConsoleKeyInfo.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.DotNetExt
 2 | {
 3 |     /// 
 4 |     /// My implementation of ConsoleKeyInfo. Made because default one sucks...
 5 |     /// This one has nice constructors and no shitty ConsoleKey property!
 6 |     /// 
 7 |     public class MyConsoleKeyInfo : IMyConsoleKeyInfo
 8 |     {
 9 |         /// 
10 |         /// Key in a form of a char
11 |         /// 
12 |         public char KeyChar { get; set; }
13 | 
14 |         /// 
15 |         /// Is alt pressed
16 |         /// 
17 |         public bool Alt { get; set; } = false;
18 | 
19 |         /// 
20 |         /// Is Ctrl pressed
21 |         /// 
22 |         public bool Ctrl { get; set; } = false;
23 | 
24 |         /// 
25 |         /// Is shift pressed
26 |         /// 
27 |         public bool Shift { get; set; } = false;
28 | 
29 |         public MyConsoleKeyInfo(char KeyChar)
30 |         {
31 |             this.KeyChar = KeyChar;
32 |         }
33 | 
34 |         public MyConsoleKeyInfo(char KeyChar, bool Alt, bool Ctrl)
35 |         {
36 |             this.KeyChar = KeyChar;
37 |             this.Alt = Alt;
38 |             this.Ctrl = Ctrl;
39 |             this.Shift = Shift;
40 |         }
41 | 
42 |         public MyConsoleKeyInfo(char KeyChar, bool Alt, bool Ctrl, bool Shift)
43 |         {
44 |             this.KeyChar = KeyChar;
45 |             this.Alt = Alt;
46 |             this.Ctrl = Ctrl;
47 |             this.Shift = Shift;
48 |         }
49 | 
50 |         public static bool operator ==(MyConsoleKeyInfo One, MyConsoleKeyInfo Two) => One.KeyChar == Two.KeyChar &&
51 |                                                                                      One.Alt == Two.Alt &&
52 |                                                                                      One.Ctrl == Two.Ctrl &&
53 |                                                                                      One.Shift == Two.Shift;
54 | 
55 |         public static bool operator !=(MyConsoleKeyInfo One, MyConsoleKeyInfo Two) => !(One.KeyChar == Two.KeyChar &&
56 |                                                                                         One.Alt == Two.Alt &&
57 |                                                                                         One.Ctrl == Two.Ctrl &&
58 |                                                                                         One.Shift == Two.Shift);
59 | 
60 |         public override bool Equals(object obj) => (obj is MyConsoleKeyInfo) &&
61 |                                                    (obj as MyConsoleKeyInfo) == this;
62 | 
63 |         public override int GetHashCode() => this.Alt.GetHashCode() &
64 |                                              this.Shift.GetHashCode() &
65 |                                              this.Ctrl.GetHashCode() &
66 |                                              this.KeyChar.GetHashCode();
67 |     }
68 | }


--------------------------------------------------------------------------------
/src/core.Portable/DotNetExt/IMyConsoleKeyInfo.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.DotNetExt
 2 | {
 3 |     internal interface IMyConsoleKeyInfo
 4 |     {
 5 |         bool Alt { get; set; }
 6 |         bool Ctrl { get; set; }
 7 |         char KeyChar { get; set; }
 8 |         bool Shift { get; set; }
 9 |     }
10 | }


--------------------------------------------------------------------------------
/src/core.Portable/Engine.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.Components;
  2 | using LandSky.DotNetExt;
  3 | using LandSky.Screen;
  4 | using LandSky.UIComponents;
  5 | //using Newtonsoft.Json;
  6 | using System;
  7 | using System.Collections.Generic;
  8 | using System.Linq;
  9 | using LandSky.MyEnums;
 10 | using Microsoft.AspNet.SignalR.Client;
 11 | using Microsoft.AspNet.SignalR.Client.Transports;
 12 | 
 13 | namespace System.Runtime.Serialization.Formatters
 14 | {
 15 |     enum FormatterAssemblyStyle
 16 |     {
 17 |         Simple,
 18 |         Full
 19 |     }
 20 | }
 21 | 
 22 | namespace LandSky
 23 | {
 24 |     
 25 |     /// 
 26 |     /// This starts everything
 27 |     /// 
 28 |     public sealed class Engine : IServer
 29 |     {
 30 |         private string _name;
 31 |         private HubConnection _hub;
 32 |         private IHubProxy _http;
 33 |         private BaseScreen _activeScreen
 34 |         {
 35 |             get
 36 |             {
 37 |                 return BaseScreen.Active.Peek();
 38 |             }
 39 |         }
 40 | 
 41 |         public Component this[string Name]
 42 |         {
 43 |             get
 44 |             {
 45 |                 return _activeScreen?.Controls?[Name];
 46 |             }
 47 |         }
 48 | 
 49 |         public Engine(string Name)
 50 |         {
 51 |             _name = Name;
 52 |             PushNewScreenOnTop(new SandboxMap(0, 0));
 53 |             PushNewComponentOnActiveScreen(new Player(Name));
 54 |         }
 55 | 
 56 |         public bool InputNextCommand(MyConsoleKeyInfo Info)
 57 |         {
 58 |             var Cc = CommandControls.KeyMap.ContainsKey(Info) ? CommandControls.KeyMap[Info] : MyEnums.Comands.Any;
 59 |             return _activeScreen.ParseCommand(_name, Cc, Info);
 60 |         }
 61 | 
 62 |         public bool InputNextCommand(MyConsoleKeyInfo Info, string NameOfSubject)
 63 |         {
 64 |             var Cc = CommandControls.KeyMap.ContainsKey(Info) ? CommandControls.KeyMap[Info] : MyEnums.Comands.Any;
 65 |             return _activeScreen.ParseCommand(NameOfSubject, Cc, Info);
 66 |         }
 67 | 
 68 |         public bool InputNextCommand(Comands Command, string NameOfTheSubject)
 69 |         {
 70 |             var comm = CommandControls.KeyMap.FirstOrDefault(command => command.Value == Command);
 71 |             if (comm.Key == null)
 72 |                 return false;
 73 |             return InputNextCommand(comm.Key, NameOfTheSubject);
 74 |         }
 75 | 
 76 |         /// 
 77 |         /// Isn't working..
 78 |         /// 
 79 |         /// 
 80 |         public string StateToJSON()
 81 |         {
 82 |             //return JsonConvert.SerializeObject(BaseScreen.Active, BaseScreen.Active.GetType(), Formatting.Indented, new JsonSerializerSettings()
 83 |             //{
 84 |             //    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead,
 85 |             //    CheckAdditionalContent = true,
 86 |             //    DateFormatHandling = DateFormatHandling.IsoDateFormat,
 87 |             //    MaxDepth = 5,
 88 |             //    MissingMemberHandling = MissingMemberHandling.Ignore,
 89 |             //    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
 90 |             //    NullValueHandling = NullValueHandling.Include,
 91 |             //    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
 92 |             //});
 93 |             return "Isn't working";
 94 |         }
 95 | 
 96 |         /// 
 97 |         /// Isn't working
 98 |         /// 
 99 |         /// 
100 |         public void LoadFromJSON(string StackOfActiveScreens)
101 |         {
102 |             //BaseScreen.Active = JsonConvert.DeserializeObject>(StackOfActiveScreens);
103 |         }
104 | 
105 |         /// 
106 |         /// Isn't working
107 |         /// 
108 |         /// 
109 |         public string CurrentFrame()
110 |         {
111 |             return _activeScreen.CurrentStateOfTheScreen.StateOfConsole;
112 |         }
113 | 
114 |         /// 
115 |         /// Get all the components on the screen
116 |         /// 
117 |         /// 
118 |         public IEnumerable AllComponentsOnScreen()
119 |         {
120 |             foreach (var comp in _activeScreen.Controls)
121 |             {
122 |                 yield return comp.Value;
123 |             }
124 |         }
125 | 
126 |         public IEnumerable AllUIComponentsOnScreen()
127 |         {
128 |             foreach (var ui in _activeScreen.UIComponents)
129 |             {
130 |                 yield return ui;
131 |             }
132 |         }
133 | 
134 |         public void PushNewScreenOnTop(BaseScreen Screen)
135 |         {
136 |             BaseScreen.Active.Push(Screen);
137 |         }
138 | 
139 |         public void PushNewComponentOnActiveScreen(Component Component)
140 |         {
141 |             if (Component == null)
142 |                 throw new Exception("cant hadel it component is null");
143 |             if (Component?.Name == null || _activeScreen.Controls.Any(i => i.Value.Name == Component.Name))
144 |                 throw new Exception($"Component can't have that name... {Component?.Name} sorry bro");
145 |             _activeScreen.Controls.Add(Component.Name, Component);
146 |         }
147 | 
148 |         public void RemoveComponentFromActiveScreen(Component Component)
149 |         {
150 |             _activeScreen.Delete(Component.Name);
151 |         }
152 | 
153 |         public void RemoveComponentFromActiveScreen(string ComponentName)
154 |         {
155 |             _activeScreen.Delete(ComponentName);
156 |         }
157 | 
158 |         public void SetActiveComponent(Component NewActive, int NewWidth, int NewHeight)
159 |         {
160 |             if (_activeScreen is SandboxMap)
161 |             {
162 |                 (_activeScreen as SandboxMap).ChangeActiveComponent(NewActive.Name, NewWidth, NewHeight);
163 |             }
164 |             else
165 |             {
166 |                 throw new ArgumentOutOfRangeException("NewActive");
167 |             }
168 |         }
169 | 
170 |         public string RenderAroundComponent(Component Component, int Width, int Height)
171 |         {
172 |             if (_activeScreen is SandboxMap)
173 |             {
174 |                 SandboxMap Map = _activeScreen as SandboxMap;
175 |                 return Map.ReginToString(Component, Width, Height);
176 |             }
177 |             return "Sorry cant find active game :(";
178 |         }
179 | 
180 |         public string RenderAroundComponent()
181 |         {
182 |             if (_activeScreen is SandboxMap)
183 |             {
184 |                 return (_activeScreen as SandboxMap).ReginToString();
185 |             }
186 |             return "Sorry cant find active game :(";
187 |         }
188 | 
189 |         public Cell[][] CellArrayAroundComponent()
190 |         {
191 | 
192 |             if (_activeScreen is SandboxMap)
193 |             {
194 |                 return (_activeScreen as SandboxMap).GetRegin();
195 |             }
196 |             throw new MissingMemberException("No Active Screen, use PushNewScreenOnTop method");
197 |         }
198 | 
199 |         public void Connect(string Url)
200 |         {
201 |             _hub = new HubConnection("127.0.0.1:52062");
202 |             
203 |             _http = _hub.CreateHubProxy("ServerHub");
204 |             _http.On("InitMap", map => this.PushNewScreenOnTop(map));
205 |             _http.On("Update", (comm, ObjName) => this.InputNextCommand(comm, ObjName));
206 |             _http.On("CallBack", Message => System.Diagnostics.Debug.WriteLine(Message));
207 |            
208 |         }
209 |         public void Register(string Mail, string Password, string Username)
210 |         {
211 |             CheckHub();
212 |             _http?.Invoke("Register", Mail, Password, Username);
213 |         }
214 | 
215 |         public void Login(string MailOrUsername, string Password)
216 |         {
217 |             CheckHub();
218 |             _http?.Invoke("Login", MailOrUsername, Password);
219 |         }
220 | 
221 |         public void NewCommand(Comands Command, string Token)
222 |         {
223 |             CheckHub();
224 |             _http?.Invoke("NewCommand", Command, Token);
225 |         }
226 | 
227 |         public void Logout()
228 |         {
229 |             CheckHub();
230 |             _http?.Invoke("Logout");
231 |         }
232 | 
233 |         private void CheckHub()
234 |         {
235 | 
236 |             if (_http == null || _hub== null)
237 |                 throw new HubException("IHubProxy is null", _http);
238 |         }
239 |     }
240 | }


--------------------------------------------------------------------------------
/src/core.Portable/IClient.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.Screen;
 3 | using System;
 4 | using System.Collections.Generic;
 5 | using System.Linq;
 6 | using System.Text;
 7 | using System.Threading.Tasks;
 8 | 
 9 | namespace LandSky
10 | {
11 |     public interface IClient
12 |     {
13 |         void InitMap(SandboxMap Map);
14 |         void Update(Comands Command, string ObjectsName);
15 |         void CallBack(string Message);
16 | 
17 |     }
18 | }
19 | 


--------------------------------------------------------------------------------
/src/core.Portable/IServer.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using System;
 3 | using System.Collections.Generic;
 4 | using System.Linq;
 5 | using System.Text;
 6 | using System.Threading.Tasks;
 7 | 
 8 | namespace LandSky
 9 | {
10 |     public interface IServer
11 |     {
12 |         void Register(string Mail, string Password, string Username);
13 |         void Login(string MailOrUsername, string Password);
14 |         void NewCommand(Comands Command, string Token);
15 |         void Logout();
16 | 
17 |     }
18 | }
19 | 


--------------------------------------------------------------------------------
/src/core.Portable/MyEnums/Enums.cs:
--------------------------------------------------------------------------------
  1 | namespace LandSky.MyEnums
  2 | {
  3 |     /// 
  4 |     /// All supported commands
  5 |     /// 
  6 |     public enum Comands
  7 |     {
  8 |         Left,
  9 |         TenStepsLeft,
 10 |         Right,
 11 |         TenStepsRight,
 12 |         Up,
 13 |         TenStepsUp,
 14 |         Down,
 15 |         TenStepsDown,
 16 |         ScrollLeft,
 17 |         ScrollRight,
 18 |         LeftScene,
 19 |         RightScene,
 20 |         GenerateOneRoom,
 21 |         GenerateALotOfRooms,
 22 |         GenerateRandomPath,
 23 |         DequeMessage,
 24 |         ShowMessages,
 25 |         ShowDebug,
 26 |         ShowHelp,
 27 |         LastSceen,
 28 |         ToJSON,
 29 |         Option1,
 30 |         Option2,
 31 |         Option3,
 32 |         Option4,
 33 |         Option5,
 34 |         Option6,
 35 |         Option7,
 36 |         Option8,
 37 |         Option9,
 38 |         Any
 39 |     }
 40 | 
 41 |     /// 
 42 |     /// All supported monoms
 43 |     /// 
 44 |     public enum KindOfMonom
 45 |     {
 46 |         /// 
 47 |         /// a*x^BottomBound
 48 |         /// 
 49 |         Line,
 50 | 
 51 |         /// 
 52 |         /// a*Sin(BottomBound*x)
 53 |         /// 
 54 |         Sine,
 55 | 
 56 |         Constant
 57 |     }
 58 | 
 59 |     /// 
 60 |     /// All supported material that can be displayed
 61 |     /// 
 62 |     public enum Material
 63 |     {
 64 |         Path,
 65 |         HorisontalWall,
 66 |         VerticalWall,
 67 |         Trap,
 68 |         Player,
 69 |         Npc,
 70 |         Loot,
 71 |         Water,
 72 |         Fire,
 73 |         Air,
 74 |         Darknes
 75 |     }
 76 | 
 77 |     /// 
 78 |     /// All of different game screens that can be displayed
 79 |     /// 
 80 |     public enum GameSceens
 81 |     {
 82 |         Game
 83 |     }
 84 | 
 85 |     /// 
 86 |     /// Different menu screens that can be displayed
 87 |     /// 
 88 |     public enum MenuSceens
 89 |     {
 90 |         MainMenu,
 91 |         Help,
 92 |         KeyMap,
 93 |         ListRooms,
 94 |         ListPaths,
 95 |         Message,
 96 |         Debug
 97 |     }
 98 | 
 99 |     /// 
100 |     /// Directions the player can move
101 |     /// 
102 |     public enum MoveDirection
103 |     {
104 |         Up,
105 |         UpRight,
106 |         Right,
107 |         DownRight,
108 |         Down,
109 |         DownLeft,
110 |         Left,
111 |         UpLeft
112 |     }
113 | 
114 |     /// 
115 |     /// Cartesian coordinate system quadrants
116 |     /// 
117 |     public enum Quadrant
118 |     {
119 |         First,
120 |         Second,
121 |         Third,
122 |         Fourth
123 |     }
124 | 
125 |     /// 
126 |     /// Supported states of the screen
127 |     /// 
128 |     public enum ScreenState
129 |     {
130 |         Active,
131 |         Paused,
132 |         Disposed
133 |     }
134 | 
135 |     public enum SizeMode
136 |     {
137 |         Auto,
138 |         Explicit
139 |     }
140 | 
141 |     public enum InputMode
142 |     {
143 |         ControlOnly,
144 |         ControlFirst,
145 |         InputOnly,
146 |         InputFirst
147 |     }
148 | 
149 |     public enum SpecialAsciiKeys
150 |     {
151 |         Tab = 9,
152 |         Space = 32,
153 |         Backspace = 8,
154 |         Del = 127,
155 |         ArrowDown = 40,
156 |         ArrowRight = 39,
157 |         ArrowUp = 38,
158 |         ArrowLeft = 37
159 |     }
160 | 
161 |     public enum PermissionsLevel
162 |     {
163 |         User,
164 |         RegisterdUser,
165 |         ServerAdmin,
166 |         GlobalAdmin
167 |     }
168 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyEventArgs/ScreenChangedArgs.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | 
 3 | namespace LandSky.MyEventArgs
 4 | {
 5 |     public class ScreenChangedArgs : EventArgs
 6 |     {
 7 |         public string StateOfConsole;
 8 |         public string BodyString;
 9 |         public DateTime DateOfCreation;
10 | 
11 |         public ScreenChangedArgs(string StateOfConsole, string BodyString) : base()
12 |         {
13 |             this.StateOfConsole = StateOfConsole;
14 |             this.BodyString = BodyString;
15 |             DateOfCreation = DateTime.Now;
16 |         }
17 |     }
18 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/FastMath.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | 
 3 | namespace LandSky.MyMath
 4 | {
 5 |     public static class FastMath
 6 |     {
 7 |         public static int ipow(int Base, int Exp)
 8 |         {
 9 |             int result = 1;
10 |             while (0 != Exp)
11 |             {
12 |                 if (0 != (Exp & 1))
13 |                     result *= Base;
14 |                 Exp >>= 1;
15 |                 Base *= Base;
16 |             }
17 | 
18 |             return result;
19 |         }
20 | 
21 |         public static int DoubleToInt(double Double)
22 |         {
23 |             return (int)Math.Round(Double);
24 |         }
25 | 
26 |         /// 
27 |         /// Returns true if this Num is inside this range [LowerBound, UpperBound>
28 |         /// 
29 |         /// 
30 |         /// 
31 |         /// 
32 |         /// 
33 |         public static bool IsInside(int Num, int LowerBound, int UpperBound)
34 |         {
35 |             return LowerBound <= Num && Num < UpperBound;
36 |         }
37 |     }
38 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Interolator.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.MyEnums;
  2 | using System;
  3 | using System.Collections.Generic;
  4 | using System.Linq;
  5 | using static System.Math;
  6 | 
  7 | namespace LandSky.MyMath
  8 | {
  9 |     /// 
 10 |     /// Used for interpolating polinonm that in on a list of points
 11 |     /// 
 12 |     public class LinearInterpolator
 13 |     {
 14 |         private List mPolinom;
 15 | 
 16 |         public LinearInterpolator()
 17 |         {
 18 |             mPolinom = new List();
 19 |         }
 20 | 
 21 |         public double ValueForX(double X)
 22 |         {
 23 |             double Rj = 0;
 24 |             foreach (Monom m in mPolinom)
 25 |             {
 26 |                 Rj += m.ValuForX(X);
 27 |             }
 28 |             return Round(Rj, 2);
 29 |         }
 30 | 
 31 |         public int IntValueForX(int X)
 32 |         {
 33 |             int Rj = 0;
 34 |             foreach (Monom m in mPolinom)
 35 |             {
 36 |                 Rj += m.IntValuForX(X);
 37 |             }
 38 |             return Rj;
 39 |         }
 40 | 
 41 |         public double ValueForX(int X)
 42 |         {
 43 |             return ValueForX(Convert.ToDouble(X));
 44 |         }
 45 | 
 46 |         public double DerivativeForX(double X)
 47 |         {
 48 |             double Rj = 0;
 49 |             foreach (Monom m in mPolinom)
 50 |             {
 51 |                 Rj += m.DerivativeForX(X);
 52 |             }
 53 |             return Round(Rj, 0);
 54 |         }
 55 | 
 56 |         public double DerivativeForX(int X)
 57 |         {
 58 |             return DerivativeForX(Convert.ToDouble(X));
 59 |         }
 60 | 
 61 |         public int IntDerivativeForX(int X)
 62 |         {
 63 |             int Rj = 0;
 64 |             foreach (Monom m in mPolinom)
 65 |             {
 66 |                 Rj += m.IntDerivativeForX(X);
 67 |             }
 68 |             return Rj;
 69 |         }
 70 | 
 71 |         private void CheckIfOneCanInterpolate(List Points)
 72 |         {
 73 |             foreach (Point P in Points)
 74 |             {
 75 |                 int N = 0;
 76 |                 for (int I = 0; I < Points.Count; I++)
 77 |                 {
 78 |                     if (Points[I].X == P.X)
 79 |                         N++;
 80 |                 }
 81 |                 if (N != 1)
 82 |                     throw new Exception("Can't interpolate if you have two or more points with the same x, sorry... remove duplicates or use non correct interpolation");
 83 |             }
 84 |         }
 85 | 
 86 |         public void Interpolate(List Points, KindOfMonom Monoms)
 87 |         {
 88 |             Interpolate(Points, Monoms, false);
 89 |         }
 90 | 
 91 |         public void Interpolate(List Points, KindOfMonom Monoms, bool MustBeCorrect)
 92 |         {
 93 |             if (MustBeCorrect)
 94 |                 CheckIfOneCanInterpolate(Points);
 95 |             if (Monoms == KindOfMonom.Constant)
 96 |                 throw new Exception("One can't interpolate array of points only with constants, one can but it wont be good... don't select constants, pls, select line it's good, or sine");
 97 |             List Monomz = new List(Points.Count);
 98 |             Monomz.Add(KindOfMonom.Constant);
 99 |             for (int I = 1; I < Points.Count; I++)
100 |             {
101 |                 Monomz.Add(Monoms);
102 |             }
103 |             Interpolate(Points, Monomz);
104 |         }
105 | 
106 |         public void Interpolate(List Points, List Monoms)
107 |         {
108 |             List> Matrix = new List>(Points.Count);
109 |             mPolinom = new List();
110 |             int LastLine = -1, LastSine = 0;
111 |             for (int I = 0; I < Points.Count; I++)
112 |             {
113 |                 Matrix.Add(new List());
114 |                 for (int J = 0; J < Points.Count + 2; J++)
115 |                 {
116 |                     Matrix[I].Add(0);
117 |                 }
118 |             }
119 |             for (int I = 0; I < Points.Count; I++)
120 |             {
121 |                 switch (Monoms[I])
122 |                 {
123 |                     case KindOfMonom.Constant:
124 |                         mPolinom.Add(new Monom(1));
125 |                         for (int J = 0; J < Points.Count; J++)
126 |                         {
127 |                             Matrix[J][I] = 1;
128 |                         }
129 |                         break;
130 | 
131 |                     case KindOfMonom.Line:
132 |                         LastLine++;
133 |                         mPolinom.Add(new Monom(KindOfMonom.Line, 1, LastLine));
134 |                         for (int J = 1; J < Points.Count; J++)
135 |                         {
136 |                             Point P = Points[J];
137 |                             Matrix[J][I] = Pow(P.X, LastLine);
138 |                         }
139 |                         break;
140 | 
141 |                     case KindOfMonom.Sine:
142 |                         LastSine++;
143 |                         mPolinom.Add(new Monom(KindOfMonom.Sine, 1, LastSine));
144 |                         for (int J = 1; J < Points.Count; J++)
145 |                         {
146 |                             Point P = Points[J];
147 |                             Matrix[J][I] = Sin(LastSine * P.X);
148 |                         }
149 |                         break;
150 |                 }
151 | 
152 |                 Matrix[I][Points.Count] = (Points[I].Y);
153 |                 //start x
154 |                 Matrix[I][Points.Count + 1] = I;
155 |             }
156 |             List Aas = SolveMatrix(Matrix);
157 |             for (int I = 0; I < Aas.Count; I++)
158 |             {
159 |                 mPolinom[I].InterpolatedValue = Aas[I];
160 |             }
161 |         }
162 | 
163 |         public void Interpolate(List Points, List Monoms, bool MustBeCorrect)
164 |         {
165 |             if (MustBeCorrect)
166 |                 CheckIfOneCanInterpolate(Points);
167 |             Interpolate(Points, Monoms);
168 |         }
169 | 
170 |         public override string ToString()
171 |         {
172 |             return mPolinom.Aggregate(string.Empty, (Current, m) => Current + (" " + m.LinearRepresentationOfMonom() + " "));
173 |         }
174 | 
175 |         public List SolveMatrix(List> Matrix)
176 |         {
177 |             if (Matrix[0].Count - 2 != Matrix.Count)
178 |                 throw new Exception("One can only interpolate Matrix of size n*n+2\n a*X=BottomBound a:= n*n matrix, BottomBound:= 1*n combination, and 1*n matrix where are saved original indexes of rows");
179 | 
180 |             #region down
181 | 
182 |             int N = Matrix.Count;
183 |             if (Matrix[0].Count - 1 == Matrix.Count)
184 |             {
185 |                 for (int I = 0; I < Matrix.Count; I++)
186 |                 {
187 |                     Matrix[I].Add(I);
188 |                 }
189 |             }
190 |             double Miny = 0.0001;
191 |             for (int I = 0; I < N; I++)
192 |             {
193 |                 if (Abs(Matrix[I][I]) - Miny <= 0)
194 |                 {
195 |                     bool Found = false;
196 |                     for (int J = N - 1; J > I; J--)
197 |                     {
198 |                         if (Abs(Matrix[J][I]) - Miny > 0)
199 |                         {
200 |                             List Temp = Matrix[I];
201 |                             Matrix[I] = Matrix[J];
202 |                             Matrix[J] = Temp;
203 |                             Found = true;
204 |                             J = I;
205 |                         }
206 |                     }
207 |                     if (!Found)
208 |                         throw new Exception("Sorry can't interpolate :(");
209 |                 }
210 | 
211 |                 for (int J = I + 1; J < N; J++)
212 |                 {
213 |                     double Koeficjent = Matrix[J][I] / Matrix[I][I];
214 | 
215 |                     for (int K = 0; K < N + 1; K++)
216 |                     {
217 |                         Matrix[J][K] = Matrix[J][K] - (Koeficjent * Matrix[I][K]);
218 |                     }
219 |                 }
220 |             }
221 | 
222 |             #endregion down
223 | 
224 |             #region up
225 | 
226 |             for (int I = (N - 1); I >= 0; I--)
227 |             {
228 |                 for (int J = I - 1; J >= 0; J--)
229 |                 {
230 |                     double Koeficjent = new double();
231 |                     Koeficjent = Matrix[J][I] / Matrix[I][I];
232 |                     Matrix[J][I] = 0;
233 |                     Matrix[J][N] = Matrix[J][N] - Koeficjent * Matrix[I][N];
234 |                 }
235 |             }
236 | 
237 |             #endregion up
238 | 
239 |             #region solve
240 | 
241 |             List Soluton = new List(N);
242 |             for (int I = 0; I < N; I++)
243 |             {
244 |                 Soluton.Add(1);
245 |             }
246 |             for (int I = 0; I < N; I++)
247 |             {
248 |                 Soluton[Convert.ToInt32(Matrix[I][N + 1])] = Matrix[I][N] / Matrix[I][I];
249 |             }
250 | 
251 |             #endregion solve
252 | 
253 |             return Soluton;
254 |         }
255 |     }
256 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Monom.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.MyEnums;
  2 | using System;
  3 | using static LandSky.MyMath.FastMath;
  4 | using static System.Math;
  5 | 
  6 | namespace LandSky.MyMath
  7 | {
  8 |     /// 
  9 |     /// This is monom just like in math
 10 |     /// 
 11 |     public class Monom
 12 |     {
 13 |         private double mA, mB, mC;
 14 |         private int _a, _b, _c;
 15 |         private const double mTolerance = 10e-6;
 16 | 
 17 |         public KindOfMonom ThisKindOfMonom;
 18 | 
 19 |         public KindOfMonom SetThisKindOfMonomKind
 20 |         {
 21 |             get
 22 |             {
 23 |                 return ThisKindOfMonom;
 24 |             }
 25 |             set
 26 |             {
 27 |                 mA = mB = mC = 0;
 28 |                 _a = _b = _c = 0;
 29 |                 ThisKindOfMonom = value;
 30 |             }
 31 |         }
 32 | 
 33 |         public double ParamaterA => ThisKindOfMonom != KindOfMonom.Constant ? mA : 0;
 34 |         public double ParamaterB => ThisKindOfMonom != KindOfMonom.Constant ? mB : 0;
 35 |         public double Constant => ThisKindOfMonom == KindOfMonom.Constant ? mC : 0;
 36 | 
 37 |         public double InterpolatedValue
 38 |         {
 39 |             get
 40 |             {
 41 |                 return this.ThisKindOfMonom != KindOfMonom.Constant ? mA : mC;
 42 |             }
 43 |             set
 44 |             {
 45 |                 if (this.ThisKindOfMonom != KindOfMonom.Constant)
 46 |                 {
 47 |                     mA = value;
 48 |                     _a = DoubleToInt(value);
 49 |                 }
 50 |                 else
 51 |                 {
 52 |                     mC = value;
 53 |                     _c = DoubleToInt(value);
 54 |                 }
 55 |             }
 56 |         }
 57 | 
 58 |         public Monom(KindOfMonom ThisKindOfMonom, double ParamaterA, double ParamaterB)
 59 |         {
 60 |             if (ThisKindOfMonom != KindOfMonom.Constant)
 61 |             {
 62 |                 mA = ParamaterA;
 63 |                 mB = ParamaterB;
 64 |                 _a = DoubleToInt(ParamaterA);
 65 |                 _b = DoubleToInt(ParamaterB);
 66 |             }
 67 |             else
 68 |             {
 69 |                 mC = DoubleToInt(ParamaterA);
 70 |                 _c = DoubleToInt(ParamaterA);
 71 |             }
 72 |             this.ThisKindOfMonom = ThisKindOfMonom;
 73 |         }
 74 | 
 75 |         public Monom(double Constant)
 76 |         {
 77 |             ThisKindOfMonom = KindOfMonom.Constant;
 78 |         }
 79 | 
 80 |         public double ValuForX(double X)
 81 |         {
 82 |             switch (ThisKindOfMonom)
 83 |             {
 84 |                 case KindOfMonom.Line:
 85 |                     return mA * Pow(X, mB);
 86 | 
 87 |                 case KindOfMonom.Sine:
 88 |                     return mA * Sin(mB * X);
 89 | 
 90 |                 case KindOfMonom.Constant:
 91 |                     return mC;
 92 | 
 93 |                 default:
 94 |                     throw new ArgumentOutOfRangeException();
 95 |             }
 96 |         }
 97 | 
 98 |         public int IntValuForX(int X)
 99 |         {
100 |             switch (ThisKindOfMonom)
101 |             {
102 |                 case KindOfMonom.Line:
103 |                     return _a * ipow(X, _b);
104 | 
105 |                 case KindOfMonom.Sine:
106 |                     return _a;
107 | 
108 |                 case KindOfMonom.Constant:
109 |                     return _c;
110 | 
111 |                 default:
112 |                     throw new ArgumentOutOfRangeException();
113 |             }
114 |         }
115 | 
116 |         public double DerivativeForX(double X)
117 |         {
118 |             switch (ThisKindOfMonom)
119 |             {
120 |                 case KindOfMonom.Constant:
121 |                     return 0;
122 | 
123 |                 case KindOfMonom.Line:
124 |                     if (Abs(mB - 1) < mTolerance)
125 |                         return mA;
126 |                     if (Abs(mB) < mTolerance)
127 |                         return 0;
128 |                     return mA * mB * Pow(X, mB - 1);
129 | 
130 |                 case KindOfMonom.Sine:
131 |                     if (Abs(mB) < mTolerance)
132 |                         return 0;
133 |                     return mB * mA * Cos(mB * X);
134 | 
135 |                 default:
136 |                     throw new ArgumentOutOfRangeException();
137 |             }
138 |         }
139 | 
140 |         public int IntDerivativeForX(int X)
141 |         {
142 |             switch (ThisKindOfMonom)
143 |             {
144 |                 case KindOfMonom.Constant:
145 |                     return 0;
146 | 
147 |                 case KindOfMonom.Line:
148 |                     if (Abs(mB - 1) < mTolerance)
149 |                         return _a;
150 |                     if (Abs(mB) < mTolerance)
151 |                         return 0;
152 |                     return _a * _b * ipow(X, _b - 1);
153 | 
154 |                 case KindOfMonom.Sine:
155 |                     if (Abs(mB) < mTolerance)
156 |                         return 0;
157 |                     return _b * _a;
158 | 
159 |                 default:
160 |                     throw new ArgumentOutOfRangeException();
161 |             }
162 |         }
163 | 
164 |         public string LinearRepresentationOfMonom()
165 |         {
166 |             const string plus = "+";
167 |             switch (ThisKindOfMonom)
168 |             {
169 |                 case KindOfMonom.Constant:
170 |                     if (mC > 0)
171 |                         return plus + $"{Round(mC, 2)}";
172 |                     return mC < 0 ? $"{Round(mC, 2)}" : string.Empty;
173 | 
174 |                 case KindOfMonom.Line:
175 |                     if (mB > 1)
176 |                     {
177 |                         if (mA > 0)
178 |                             return plus + $"{Round(mA, 2)}X^{Round(mB, 2)}";
179 |                         return mA < 0 ? $"{Round(mA, 2)}X^{Round(mB, 2)}" : string.Empty;
180 |                     }
181 |                     if (Abs(mB - 1) < mTolerance)
182 |                     {
183 |                         if (mA > 0)
184 |                             return plus + $"{Round(mA, 2)}X";
185 |                         return mA < 0 ? $"{Round(mA, 2)}X" : string.Empty;
186 |                     }
187 |                     else
188 |                     {
189 |                         if (mA > 0)
190 |                             return plus + $"{Round(mA, 2)}";
191 |                         return mA < 0 ? $"{Round(mA, 2)}" : string.Empty;
192 |                     }
193 |                 case KindOfMonom.Sine:
194 |                     if (Abs(mB) > mTolerance)
195 |                     {
196 |                         if (Abs(mA - 1) < mTolerance)
197 |                             return plus + $"Sin(X{Round(mB, 2)})";
198 |                         if (Abs(mA + 1) < mTolerance)
199 |                             return plus + $"-Sin(X{Round(mB, 2)})";
200 |                         if (mA > 0)
201 |                             return plus + $"{Round(mA, 2)}Sin({Round(mB, 2)}X)";
202 |                         return mA < 0 ? $"{Round(mA, 2)}Sin({Round(mB, 2)}X)" : string.Empty;
203 |                     }
204 |                     return string.Empty;
205 | 
206 |                 default:
207 |                     return string.Empty;
208 |             }
209 |         }
210 |     }
211 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Monom3D.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using static System.Math;
 3 | 
 4 | namespace LandSky.MyMath
 5 | {
 6 |     internal class Monom3D : Monom
 7 |     {
 8 |         /// 
 9 |         /// It looks like this: f(x,y)=ParamaterA*sin(ParamaterB*x*y + ParamaterA)
10 |         /// 
11 |         /// 
12 |         /// 
13 |         public Monom3D(double ParamaterA, double ParamaterB) : base(KindOfMonom.Sine, ParamaterA, ParamaterB)
14 |         {
15 |         }
16 | 
17 |         public bool IsBiggerThanZero(int x, int y)
18 |         {
19 |             return Sin(ParamaterB * x * y + ParamaterA) > 0;
20 |         }
21 | 
22 |         public double ValueForX(int x, int y)
23 |         {
24 |             return Cos(ParamaterA * x * y + ParamaterB) * Sin(ParamaterB * x * y + ParamaterA);
25 |         }
26 | 
27 |         public double ValueForX(Point Location)
28 |         {
29 |             return ValueForX(Location.X, Location.Y);
30 |         }
31 |     }
32 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Point.cs:
--------------------------------------------------------------------------------
 1 | using static System.Convert;
 2 | using static System.Math;
 3 | 
 4 | namespace LandSky.MyMath
 5 | {
 6 |     /// 
 7 |     /// Point class
 8 |     /// 
 9 |     public class Point
10 |     {
11 |         public int X, Y;
12 | 
13 |         public Point(int X, int Y)
14 |         {
15 |             this.X = X;
16 |             this.Y = Y;
17 |         }
18 | 
19 |         public static Point Origin()
20 |         {
21 |             return new Point(0, 0);
22 |         }
23 | 
24 |         public Point ToTopLeft(Size S, int X, int Y)
25 |         {
26 |             Point P = new Point(Max(1, Min(S.Width - 1, X - this.X)), Max(1, Min(S.Height - 2, -Y + this.Y)));
27 |             return P;
28 |         }
29 | 
30 |         public int Distance(Point To)
31 |         {
32 |             return ToInt32(Sqrt(Pow(this.X - To.X, 2) + Pow(this.Y - To.Y, 2)));
33 |         }
34 | 
35 |         public int DistanceOnXAxis(Point To)
36 |         {
37 |             return Abs(To.X - this.X);
38 |         }
39 | 
40 |         public int AbsDerivative(Point To)
41 |         {
42 |             return Abs(ToInt32((this.Y - To.Y) / (this.X - To.X)));
43 |         }
44 | 
45 |         public static Point operator -(Point A, Point B)
46 |         {
47 |             return new Point(B.X - A.X, B.Y - A.Y);
48 |         }
49 | 
50 |         public static Point operator +(Point A, Point B)
51 |         {
52 |             return new Point(A.X + B.X, A.Y + B.Y);
53 |         }
54 | 
55 |         public static bool operator ==(Point a, Point b) => a.X == b.X && a.Y == b.Y;
56 | 
57 |         public static bool operator !=(Point a, Point b) => !(a == b);
58 | 
59 |         public override bool Equals(object obj) => (obj is Point) && (obj as Point) == this;
60 | 
61 |         public override int GetHashCode()
62 |         {
63 |             int hash = 13;
64 |             hash = (hash) + this.X.GetHashCode();
65 |             hash = (hash * 7) + this.Y.GetHashCode();
66 |             return hash;
67 |         }
68 |     }
69 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/PointWithLifetime.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | 
 3 | namespace LandSky.MyMath
 4 | {
 5 |     internal class PointWithLifetime : Point
 6 |     {
 7 |         public DateTime LastUsed;
 8 | 
 9 |         public PointWithLifetime(int X, int Y) : base(X, Y)
10 |         {
11 |             LastUsed = DateTime.Now;
12 |         }
13 | 
14 |         public Point GiveMePoint()
15 |         {
16 |             LastUsed = DateTime.Now;
17 |             return this;
18 |         }
19 | 
20 |         public static bool operator ==(PointWithLifetime one, PointWithLifetime two) => one.X == two.X &&
21 |                                                                                    one.Y == two.Y;
22 | 
23 |         public static bool operator !=(PointWithLifetime one, PointWithLifetime two) => !(one == two);
24 | 
25 |         public static bool operator <(PointWithLifetime one, PointWithLifetime two) => one.LastUsed < two.LastUsed;
26 | 
27 |         public static bool operator >(PointWithLifetime one, PointWithLifetime two) => one.LastUsed > two.LastUsed;
28 | 
29 |         public static bool operator <=(PointWithLifetime one, PointWithLifetime two) => one.LastUsed <= two.LastUsed;
30 | 
31 |         public static bool operator >=(PointWithLifetime one, PointWithLifetime two) => one.LastUsed >= two.LastUsed;
32 | 
33 |         public override bool Equals(object obj) => obj is PointWithLifetime &&
34 |                                                    (obj as PointWithLifetime) == this;
35 | 
36 |         public override int GetHashCode()
37 |         {
38 |             int hash = 13;
39 |             hash = (hash) + this.X.GetHashCode();
40 |             hash = (hash * 7) + this.Y.GetHashCode();
41 |             return hash;
42 |         }
43 |     }
44 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Polinom3D.cs:
--------------------------------------------------------------------------------
 1 | using System.Collections.Generic;
 2 | using System.Linq;
 3 | 
 4 | namespace LandSky.MyMath
 5 | {
 6 |     internal class Polinom3D
 7 |     {
 8 |         public List Monoms = new List();
 9 | 
10 |         public bool IsBiggerThanZero(int x, int y)
11 |         {
12 |             if (Monoms.Count < 100)
13 |                 return Monoms.Sum(Mon => Mon.ValueForX(x, y)) > -1;
14 |             return Monoms.AsParallel().Sum(Mon => Mon.ValueForX(x, y)) > -1;
15 |         }
16 | 
17 |         public double ValueForX(int x, int y)
18 |         {
19 |             if (Monoms.Count < 100)
20 |                 return Monoms.Sum(Mon => Mon.ValueForX(x, y));
21 |             return Monoms.AsParallel().Sum(Mon => Mon.ValueForX(x, y));
22 |         }
23 |     }
24 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Rectangle.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using static System.Math;
  3 | 
  4 | namespace LandSky.MyMath
  5 | {
  6 |     /// 
  7 |     /// Rectangle class
  8 |     /// 
  9 |     public class Rectangle
 10 |     {
 11 |         private int mMx;
 12 |         private int mMy;
 13 | 
 14 |         public int LeftBound { get; private set; }
 15 |         public int RightBound { get; private set; }
 16 |         public int TopBound { get; private set; }
 17 |         public int BottomBound { get; private set; }
 18 | 
 19 |         public int DistaceToLeftBound => LeftBound - mMx;
 20 |         public int DistaceToRightBound => RightBound - mMx;
 21 |         public int DistaceToBottomBound => BottomBound - mMy;
 22 |         public int DistaceToTopBound => TopBound - mMy;
 23 | 
 24 |         public int X
 25 |         {
 26 |             get
 27 |             {
 28 |                 return mMx;
 29 |             }
 30 |             set
 31 |             {
 32 |                 mMx = value;
 33 |                 int RightTs = mMx + Width / 2;
 34 |                 int LeftTs = RightTs - Width + 1;
 35 |                 LeftBound = LeftTs;
 36 |                 RightBound = RightTs;
 37 |             }
 38 |         }
 39 | 
 40 |         public int Y
 41 |         {
 42 |             get
 43 |             {
 44 |                 return mMy;
 45 |             }
 46 | 
 47 |             set
 48 |             {
 49 |                 mMy = value;
 50 |                 int BottomTs = mMy - Height / 2;
 51 |                 int TopTs = BottomTs + Height - 1;
 52 |                 TopBound = TopTs;
 53 |                 BottomBound = BottomTs;
 54 |             }
 55 |         }
 56 | 
 57 |         public Point Location => new Point(this.X, this.Y);
 58 |         public int Width => this.RightBound - this.LeftBound + 1;
 59 |         public int Height => this.TopBound - this.BottomBound + 1;
 60 | 
 61 |         private void InitXy()
 62 |         {
 63 |             int LR = LeftBound + RightBound;
 64 |             int TB = TopBound + BottomBound;
 65 | 
 66 |             X = (LR) / 2 + (LR < 0 ? LR % 2 : 0);
 67 |             Y = TB / 2 + (TB < 0 ? 0 : TB % 2);
 68 |         }
 69 | 
 70 |         public Rectangle(int T, int R, int B, int L)
 71 |         {
 72 |             this.LeftBound = L;
 73 |             this.RightBound = R;
 74 |             this.TopBound = T;
 75 |             this.BottomBound = B;
 76 |             InitXy();
 77 |         }
 78 | 
 79 |         public Rectangle(Point Location, int Width, int Height)
 80 |         {
 81 |             if (Width == 0 || Height == 0)
 82 |                 throw new Exception("Cant have width or height 0");
 83 |             Width--;
 84 |             Height--;
 85 |             this.LeftBound = Location.X - Width / 2;
 86 |             this.RightBound = Location.X + Width / 2 + Width % 2;
 87 |             this.TopBound = Location.Y + Height / 2;
 88 |             this.BottomBound = Location.Y - Height / 2 + Height % 2;
 89 |             InitXy();
 90 |         }
 91 | 
 92 |         public static Rectangle DefineRectangleByWidthAndHeight(int X, int Y, int Width, int Height)
 93 |         {
 94 |             int negX = X < 0 ? 1 : 0;
 95 |             int negY = Y < 0 ? 1 : 0;
 96 |             return new Rectangle(Y + Height / 2 - negY, X + Width / 2 + Width % 2 - negX, Y - Height / 2 - Height % 2 - negY, X - Width / 2 - negX);
 97 |         }
 98 | 
 99 |         /// 
100 |         /// Convert from Cartesian coordinates system to Top Left coordinates
101 |         /// 
102 |         /// X coordinate in Cartesian coordinate system 
103 |         /// Y coordinate in Cartesian coordinate system
104 |         /// Returns a Top Left style point 
105 |         public Point ToTopLeft(int x, int y)
106 |         {
107 |             int Top = Min(this.Height - 1, Max(1, this.TopBound - y));
108 |             int Left = Min(this.Width - 1, Max(1, this.RightBound - x));
109 |             Point P = new Point(Top, Left);
110 |             return P;
111 |         }
112 | 
113 |         /// 
114 |         /// Convert from Cartesian coordinates system to Top Left coordinates
115 |         /// 
116 |         /// Rectangle you want to transform
117 |         /// Returns a Top Left style Rectangle 
118 |         public Rectangle ToTopLeft(Rectangle Bounds)
119 |         {
120 |             var TransformdT = Max(0, Min(this.Height - 1, this.TopBound - Bounds.TopBound));
121 |             var TransformdR = Max(0, Min(this.Width - 1, Bounds.RightBound - this.LeftBound));
122 |             var TransformdB = Max(1, Min(this.Height - 1, this.TopBound - Bounds.BottomBound));
123 |             var TransformdL = Max(0, Min(this.Width - 1, Bounds.LeftBound - this.LeftBound));
124 | 
125 |             return new Rectangle(TransformdT, TransformdR, TransformdB, TransformdL)
126 |             {
127 |                 TopBound = TransformdT,
128 |                 RightBound = TransformdR,
129 |                 BottomBound = TransformdB,
130 |                 LeftBound = TransformdL
131 |             };
132 |         }
133 | 
134 |         public static Rectangle RectangleZero() => new Rectangle(0, 0, 0, 0);
135 | 
136 |         public static Rectangle operator -(Rectangle one, Rectangle two)
137 |         {
138 |             if (!(one & two))
139 |                 return RectangleZero();
140 |             return new Rectangle(Min(one.TopBound, two.TopBound),
141 |                                  Min(one.RightBound, two.RightBound),
142 |                                  Max(one.BottomBound, two.BottomBound),
143 |                                  Max(one.LeftBound, two.LeftBound));
144 |         }
145 | 
146 |         public static Rectangle operator -(Rectangle Rc, Point P)
147 |         {
148 |             return new Rectangle(Rc.TopBound - P.Y, Rc.RightBound - P.X, Rc.BottomBound - P.Y, Rc.LeftBound - P.X);
149 |         }
150 | 
151 |         public static Rectangle operator +(Rectangle Rc, Point P)
152 |         {
153 |             return new Rectangle(Rc.TopBound + P.Y, Rc.RightBound + P.X, Rc.BottomBound + P.Y, Rc.LeftBound + P.X);
154 |         }
155 | 
156 |         public static Rectangle operator +(Rectangle One, Rectangle Two)
157 |         {
158 |             return new Rectangle(One.TopBound + Two.Y, One.RightBound + Two.X, One.BottomBound + Two.Y, One.LeftBound + Two.X);
159 |         }
160 | 
161 |         public static bool operator &(Rectangle One, Rectangle Two)
162 |         {
163 |             return (One.LeftBound < Two.RightBound && One.RightBound > Two.LeftBound &&
164 |                     One.TopBound > Two.BottomBound && One.BottomBound < Two.TopBound);
165 |         }
166 | 
167 |         public static bool operator &(Rectangle One, Point Two) => One.LeftBound <= Two.X && One.RightBound >= Two.X &&
168 |                                                                    One.TopBound >= Two.Y && One.BottomBound <= Two.Y;
169 | 
170 |         public static bool operator &(Point One, Rectangle Two) => Two & One;
171 |     }
172 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Seeds.cs:
--------------------------------------------------------------------------------
 1 | using System.Linq;
 2 | using static System.Math;
 3 | 
 4 | namespace LandSky.MyMath
 5 | {
 6 |     internal class Seeds
 7 |     {
 8 |         private const int STICK_FACTOR = 2;
 9 |         private const int DEMINISH_FACTOR = 10;
10 | 
11 |         public string Seed { get; private set; }
12 |         private Polinom3D Poly = new Polinom3D();
13 | 
14 |         public Seeds(string Seed)
15 |         {
16 |             this.Seed = Seed;
17 |             InitPolinom(Seed);
18 |         }
19 | 
20 |         public bool IsOver(int x, int y) => Poly.IsBiggerThanZero((x / STICK_FACTOR) * STICK_FACTOR, (y / STICK_FACTOR) * STICK_FACTOR);
21 | 
22 |         private void InitPolinom(string seed)
23 |         {
24 |             foreach (var c in seed.AsParallel())
25 |             {
26 |                 int num = c.GetHashCode() % 100000;
27 | 
28 |                 double ParamaterA = num * ((num % 2) == 0 ? -1 : 1) * Sin(Sqrt(num) * (((num) % 2) == 0 ? -1 : 1)) / DEMINISH_FACTOR;
29 |                 double ParamaterB = ((int)Sqrt(num) * ((num % 2) == 1 ? -1 : 1) * Sin(Sqrt(num) * (((num) % 2) == 1 ? -1 : 1))) / DEMINISH_FACTOR;
30 |                 Poly.Monoms.Add(new Monom3D(ParamaterA, ParamaterB));
31 |             }
32 |         }
33 |     }
34 | }


--------------------------------------------------------------------------------
/src/core.Portable/MyMath/Size.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.MyMath
 2 | {
 3 |     /// 
 4 |     /// Size class
 5 |     /// 
 6 |     public class Size
 7 |     {
 8 |         public int Height, Width;
 9 | 
10 |         public Size(int Width, int Height)
11 |         {
12 |             this.Height = Height;
13 |             this.Width = Width;
14 |         }
15 |     }
16 | }


--------------------------------------------------------------------------------
/src/core.Portable/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
 1 | using System.Reflection;
 2 | 
 3 | 
 4 | // General Information about an assembly is controlled through the following
 5 | // set of attributes. Change these attribute values to modify the information
 6 | // associated with an assembly.
 7 | [assembly: AssemblyTitle("core.Portable")]
 8 | [assembly: AssemblyDescription("")]
 9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("core.Portable")]
12 | [assembly: AssemblyCopyright("Copyright ©  2016")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 | 
16 | // Version information for an assembly consists of the following four values:
17 | //
18 | //      Major Version
19 | //      Minor Version
20 | //      Build Number
21 | //      Revision
22 | //
23 | // You can specify all the values or you can default the Build and Revision Numbers
24 | // by using the '*' as shown below:
25 | // [assembly: AssemblyVersion("1.0.*")]
26 | [assembly: AssemblyVersion("1.0.0.0")]
27 | [assembly: AssemblyFileVersion("1.0.0.0")]


--------------------------------------------------------------------------------
/src/core.Portable/Screen/ConnectToRemoteServerScreen.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.UIComponents;
 2 | 
 3 | namespace LandSky.Screen
 4 | {
 5 |     public class ConnectToRemoteServerScreen : BaseScreen
 6 |     {
 7 |         public ConnectToRemoteServerScreen() : base(0, 0, "Connect To Remote Server")
 8 |         {
 9 |             InitTextBoxes();
10 |             InputMode = MyEnums.InputMode.InputFirst;
11 |             ScreenChange();
12 |         }
13 | 
14 |         private void InitTextBoxes()
15 |         {
16 |             UIComponents.Add(new TextBox("test", 0, 2, 20));
17 |             UIComponents.Add(new TextBox("Ip", 0, 7, 7, "", ".:") { Hint = "Enter IP:PORT" });
18 |         }
19 |     }
20 | }


--------------------------------------------------------------------------------
/src/core.Portable/Screen/DebugScreen.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.Commands;
  2 | using LandSky.Components;
  3 | using LandSky.MyEnums;
  4 | using System;
  5 | using System.Collections.Generic;
  6 | using System.Linq;
  7 | 
  8 | namespace LandSky.Screen
  9 | {
 10 |     /// 
 11 |     /// This should show all debug info (not implemented yet)
 12 |     /// 
 13 |     public class DebugScreen : BaseScreen
 14 |     {
 15 |         public DebugScreen(int Top, int Left, BaseScreen ScreenToDebug) : base(Top,
 16 |                                                                                 Left,
 17 |                                                                                 $"Debugging {ScreenToDebug.Name} screen, it's type of {ScreenToDebug.GetType().ToString().Split(new char[] { '.' }).Last()}"
 18 |                                                                                )
 19 |         {
 20 |             MInitText(ScreenToDebug);
 21 |             ScreenChange();
 22 |         }
 23 | 
 24 |         private void MInitText(BaseScreen ScreenToDebug)
 25 |         {
 26 |             VirtualConsoleAddLine($"Contains {ScreenToDebug.NumOfRooms} rooms, {ScreenToDebug.NumOfPaths} paths, {ScreenToDebug.NumOfWalls} walls");
 27 |             PrintControls(ScreenToDebug as Component, 1);
 28 |             VirtualConsoleAddLine($"Able to input {ScreenToDebug.Comand.Count} different commands");
 29 |             MPrintCommands(ScreenToDebug.Comand, 1);
 30 |         }
 31 | 
 32 |         private void MPrintCommands(Dictionary> MCommands, int Indent)
 33 |         {
 34 |             var Km = CommandControls.KeyMap;
 35 |             foreach (var Command in MCommands)
 36 |             {
 37 |                 VirtualConsoleAddLine(
 38 |                     $"{new string(' ', Indent * 2)}{Km.Where(I => I.Value == Command.Key).ToList()?[0].Key.KeyChar} -> {Command.Key} -> {Command.Value.Target.GetType().Name}");
 39 |             }
 40 |         }
 41 | 
 42 |         private void PrintControls(Component ScreenToDebug, int Indent)
 43 |         {
 44 |             if (ScreenToDebug.NumOfRooms > 0)
 45 |             {
 46 |                 MPrintRooms(ScreenToDebug.Controls.Where(I => I.Value.GetType() == typeof(Room)).ToList(), Indent);
 47 |             }
 48 |             if (ScreenToDebug.NumOfPaths > 0)
 49 |             {
 50 |                 MPrintPaths(ScreenToDebug.Controls.Where(I => I.Value.GetType() == typeof(Path)).ToList(), Indent);
 51 |             }
 52 |             if (ScreenToDebug.NumOfWalls > 0)
 53 |             {
 54 |                 MPrintWalls(ScreenToDebug.Controls.Where(I => I.Value.GetType() == typeof(Wall)).ToList(), Indent);
 55 |             }
 56 |         }
 57 | 
 58 |         private void MPrintWalls(IEnumerable> MWalls, int Indent)
 59 |         {
 60 |             foreach (var Wall in MWalls)
 61 |             {
 62 |                 VirtualConsoleAddLine(string.Format("{0}Wall {1} is localy located on ({2},{3}) and globaly on ({4},{5}), width = {6}, height = {7}", new object[] { new string(' ', Indent * 2), Wall.Value.Name, Wall.Value.LocalX, Wall.Value.LocalY, Wall.Value.GlobalX, Wall.Value.GlobalY, Wall.Value.Width, Wall.Value.Height }));
 63 |                 if (Wall.Value.Controls.Count > 0)
 64 |                     VirtualConsoleAddLine(
 65 |                         $"{new string(' ', Indent * 2)}Wall contains {Wall.Value.NumOfRooms} Rooms, {Wall.Value.NumOfPaths} Paths, {Wall.Value.NumOfWalls} walls");
 66 |                 PrintControls(Wall.Value, Indent + 1);
 67 |             }
 68 |         }
 69 | 
 70 |         private void MPrintPaths(IEnumerable> MPaths, int Indent)
 71 |         {
 72 |             foreach (var Path in MPaths)
 73 |             {
 74 |                 VirtualConsoleAddLine(
 75 |                     $"{new string(' ', Indent * 2)}Path {Path.Value.Name} is polynomial of {(Path.Value as Path).ConnectedComponent.Count}th power");
 76 |                 if (Path.Value.Controls.Count > 0)
 77 |                     VirtualConsoleAddLine(
 78 |                         $"{new string(' ', Indent * 2)}Room contains {Path.Value.NumOfRooms} Rooms, {Path.Value.NumOfPaths} Paths, {Path.Value.NumOfWalls} walls");
 79 |                 if ((Path.Value as Path).ConnectedComponent.Count > 0)
 80 |                 {
 81 |                     MPrintRooms((Path.Value as Path).ConnectedComponent.Where(I => I.GetType() == typeof(Room)).ToList(), Indent + 1);
 82 |                 }
 83 |                 PrintControls(Path.Value, Indent + 1);
 84 |             }
 85 |         }
 86 | 
 87 |         private void MPrintRooms(IEnumerable MRooms, int Indent)
 88 |         {
 89 |             foreach (var Room in MRooms)
 90 |             {
 91 |                 VirtualConsoleAddLine(
 92 |                     $"{new string(' ', Indent * 2)}Room {Room.Name} is located on ({Room.LocalX},{Room.LocalY}), width = {Room.Width}, height = {Room.Height}");
 93 |                 if (Room.Controls.Count > 0)
 94 |                     VirtualConsoleAddLine(
 95 |                         $"{new string(' ', Indent * 2)}Room contains {Room.NumOfRooms} Rooms, {Room.NumOfPaths} Paths, {Room.NumOfWalls} walls");
 96 |                 if (Room.NumOfRooms > 0)
 97 |                 {
 98 |                     MPrintRooms(Room.Controls.Where(I => I.Value.GetType() == typeof(Room)).ToList(), Indent + 1);
 99 |                 }
100 |                 PrintControls(Room, Indent + 1);
101 |             }
102 |         }
103 | 
104 |         private void MPrintRooms(IEnumerable> MRooms, int Indent)
105 |         {
106 |             foreach (var Room in MRooms)
107 |             {
108 |                 VirtualConsoleAddLine(
109 |                     $"{new string(' ', Indent * 2)}Room {Room.Value.Name} is located on ({Room.Value.LocalX},{Room.Value.LocalY}), width = {Room.Value.Width}, height = {Room.Value.Height}");
110 |                 if (Room.Value.Controls.Count > 0)
111 |                     VirtualConsoleAddLine(
112 |                         $"{new string(' ', Indent * 2)}Room contains {Room.Value.NumOfRooms} Rooms, {Room.Value.NumOfPaths} Paths, {Room.Value.NumOfWalls} walls");
113 |                 PrintControls(Room.Value, Indent + 1);
114 |             }
115 |         }
116 |     }
117 | }


--------------------------------------------------------------------------------
/src/core.Portable/Screen/HelpScreen.cs:
--------------------------------------------------------------------------------
 1 | namespace LandSky.Screen
 2 | {
 3 |     /// 
 4 |     /// Help screen (need to be implemented)
 5 |     /// 
 6 |     public class HelpScreen : BaseScreen
 7 |     {
 8 |         public HelpScreen(int Top, int Left) : base(Top, Left, "Help")
 9 |         {
10 |             InitText();
11 |             ScreenChange();
12 |         }
13 | 
14 |         private void InitText()
15 |         {
16 |             PrintCenter("This is Land sky");
17 |             PrintLine();
18 |             PrintCenter("Rouge like multiplayer game");
19 |             PrintLine();
20 |             PrintCenter("Use h/j/k/l to move left/down/up/right");
21 |             PrintCenter("Press ESC to get to the last screen");
22 |             PrintCenter("Press 1-9 to chose option 1-9");
23 |             PrintCenter("This is still in early stages so there isn't a lot of gameplay");
24 |         }
25 |     }
26 | }


--------------------------------------------------------------------------------
/src/core.Portable/Screen/MainMenuScreen.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.MyEnums;
 2 | using LandSky.UIComponents;
 3 | using System;
 4 | 
 5 | namespace LandSky.Screen
 6 | {
 7 |     /// 
 8 |     /// Screen showing all the options. Extends BaseScreen
 9 |     /// 
10 |     public class MainMenuScreen : BaseScreen
11 |     {
12 |         /// 
13 |         /// Create new Main Menu Screen
14 |         /// 
15 |         /// Distance from the top of the global console
16 |         /// Distance form the left of the global console
17 |         public MainMenuScreen(int Top, int Left) : base(Top, Left, "Main menu")
18 |         {
19 |             InitButtons();
20 |             InitComands();
21 |             InputMode = InputMode.ControlFirst;
22 |             ScreenChange();
23 |         }
24 | 
25 |         private void InitButtons()
26 |         {
27 |             Button StartLocalGame = new Button("StartLocal", "Start new local game", 0, 0, 0, Comands.Option1);
28 |             Button ConnectToRemoteServer = new Button("ConnectToRemoteServer", "Connect to remote server", 0, 1, 0, Comands.Option2);
29 |             Button Exit = new Button("Exit", "Exit game", 0, 2, 0, Comands.Option3);
30 |             StartLocalGame.OnAccept += StartLocalOnPress;
31 |             ConnectToRemoteServer.OnAccept += ConnectToRemoteServerOnPress;
32 |             Exit.OnAccept += ExitOnPress;
33 | 
34 |             UIComponents.AddRange(new UIComponentBase[] { StartLocalGame, ConnectToRemoteServer, Exit });
35 |         }
36 | 
37 |         private void InitComands()
38 |         {
39 |             foreach (var B in UIComponents)
40 |             {
41 |                 MLocalCommands.Add((B as Button).InvokeCommand, B.InvokeAccept);
42 |             }
43 |             this.Resume();
44 |         }
45 | 
46 |         private void ConnectToRemoteServerOnPress(object sender, DateTime e)
47 |         {
48 |             this.Pause();
49 |             Active.Push(new ConnectToRemoteServerScreen());
50 |         }
51 | 
52 |         private void ExitOnPress(object Sender, DateTime E)
53 |         {
54 |             this.Pause();
55 |             Active.Pop();
56 |             base.OnExit();
57 |         }
58 | 
59 |         /// 
60 |         /// Start new instance of the game
61 |         /// 
62 |         private void StartLocalOnPress(object Sender, DateTime E)
63 |         {
64 |             this.Pause();
65 |             Active.Push(new SandboxMap(GlobalTop, GlobalLeft));
66 |         }
67 |     }
68 | }


--------------------------------------------------------------------------------
/src/core.Portable/Screen/SandboxMapScreen.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.Commands;
  2 | using LandSky.Components;
  3 | using LandSky.MyEnums;
  4 | using LandSky.MyMath;
  5 | using System;
  6 | using System.Collections.Generic;
  7 | using System.Linq;
  8 | using System.Threading.Tasks;
  9 | using static System.Math;
 10 | 
 11 | namespace LandSky.Screen
 12 | {
 13 |     /// 
 14 |     ///     Displays the instance of the game. This Extends BaseScreen.
 15 |     /// 
 16 |     public class SandboxMap : BaseScreen
 17 |     {
 18 |         /// 
 19 |         ///     Current state of the game instance
 20 |         /// 
 21 |         private List> mBuff1;
 22 | 
 23 |         private bool mGhost;
 24 |         private readonly object mLockDrawMethode = new object();
 25 | 
 26 |         /// 
 27 |         ///     The bounds in the Cartesian coordinate system
 28 |         /// 
 29 |         private Rectangle mMBoundsAroundThisPlayer;
 30 | 
 31 |         private int mSpeed;
 32 | 
 33 |         /// 
 34 |         ///     Textures for the materials
 35 |         /// 
 36 |         private Dictionary mTexture;
 37 | 
 38 |         /// 
 39 |         ///     Matrix for zbuffering
 40 |         /// 
 41 |         private List> mUpdated;
 42 | 
 43 |         /// 
 44 |         ///     Create new Engine Screen
 45 |         /// 
 46 |         /// Distance from the top of the global console
 47 |         /// Distance form the left of the global console
 48 |         public SandboxMap(int Top, int Left) : base(Top, Left, "Land sky")
 49 |         {
 50 |             InitProperties();
 51 |             InitBuffer();
 52 |             InitTexture();
 53 |             InitEvents();
 54 |             InitControls();
 55 |             //EngineConsoleDraw();
 56 |         }
 57 | 
 58 |         public Rectangle BoundsAroundThisPlayer
 59 |         {
 60 |             get
 61 |             {
 62 |                 if (ActiveComponent.IsRoot != true)
 63 |                     return new Rectangle(new Point(ActiveComponent.LocalX, ActiveComponent.LocalY), WantedWidth - 1, WantedHeight - 1);
 64 |                 return new Rectangle(new Point(0, 0), WantedWidth, WantedHeight);
 65 |             }
 66 |         }
 67 | 
 68 |         public event EventHandler Message;
 69 | 
 70 |         private void InitBuffer()
 71 |         {
 72 |             mBuff1 = new List>(TrueHeight + 1);
 73 |             for (var J = 0; J <= TrueHeight; J++)
 74 |             {
 75 |                 mBuff1.Add(new List(TrueWidth + 1));
 76 |                 mBuff1[J] = new List(TrueWidth + 1);
 77 |                 if (J == 0)
 78 |                 {
 79 |                     for (var I = 0; I <= TrueWidth; I++)
 80 |                     {
 81 |                         mBuff1[J].Add(new char());
 82 |                     }
 83 |                 }
 84 |                 else
 85 |                     mBuff1[J].AddRange(mBuff1[0]);
 86 |             }
 87 |             mUpdated = new List>();
 88 | 
 89 |             for (var I = 0; I <= TrueHeight; I++)
 90 |             {
 91 |                 mUpdated.Add(new List(TrueWidth + 1));
 92 |                 if (I == 0)
 93 |                 {
 94 |                     for (var J = 0; J < TrueWidth + 1; J++)
 95 |                     {
 96 |                         mUpdated[I].Add(-1);
 97 |                     }
 98 |                 }
 99 |                 else
100 |                 {
101 |                     mUpdated[I].AddRange(mUpdated[0]);
102 |                 }
103 |             }
104 |         }
105 | 
106 |         private void ResetBuffers()
107 |         {
108 |             mUpdated = mUpdated.Select(UpLine => UpLine
109 |                 .Select(UpChar => -1)
110 |                 .ToList())
111 |                 .ToList();
112 | 
113 |             mBuff1 = mBuff1.Select(BuffLine => BuffLine
114 |                 .Select(BuffChar => BuffChar == ' ' ? BuffChar : ' ')
115 |                 .ToList())
116 |                 .ToList();
117 |         }
118 | 
119 |         private void InitTexture()
120 |         {
121 |             mTexture = new Dictionary();
122 |             mTexture.Add(Material.Air, '.');
123 |             mTexture.Add(Material.Fire, '~');
124 |             mTexture.Add(Material.Loot, '$');
125 |             mTexture.Add(Material.Npc, 'N');
126 |             mTexture.Add(Material.Path, '#');
127 |             mTexture.Add(Material.Player, '@');
128 |             mTexture.Add(Material.Trap, '.');
129 |             mTexture.Add(Material.HorisontalWall, '-');
130 |             mTexture.Add(Material.VerticalWall, '|');
131 |             mTexture.Add(Material.Water, '}');
132 |             mTexture.Add(Material.Darknes, ' ');
133 |         }
134 | 
135 |         private void InitControls()
136 |         {
137 |             MLocalCommands.Add(Comands.Left, GeneralMove);
138 |             MLocalCommands.Add(Comands.TenStepsLeft, GeneralMove);
139 |             MLocalCommands.Add(Comands.Right, GeneralMove);
140 |             MLocalCommands.Add(Comands.TenStepsRight, GeneralMove);
141 |             MLocalCommands.Add(Comands.Up, GeneralMove);
142 |             MLocalCommands.Add(Comands.TenStepsUp, GeneralMove);
143 |             MLocalCommands.Add(Comands.Down, GeneralMove);
144 |             MLocalCommands.Add(Comands.TenStepsDown, GeneralMove);
145 |             MLocalCommands.Add(Comands.GenerateALotOfRooms, GenerateRooms);
146 |             MLocalCommands.Add(Comands.GenerateOneRoom, GenerateRooms);
147 |             MLocalCommands.Add(Comands.GenerateRandomPath, GeneratePath);
148 |             foreach (var Comm in MLocalCommands)
149 |             {
150 |                 Comand.Add(Comm.Key, Comm.Value);
151 |             }
152 |         }
153 | 
154 |         private void InitProperties()
155 |         {
156 |             WantedWidth = 50;
157 |             WantedHeight = 20;
158 |             ActiveComponent = this;
159 |             //Insert(_ActiveComponent);
160 |             mBuff1 = new List>();
161 |             mUpdated = new List>();
162 |             MLocalCommands = new Dictionary>();
163 |             MadeOf = Material.Darknes;
164 |             mGhost = true;
165 |             mSpeed = 50; // steep = 1/speed
166 |             IsRoot = true;
167 |         }
168 | 
169 |         private void InitEvents()
170 |         {
171 |         }
172 | 
173 |         public void MyDispose()
174 |         {
175 |             foreach (var Comm in MLocalCommands)
176 |             {
177 |                 Comand.Remove(Comm.Key);
178 |             }
179 |         }
180 | 
181 |         private object GenerateRoomsLock = new object();
182 | 
183 |         /// 
184 |         ///     Generate new rooms in this instance of the game
185 |         /// 
186 |         /// This should be typeof(GenerateRoomsCommand) 
187 |         public void GenerateRooms(BaseCommand Bc)
188 |         {
189 |             lock (GenerateRoomsLock)
190 |             {
191 |                 var GRc = Bc as GenerateRoomsCommand;
192 |                 Task.Run(async () =>
193 |                 {
194 |                     var StartTime = DateTime.Now;
195 |                     await GenerateRandomRooms((Bc as GenerateRoomsCommand).NumberOfRooms);
196 | 
197 |                     EnqueMessage(string.Format("Generated {0} rooms in {0}s\n", (Bc as GenerateRoomsCommand).NumberOfRooms,
198 |                         DateTime.Now.Second - StartTime.Second));
199 |                     EngineConsoleDraw();
200 |                 }, GenerateRoomsCommand.CancelGenerting);
201 |             }
202 |         }
203 | 
204 |         /// 
205 |         ///     Generate new paths in this instance of the game
206 |         /// 
207 |         /// This should be typeof(GeneratePathCommand) 
208 |         public async void GeneratePath(BaseCommand Bc)
209 |         {
210 |             if (NumOfRooms < 10)
211 |                 await Task.Run(() => { GenerateRooms(new GenerateRoomsCommand(100)); });
212 |             for (var I = 0; I < (Bc as GeneratePathCommand).NumberOfPaths; I++)
213 |             {
214 |                 var P = new Path("Path" + NumOfPaths);
215 |                 P.GeneratePathThrueRandomChildren(this);
216 |                 Insert(P);
217 |             }
218 |             EngineConsoleDraw();
219 |         }
220 | 
221 |         /// 
222 |         ///     Move played in current game instance
223 |         /// 
224 |         /// this should be typeof(MoveCommand) 
225 |         private void GeneralMove(BaseCommand Bc)
226 |         {
227 |             var Move = Bc as MoveCommand;
228 |             MoveCommand.InitToken();
229 |             var T = Task.Run(async () =>
230 |             {
231 |                 int Steps = Move.Steps;
232 |                 while (Steps > 0)
233 |                 {
234 |                     if (Move.Direction == MoveDirection.Down || Move.Direction == MoveDirection.DownLeft ||
235 |                         Move.Direction == MoveDirection.DownRight)
236 |                     {
237 |                         if (GetComponentOnLocation(ActiveComponent.LocalX, ActiveComponent.LocalY - 1).IsPassable || mGhost)
238 |                         {
239 |                             ActiveComponent.LocalY--;
240 |                             Steps--;
241 |                         }
242 |                     }
243 |                     if (Move.Direction == MoveDirection.Up || Move.Direction == MoveDirection.UpLeft ||
244 |                         Move.Direction == MoveDirection.UpRight)
245 |                     {
246 |                         if (GetComponentOnLocation(ActiveComponent.LocalX, ActiveComponent.LocalY + 1).IsPassable || mGhost)
247 |                         {
248 |                             ActiveComponent.LocalY++;
249 |                             Steps--;
250 |                         }
251 |                     }
252 |                     if (Move.Direction == MoveDirection.Left || Move.Direction == MoveDirection.UpLeft ||
253 |                         Move.Direction == MoveDirection.DownLeft)
254 |                     {
255 |                         if (GetComponentOnLocation(ActiveComponent.LocalX + 1, ActiveComponent.LocalY).IsPassable || mGhost)
256 |                         {
257 |                             ActiveComponent.LocalX--;
258 |                             Steps--;
259 |                         }
260 |                     }
261 |                     if (Move.Direction == MoveDirection.Right || Move.Direction == MoveDirection.UpRight ||
262 |                         Move.Direction == MoveDirection.DownRight)
263 |                     {
264 |                         if (GetComponentOnLocation(ActiveComponent.LocalX - 1, ActiveComponent.LocalY).IsPassable || mGhost)
265 |                         {
266 |                             ActiveComponent.LocalX++;
267 |                             Steps--;
268 |                         }
269 |                     }
270 |                     EngineConsoleDraw();
271 |                     await Task.Delay(mSpeed);
272 |                 }
273 |             }, MoveCommand.CancleMove);
274 |         }
275 | 
276 |         protected override void GenerateFooter()
277 |         {
278 |             try
279 |             {
280 |                 string Mid = $"({ActiveComponent.LocalX},{ActiveComponent.LocalY}) - {GetComponentOnLocation(ActiveComponent.LocalX, ActiveComponent.LocalY).Name}";
281 |                 GenerateFooter(Mid);
282 |             }
283 |             catch
284 |             {
285 |                 base.GenerateFooter();
286 |             }
287 |         }
288 | 
289 |         private object LockChangeActiveComponent = new object();
290 | 
291 |         public void ChangeActiveComponent(string NewActiveComponent, int NewWidth, int NewHeight)
292 |         {
293 |             lock (LockChangeActiveComponent)
294 |             {
295 |                 ActiveComponent = this.Controls.First(i => i.Value.Name == NewActiveComponent).Value;
296 |                 WantedWidth = NewWidth;
297 |                 WantedHeight = NewHeight;
298 |                 //EngineConsoleDraw();
299 |             }
300 |         }
301 | 
302 |         public string ReginToString()
303 |         {
304 |             return ReginToString(ActiveComponent, WantedWidth, WantedHeight);
305 |         }
306 | 
307 |         public Cell[][] GetRegin()
308 |         {
309 |             return GetRegin(BoundsAroundThisPlayer);
310 |         }
311 |         private void EngineConsoleDraw()
312 |         {
313 |             lock (mLockDrawMethode)
314 |             {
315 |                 //ResetBuffers();
316 |                 InitBuffer();
317 |                 ZBufferUpdate(this);
318 |                 FillBuffer(BoundsAroundThisPlayer, MadeOf, 0);
319 |                 FlushBuffer();
320 |                 ScreenChange();
321 |             }
322 |         }
323 | 
324 |         private void ZBufferUpdate(Component Comp)
325 |         {
326 |             //var GoodComponents = Comp.Controls.Where(I => I.Value.GetType() != typeof(Path) &&
327 |             //                                              I.Value.GlobalBounds & BoundsAroundThisPlayer);
328 |             //foreach (var GoodComponent in GoodComponents)
329 |             //{
330 |             //    ZBufferUpdate(GoodComponent.Value);
331 |             //}
332 |             //FillBuffer(Comp.GlobalBounds, Comp.MadeOf, Comp.ZValue);
333 |             //DrawPaths(Comp);
334 |         }
335 | 
336 |         private void FillBuffer(Rectangle TransformdBounds, Material madeOf, int ZLevel)
337 |         {
338 |             var Transformed = BoundsAroundThisPlayer.ToTopLeft(TransformdBounds);
339 |             for (int I = Min(Transformed.TopBound, Transformed.BottomBound); I <= Max(Transformed.TopBound, Transformed.BottomBound); I++)
340 |             {
341 |                 for (int J = Transformed.LeftBound; J <= Transformed.RightBound; J++)
342 |                 {
343 |                     if (mUpdated[I][J] < ZLevel)
344 |                     {
345 |                         mBuff1[I][J] = mTexture[madeOf];
346 |                         mUpdated[I][J] = ZLevel;
347 |                     }
348 |                 }
349 |             }
350 |         }
351 | 
352 |         private void FlushBuffer()
353 |         {
354 |             Clear();
355 |             foreach (var C in mBuff1)
356 |                 VirtualConsoleAddLine(new string(C.ToArray()));
357 |         }
358 | 
359 |         private void DrawPaths(Component ComponentsWithPaths)
360 |         {
361 |             foreach (var path in ComponentsWithPaths.Controls.Where(I => I.Value.GetType() == typeof(Path)))
362 |             {
363 |                 var Component = path.Value as Path;
364 | 
365 |                 var Pol = Component.Poly;
366 | 
367 |                 for (int J = BoundsAroundThisPlayer.LeftBound; J < BoundsAroundThisPlayer.RightBound; J++)
368 |                 {
369 |                     var TransformdBounds = new Rectangle(
370 |                         new Point(J, Pol.IntValueForX(J)),
371 |                         1,
372 |                         Abs(Pol.IntDerivativeForX(J) * 2) + 4);
373 |                     if (TransformdBounds & BoundsAroundThisPlayer)
374 |                         FillBuffer(TransformdBounds,
375 |                                     path.Value.MadeOf,
376 |                                     path.Value.ZValue);
377 |                 }
378 |             }
379 |         }
380 |     }
381 | }


--------------------------------------------------------------------------------
/src/core.Portable/UIComponents/Button.cs:
--------------------------------------------------------------------------------
 1 | using LandSky.DotNetExt;
 2 | using LandSky.MyEnums;
 3 | 
 4 | namespace LandSky.UIComponents
 5 | {
 6 |     /// 
 7 |     /// Ui element button
 8 |     /// 
 9 |     internal class Button : UIComponentBase
10 |     {
11 |         public Comands InvokeCommand;
12 | 
13 |         public Button(string Name, string Text, int TabIndex, int Top, int Left, Comands Comm) : base(Name, TabIndex, Top, Left, Text)
14 |         {
15 |             InvokeCommand = Comm;
16 |         }
17 | 
18 |         public Button(string Name, string Text, Comands Comm) : base(Name, 0, 0, 0, Text)
19 |         {
20 |             InvokeCommand = Comm;
21 |         }
22 | 
23 |         public override string ToString()
24 |         {
25 |             if (Focus == true)
26 |                 return $"->{InvokeCommand.ToString().Replace("Option", string.Empty)}. {Text}";
27 |             else
28 |                 return $"{InvokeCommand.ToString().Replace("Option", string.Empty)}. {Text}";
29 |         }
30 | 
31 |         public override bool NewInput(MyConsoleKeyInfo c)
32 |         {
33 |             return base.NewInput(c);
34 |         }
35 |     }
36 | }


--------------------------------------------------------------------------------
/src/core.Portable/UIComponents/TextBox.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.DotNetExt;
  2 | using LandSky.MyEnums;
  3 | using System.Collections.Generic;
  4 | using System.Linq;
  5 | using static System.Math;
  6 | 
  7 | namespace LandSky.UIComponents
  8 | {
  9 |     internal class TextBox : UIComponentBase
 10 |     {
 11 |         private List mAcceptedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".ToCharArray().ToList();
 12 |         private int mCursorLeft;
 13 |         private int mCursorTop;
 14 | 
 15 |         public TextBox(string Name, int TabIndex, int Top, int Left) : base(Name, TabIndex, Top, Left)
 16 |         {
 17 |         }
 18 | 
 19 |         public TextBox(string Name, int TabIndex, int Top, int Left, string InitText) : base(Name, TabIndex, Top, Left, InitText)
 20 |         {
 21 |             this.mCursorLeft = Text.Split(new char[] { '\n' }).Last().Length;
 22 |             this.mCursorTop = this.Size.Height;
 23 |         }
 24 | 
 25 |         public TextBox(string Name, int TabIndex, int Top, int Left, string InitText, string AditionalSpecialCharacters) : base(Name, TabIndex, Top, Left, InitText)
 26 |         {
 27 |             this.mCursorLeft = InitText.Length;
 28 |             mAcceptedCharacters.AddRange(AditionalSpecialCharacters.ToCharArray());
 29 |         }
 30 | 
 31 |         public override bool NewInput(MyConsoleKeyInfo KeyInfo)
 32 |         {
 33 |             if (mAcceptedCharacters.Any(i => i == KeyInfo.KeyChar))
 34 |             {
 35 |                 InsertCharInText(mCursorTop, mCursorLeft, KeyInfo.KeyChar);
 36 | 
 37 |                 return true;
 38 |             }
 39 |             else
 40 |             {
 41 |                 switch (KeyInfo.KeyChar)
 42 |                 {
 43 |                     case (char)SpecialAsciiKeys.Backspace:
 44 |                         RemoveCharFormText(1);
 45 |                         return true;
 46 | 
 47 |                     case (char)SpecialAsciiKeys.Del:
 48 |                         RemoveCharFormText(-1);
 49 |                         return true;
 50 | 
 51 |                     case (char)SpecialAsciiKeys.ArrowUp:
 52 |                         MoveCursureVertical(1);
 53 |                         return true;
 54 | 
 55 |                     case (char)SpecialAsciiKeys.ArrowDown:
 56 |                         MoveCursureVertical(-1);
 57 |                         return true;
 58 | 
 59 |                     case (char)SpecialAsciiKeys.ArrowRight:
 60 |                         MoveCursureHorisontal(1);
 61 |                         return true;
 62 | 
 63 |                     case (char)SpecialAsciiKeys.ArrowLeft:
 64 |                         MoveCursureHorisontal(-1);
 65 |                         return true;
 66 |                 }
 67 |             }
 68 |             return base.NewInput(KeyInfo);
 69 |         }
 70 | 
 71 |         private void MoveCursureHorisontal(int v)
 72 |         {
 73 |             mCursorLeft = Max(0, Min(mCursorLeft + v, mLinesOfText[mCursorTop].Length));
 74 |         }
 75 | 
 76 |         private void MoveCursureVertical(int v)
 77 |         {
 78 |             mCursorTop = Max(0, Min(mLinesOfText.Count - 1, mCursorTop + v));
 79 |             mCursorLeft = Min(mCursorLeft, mLinesOfText[mCursorTop].Length - 1);
 80 |         }
 81 | 
 82 |         private void RemoveCharFormText(int v)
 83 |         {
 84 |             string aLine = mLinesOfText[mCursorTop];
 85 |             int pointA = Min(aLine.Length, Max(0, mCursorLeft - v));
 86 |             int pointB = Min(aLine.Length, Max(0, mCursorLeft));
 87 |             mLinesOfText[mCursorTop] = $"{aLine.Substring(0, Min(pointA, pointB))}{aLine.Substring(Max(pointA, pointB))}";
 88 |             mCursorLeft -= v;
 89 |             LinesUpdated();
 90 |         }
 91 | 
 92 |         private void InsertCharInText(int top, int left, char c)
 93 |         {
 94 |             string OutText = string.Empty;
 95 |             string before = mLinesOfText[mCursorTop].Substring(0, mCursorLeft);
 96 |             string after = mLinesOfText[mCursorTop].Substring(mCursorLeft);
 97 |             mLinesOfText[mCursorTop] = $"{before}{c}{after}";
 98 |             mCursorLeft++;
 99 |             LinesUpdated();
100 |         }
101 | 
102 |         public override string ToString()
103 |         {
104 |             List Lines = new List();
105 |             if (mLinesOfText.Count > 0 && mLinesOfText[0].Length > 0)
106 |             {
107 |                 foreach (var line in mLinesOfText)
108 |                 {
109 |                     Lines.Add(line);
110 |                 }
111 |             }
112 |             else
113 |             {
114 |                 Lines.Add(Hint);
115 |             }
116 |             string aLine = Lines[mCursorTop];
117 |             Lines[mCursorTop] = $"{aLine.Substring(0, mCursorLeft)}|{aLine.Substring(mCursorLeft)}";
118 |             int MaxWitdth = SizeMode == SizeMode.Auto ? Lines.Max(i => i.Length) : this.mSize.Width;
119 |             string OutString = Focus ? ("-" + new string('+', MaxWitdth) + "-\n") : ("+" + new string('-', MaxWitdth) + "+\n");
120 | 
121 |             foreach (var Line in Lines)
122 |             {
123 |                 OutString += $"|{Line}{new string(' ', Max(0, MaxWitdth - Line.Length))}|".Substring(0, SizeMode == SizeMode.Auto ? Line.Length + 2 : Min(Line.Length + 2, mSize.Width)) + '\n';
124 |             }
125 |             if (!Lines.Any())
126 |                 OutString += $"|{Hint}{new string(' ', Max(0, MaxWitdth - Hint.Length))}|";
127 | 
128 |             if (SizeMode == SizeMode.Explicit)
129 |             {
130 |                 int currentLine = 0;
131 |                 OutString = new string(OutString.ToCharArray().Select(i =>
132 |                 {
133 |                     if (i == '\n')
134 |                         currentLine++;
135 |                     return currentLine + 2 < this.mSize.Height ? i : '\0';
136 |                 }).ToArray());
137 |             }
138 |             OutString += Focus ? ("-" + new string('+', MaxWitdth) + "-") : ("+" + new string('-', MaxWitdth) + "+");
139 |             return OutString;
140 |         }
141 |     }
142 | }


--------------------------------------------------------------------------------
/src/core.Portable/UIComponents/UIComponentBase.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.Commands;
  2 | using LandSky.DotNetExt;
  3 | using LandSky.MyEnums;
  4 | using LandSky.MyMath;
  5 | using System;
  6 | using System.Collections.Generic;
  7 | using System.Linq;
  8 | 
  9 | namespace LandSky.UIComponents
 10 | {
 11 |     public abstract class UIComponentBase
 12 |     {
 13 |         public int Top
 14 |         {
 15 |             get
 16 |             {
 17 |                 return mTop;
 18 |             }
 19 |             set
 20 |             {
 21 |                 mTop = value;
 22 |                 OnMove?.Invoke(this, DateTime.Now);
 23 |             }
 24 |         }
 25 | 
 26 |         public int Left
 27 |         {
 28 |             get
 29 |             {
 30 |                 return mLeft;
 31 |             }
 32 |             set
 33 |             {
 34 |                 mLeft = value;
 35 |                 OnMove?.Invoke(this, DateTime.Now);
 36 |             }
 37 |         }
 38 | 
 39 |         public Size Size
 40 |         {
 41 |             get
 42 |             {
 43 |                 int MaxLenght = mLinesOfText.Max(i => i.Length);
 44 |                 return SizeMode == SizeMode.Auto ? new Size(MaxLenght, mLinesOfText.Count) : mSize;
 45 |             }
 46 |             set
 47 |             {
 48 |                 SizeMode = SizeMode.Explicit;
 49 |                 mSize = value;
 50 |                 OnSizeChanged?.Invoke(this, DateTime.Now);
 51 |             }
 52 |         }
 53 | 
 54 |         public string Name { get; set; }
 55 | 
 56 |         public string Text
 57 |         {
 58 |             get
 59 |             {
 60 |                 return mText;
 61 |             }
 62 |             set
 63 |             {
 64 |                 mText = value;
 65 |                 OnTextChanged?.Invoke(this, DateTime.Now);
 66 |             }
 67 |         }
 68 | 
 69 |         public int TabIndex { get; set; } = 0;
 70 |         public bool Focus { get; set; } = false;
 71 |         public string Hint { get; set; } = "Hint not set";
 72 |         public SizeMode SizeMode { get; set; } = SizeMode.Auto;
 73 |         public Rectangle Bounds => new Rectangle(Top, Left + Size.Width, Top + Size.Height, Left);
 74 | 
 75 |         public event EventHandler OnFocusGained;
 76 | 
 77 |         public event EventHandler OnFocusLost;
 78 | 
 79 |         public event EventHandler OnAccept;
 80 | 
 81 |         public event EventHandler OnMove;
 82 | 
 83 |         public event EventHandler OnTextChanged;
 84 | 
 85 |         public event EventHandler OnStart;
 86 | 
 87 |         public event EventHandler OnSizeChanged;
 88 | 
 89 |         public event EventHandler OnTab;
 90 | 
 91 |         private int mTop = 0;
 92 |         private int mLeft = 0;
 93 |         private bool mForcus = false;
 94 | 
 95 |         protected Size mSize;
 96 |         protected List mLinesOfText = new List() { string.Empty };
 97 |         protected string mText = "";
 98 | 
 99 |         protected UIComponentBase(string Name)
100 |         {
101 |             this.Name = Name;
102 |             OnStart?.Invoke(this, DateTime.Now);
103 |         }
104 | 
105 |         protected UIComponentBase(string Name, int TabIndex)
106 |         {
107 |             this.Name = Name;
108 |             this.TabIndex = TabIndex;
109 |             OnStart?.Invoke(this, DateTime.Now);
110 |         }
111 | 
112 |         protected UIComponentBase(string Name, int TabIndex, int Top, int Left)
113 |         {
114 |             this.Name = Name;
115 |             this.Top = Top;
116 |             this.Left = Left;
117 |             this.TabIndex = TabIndex;
118 |             OnStart?.Invoke(this, DateTime.Now);
119 |         }
120 | 
121 |         protected UIComponentBase(string Name, int TabIndex, int Top, int Left, string InitText)
122 |         {
123 |             this.Name = Name;
124 |             this.Top = Top;
125 |             this.Left = Left;
126 |             this.Text = InitText;
127 |             this.TabIndex = TabIndex;
128 |             OnStart?.Invoke(this, DateTime.Now);
129 |         }
130 | 
131 |         protected void LinesUpdated()
132 |         {
133 |             mText = string.Empty;
134 |             foreach (var Line in mLinesOfText)
135 |             {
136 |                 mText += Line + '\n';
137 |             }
138 |         }
139 | 
140 |         public virtual bool NewInput(MyConsoleKeyInfo KeyInfo)
141 |         {
142 |             switch (KeyInfo.KeyChar)
143 |             {
144 |                 case (char)SpecialAsciiKeys.Tab:
145 |                     OnTab?.Invoke(this, DateTime.Now);
146 |                     return true;
147 | 
148 |                 case '\n':
149 |                     OnAccept?.Invoke(this, DateTime.Now);
150 |                     return true;
151 |             }
152 |             return false;
153 |         }
154 | 
155 |         public void InvokeAccept(BaseCommand BaseCommand)
156 |         {
157 |             OnAccept?.Invoke(this, DateTime.Now);
158 |         }
159 |     }
160 | }


--------------------------------------------------------------------------------
/src/core.Portable/UIComponents/UIComponentsCollection.cs:
--------------------------------------------------------------------------------
  1 | using LandSky.DotNetExt;
  2 | using System;
  3 | using System.Collections;
  4 | using System.Collections.Generic;
  5 | using System.Linq;
  6 | 
  7 | namespace LandSky.UIComponents
  8 | {
  9 |     public class UIComponentsCollection : IList
 10 |     {
 11 |         public int Count
 12 |         {
 13 |             get
 14 |             {
 15 |                 return mCollection.Count();
 16 |             }
 17 |         }
 18 | 
 19 |         public bool IsReadOnly
 20 |         {
 21 |             get
 22 |             {
 23 |                 return false;
 24 |             }
 25 |         }
 26 | 
 27 |         public UIComponentBase this[int index]
 28 |         {
 29 |             get
 30 |             {
 31 |                 return mCollection[index];
 32 |             }
 33 | 
 34 |             set
 35 |             {
 36 |                 mCollection[index] = value;
 37 |             }
 38 |         }
 39 | 
 40 |         public UIComponentBase this[string name]
 41 |         {
 42 |             get
 43 |             {
 44 |                 return mCollection.Where(i => i.Name == name).First();
 45 |             }
 46 | 
 47 |             set
 48 |             {
 49 |                 var a = mCollection.Where(i => i.Name == name).First();
 50 |                 mCollection[mCollection.IndexOf(a)] = value;
 51 |             }
 52 |         }
 53 | 
 54 |         public UIComponentBase CurrentActive { get; private set; } = null;
 55 | 
 56 |         private int mCurrentTab = -1;
 57 |         private List mCollection = new List();
 58 | 
 59 |         internal void AddRange(UIComponentBase[] Components)
 60 |         {
 61 |             bool shuldTab = mCollection.Count == 0 ? true : false;
 62 |             mCollection.AddRange(Components);
 63 |             if (shuldTab)
 64 |                 TabNext();
 65 |         }
 66 | 
 67 |         public void Clear()
 68 |         {
 69 |             mCollection.Clear();
 70 |         }
 71 | 
 72 |         public void RemoveAt(int index)
 73 |         {
 74 |             mCollection.RemoveAt(index);
 75 |         }
 76 | 
 77 |         public int CountSpecType(Type t)
 78 |         {
 79 |             return mCollection.Count(i => i.GetType() == t);
 80 |         }
 81 | 
 82 |         public UIComponentBase TabNext()
 83 |         {
 84 |             mCurrentTab++;
 85 |             mCurrentTab %= Count == 0 ? 1 : Count;
 86 |             if (CurrentActive != null)
 87 |             {
 88 |                 CurrentActive.Focus = false;
 89 |                 CurrentActive.OnTab -= CurrentActiveOnTab;
 90 |             }
 91 |             CurrentActive = mCollection?[mCurrentTab];
 92 |             if (CurrentActive != null)
 93 |             {
 94 |                 CurrentActive.OnTab += CurrentActiveOnTab;
 95 |                 CurrentActive.Focus = true;
 96 |             }
 97 |             return mCollection?[mCurrentTab];
 98 |         }
 99 | 
100 |         public bool ParseCommand(MyConsoleKeyInfo KeyInfo)
101 |         {
102 |             return (bool)CurrentActive?.NewInput(KeyInfo);
103 |         }
104 | 
105 |         public void Add(UIComponentBase item)
106 |         {
107 |             mCollection.Add(item);
108 |             if (Count == 1)
109 |                 TabNext();
110 |         }
111 | 
112 |         public bool Remove(UIComponentBase item)
113 |         {
114 |             return mCollection.Remove(item);
115 |         }
116 | 
117 |         public int IndexOf(UIComponentBase item)
118 |         {
119 |             return mCollection.IndexOf(item);
120 |         }
121 | 
122 |         public bool Contains(UIComponentBase item)
123 |         {
124 |             return mCollection.Contains(item);
125 |         }
126 | 
127 |         public void Insert(int index, UIComponentBase item)
128 |         {
129 |             mCollection.Insert(index, item);
130 |         }
131 | 
132 |         public IEnumerator GetEnumerator()
133 |         {
134 |             foreach (var item in mCollection)
135 |             {
136 |                 yield return item;
137 |             }
138 |         }
139 | 
140 |         public void CopyTo(UIComponentBase[] array, int arrayIndex)
141 |         {
142 |             mCollection.CopyTo(array, arrayIndex);
143 |         }
144 | 
145 |         private void CurrentActiveOnTab(object sender, DateTime e)
146 |         {
147 |             TabNext();
148 |         }
149 | 
150 |         IEnumerator IEnumerable.GetEnumerator()
151 |         {
152 |             return mCollection.GetEnumerator();
153 |         }
154 |     }
155 | }


--------------------------------------------------------------------------------
/src/core.Portable/core.Portable.csproj:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |   
 4 |   
 5 |     14.0
 6 |     Debug
 7 |     AnyCPU
 8 |     {661DC64D-6282-422C-A6AF-60E3C8A63BCC}
 9 |     Library
10 |     Properties
11 |     LandSky
12 |     LandSky
13 |     en-US
14 |     512
15 |     {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 |     
17 |     
18 |     v5.0
19 |   
20 |   
21 |     true
22 |     full
23 |     false
24 |     bin\Debug\
25 |     DEBUG;TRACE
26 |     prompt
27 |     4
28 |   
29 |   
30 |     pdbonly
31 |     true
32 |     bin\Release\
33 |     TRACE
34 |     prompt
35 |     4
36 |   
37 |   
38 |     bin\DebugConsoleAndServer\
39 |   
40 |   
41 |     
42 |     
43 |     
44 |     
45 |     
46 |     
47 |     
48 |     
49 |     
50 |     
51 |     
52 |     
53 |     
54 |     
55 |     
56 |     
57 |     
58 |     
59 |     
60 |     
61 |     
62 |     
63 |     
64 |     
65 |     
66 |     
67 |     
68 |     
69 |     
70 |     
71 |     
72 |     
73 |     
74 |     
75 |     
76 |     
77 |     
78 |     
79 |     
80 |     
81 |     
82 |     
83 |     
84 |     
85 |   
86 |   
87 |     
88 |   
89 |   
90 |   
97 | 


--------------------------------------------------------------------------------
/src/core.Portable/core.Portable.xproj:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |   
 4 |     14.0.25420
 5 |     $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
 6 |   
 7 |   
 8 |   
 9 |     c4a58575-95cf-4f26-8bc9-3e0491404994
10 |     core.Portable
11 |     .\obj
12 |     .\bin\
13 |   
14 | 
15 |   
16 |     2.0
17 |   
18 |   
19 | 


--------------------------------------------------------------------------------
/src/core.Portable/project.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "version": "1.0.0-*",
 3 |   "dependencies": {
 4 |     
 5 |   },
 6 |   "frameworks": {
 7 |     "netstandard1.6": {
 8 |       "dependencies": {
 9 |         "System.Runtime": "4.1.0",
10 |         "System.Linq": "4.1.0",
11 |         "System.Linq.Parallel": "4.0.1",
12 |         "System.Runtime.Extensions": "4.1.0",
13 |         "Microsoft.AspNet.SignalR.Client": "2.2.1",
14 |         "System.Threading": "4.0.11",
15 |         "System.Threading.Tasks": "4.0.11",
16 |         "Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",
17 |         "System.Diagnostics.Debug": "4.0.11"
18 | 
19 |       },
20 |       "imports": [ "net45", "monoandroid", "netcore45" ] 
21 |     }
22 |   }
23 | }


--------------------------------------------------------------------------------
/src/global.json:
--------------------------------------------------------------------------------
1 | {
2 |   "projects": [ "../libs/LibBinary" ]
3 | }


--------------------------------------------------------------------------------