├── .github ├── renovate.json └── workflows │ └── cicd.yml ├── .gitignore ├── .releaserc.json ├── AvaloniaTetris.sln ├── LICENSE ├── README.md ├── docs └── Diagram.drawio ├── global.json └── src ├── .gitignore ├── AvaloniaTetris.Browser ├── AppBundle │ ├── Logo.svg │ ├── app.css │ ├── favicon.ico │ ├── index.html │ └── main.js ├── AvaloniaTetris.Browser.csproj ├── Program.cs ├── Properties │ └── launchSettings.json └── runtimeconfig.template.json ├── AvaloniaTetris.Desktop ├── AvaloniaTetris.Desktop.csproj ├── Program.cs └── app.manifest └── AvaloniaTetris ├── App.axaml ├── App.axaml.cs ├── Assets └── avalonia-logo.ico ├── AvaloniaTetris.csproj ├── Game.cs ├── GridPoint.cs ├── IntToColorConverter.cs ├── Piece.cs ├── ViewModels ├── MainViewModel.cs └── ViewModelBase.cs └── Views ├── MainView.axaml ├── MainView.axaml.cs ├── MainWindow.axaml └── MainWindow.axaml.cs /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "enabled": true, 4 | "timezone": "America/Vancouver", 5 | "dependencyDashboard": true, 6 | "semanticCommits": "enabled", 7 | "assignees": ["@ivanjosipovic"], 8 | "extends": [ "config:recommended" ], 9 | "platformAutomerge": true, 10 | "ignorePaths": [ 11 | "**/docs/**" 12 | ], 13 | "packageRules": [ 14 | { 15 | "groupName": "Avalonia", 16 | "separateMajorMinor": true, 17 | "groupSlug": "avalonia-libs", 18 | "packageRules": [ 19 | { 20 | "matchPackagePatterns": [ 21 | "Avalonia", 22 | "Avalonia.*" 23 | ] 24 | } 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/cicd.yml: -------------------------------------------------------------------------------- 1 | name: CICD 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - 'main' 8 | - 'alpha' 9 | - 'beta' 10 | - 'dev' 11 | pull_request: 12 | types: [opened, reopened, synchronize] 13 | merge_group: 14 | 15 | jobs: 16 | create-release: 17 | name: Create Release 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Checkout code 21 | uses: actions/checkout@v4 22 | 23 | - name: Setup .NET Core 24 | uses: actions/setup-dotnet@v4 25 | env: 26 | DOTNET_INSTALL_DIR: "./.dotnet" 27 | with: 28 | global-json-file: global.json 29 | 30 | - name: Dotnet Restore Workloads 31 | run: dotnet workload restore 32 | 33 | - name: Dotnet Build 34 | run: dotnet build -c Release 35 | 36 | - name: Dotnet Publish Browser 37 | working-directory: src/AvaloniaTetris.Browser 38 | run: dotnet publish -c Release 39 | 40 | - name: Setup Node 41 | uses: actions/setup-node@v4 42 | with: 43 | node-version: 'latest' 44 | 45 | - name: Install Netlify CLI 46 | run: npm install netlify-cli -g 47 | 48 | - name: Deploy 49 | run: netlify deploy ${{ (github.ref == 'refs/heads/main' && '--prod') || '' }} --json -d src/AvaloniaTetris.Browser/bin/Release/net8.0/browser-wasm/AppBundle/ 50 | env: 51 | NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} 52 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} 53 | 54 | - name: Semantic Release 55 | uses: cycjimmy/semantic-release-action@v4 56 | id: semantic 57 | env: 58 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": [ 3 | "main", 4 | { 5 | "name": "beta", 6 | "prerelease": true 7 | }, 8 | { 9 | "name": "alpha", 10 | "prerelease": true 11 | } 12 | ], 13 | "plugins": [ 14 | "@semantic-release/commit-analyzer", 15 | "@semantic-release/release-notes-generator", 16 | [ 17 | "@semantic-release/github", 18 | { 19 | "assets": [ 20 | { 21 | "path": "dist/**" 22 | } 23 | ] 24 | } 25 | ] 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /AvaloniaTetris.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34414.90 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaTetris", "src\AvaloniaTetris\AvaloniaTetris.csproj", "{8A2E32FC-20E5-4502-9BCD-9399D3B190F2}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaTetris.Desktop", "src\AvaloniaTetris.Desktop\AvaloniaTetris.Desktop.csproj", "{1EF675DA-D0A5-4151-84DF-71FD2A2B52D0}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaTetris.Browser", "src\AvaloniaTetris.Browser\AvaloniaTetris.Browser.csproj", "{C024C876-CDFA-4FB7-9D24-132D66286E7E}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1936A950-9AB4-4157-8A60-C2731831E079}" 13 | ProjectSection(SolutionItems) = preProject 14 | README.md = README.md 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {8A2E32FC-20E5-4502-9BCD-9399D3B190F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {8A2E32FC-20E5-4502-9BCD-9399D3B190F2}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {8A2E32FC-20E5-4502-9BCD-9399D3B190F2}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {8A2E32FC-20E5-4502-9BCD-9399D3B190F2}.Release|Any CPU.Build.0 = Release|Any CPU 27 | {1EF675DA-D0A5-4151-84DF-71FD2A2B52D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {1EF675DA-D0A5-4151-84DF-71FD2A2B52D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {1EF675DA-D0A5-4151-84DF-71FD2A2B52D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {1EF675DA-D0A5-4151-84DF-71FD2A2B52D0}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {C024C876-CDFA-4FB7-9D24-132D66286E7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {C024C876-CDFA-4FB7-9D24-132D66286E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {C024C876-CDFA-4FB7-9D24-132D66286E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {C024C876-CDFA-4FB7-9D24-132D66286E7E}.Release|Any CPU.Build.0 = Release|Any CPU 35 | EndGlobalSection 36 | GlobalSection(SolutionProperties) = preSolution 37 | HideSolutionNode = FALSE 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityGlobals) = postSolution 40 | SolutionGuid = {BA0E23E9-773C-47F4-992A-CE0A5E008669} 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Ivan Josipovic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AvaloniaTetris 2 | A Tetris game written with Avalonia 3 | 4 | [Live Demo](https://AvaloniaTetris.netlify.app) -------------------------------------------------------------------------------- /docs/Diagram.drawio: -------------------------------------------------------------------------------- 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 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 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 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.401", 4 | "rollForward": "latestFeature" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # Tye 66 | .tye/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio LightSwitch build output 300 | **/*.HTMLClient/GeneratedArtifacts 301 | **/*.DesktopClient/GeneratedArtifacts 302 | **/*.DesktopClient/ModelManifest.xml 303 | **/*.Server/GeneratedArtifacts 304 | **/*.Server/ModelManifest.xml 305 | _Pvt_Extensions 306 | 307 | # Paket dependency manager 308 | .paket/paket.exe 309 | paket-files/ 310 | 311 | # FAKE - F# Make 312 | .fake/ 313 | 314 | # CodeRush personal settings 315 | .cr/personal 316 | 317 | # Python Tools for Visual Studio (PTVS) 318 | __pycache__/ 319 | *.pyc 320 | 321 | # Cake - Uncomment if you are using it 322 | # tools/** 323 | # !tools/packages.config 324 | 325 | # Tabs Studio 326 | *.tss 327 | 328 | # Telerik's JustMock configuration file 329 | *.jmconfig 330 | 331 | # BizTalk build output 332 | *.btp.cs 333 | *.btm.cs 334 | *.odx.cs 335 | *.xsd.cs 336 | 337 | # OpenCover UI analysis results 338 | OpenCover/ 339 | 340 | # Azure Stream Analytics local run output 341 | ASALocalRun/ 342 | 343 | # MSBuild Binary and Structured Log 344 | *.binlog 345 | 346 | # NVidia Nsight GPU debugger configuration file 347 | *.nvuser 348 | 349 | # MFractors (Xamarin productivity tool) working folder 350 | .mfractor/ 351 | 352 | # Local History for Visual Studio 353 | .localhistory/ 354 | 355 | # BeatPulse healthcheck temp database 356 | healthchecksdb 357 | 358 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 359 | MigrationBackup/ 360 | 361 | # Ionide (cross platform F# VS Code tools) working folder 362 | .ionide/ 363 | 364 | # Fody - auto-generated XML schema 365 | FodyWeavers.xsd 366 | 367 | ## 368 | ## Visual studio for Mac 369 | ## 370 | 371 | 372 | # globs 373 | Makefile.in 374 | *.userprefs 375 | *.usertasks 376 | config.make 377 | config.status 378 | aclocal.m4 379 | install-sh 380 | autom4te.cache/ 381 | *.tar.gz 382 | tarballs/ 383 | test-results/ 384 | 385 | # Mac bundle stuff 386 | *.dmg 387 | *.app 388 | 389 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 390 | # General 391 | .DS_Store 392 | .AppleDouble 393 | .LSOverride 394 | 395 | # Icon must end with two \r 396 | Icon 397 | 398 | 399 | # Thumbnails 400 | ._* 401 | 402 | # Files that might appear in the root of a volume 403 | .DocumentRevisions-V100 404 | .fseventsd 405 | .Spotlight-V100 406 | .TemporaryItems 407 | .Trashes 408 | .VolumeIcon.icns 409 | .com.apple.timemachine.donotpresent 410 | 411 | # Directories potentially created on remote AFP share 412 | .AppleDB 413 | .AppleDesktop 414 | Network Trash Folder 415 | Temporary Items 416 | .apdisk 417 | 418 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 419 | # Windows thumbnail cache files 420 | Thumbs.db 421 | ehthumbs.db 422 | ehthumbs_vista.db 423 | 424 | # Dump file 425 | *.stackdump 426 | 427 | # Folder config file 428 | [Dd]esktop.ini 429 | 430 | # Recycle Bin used on file shares 431 | $RECYCLE.BIN/ 432 | 433 | # Windows Installer files 434 | *.cab 435 | *.msi 436 | *.msix 437 | *.msm 438 | *.msp 439 | 440 | # Windows shortcuts 441 | *.lnk 442 | 443 | # JetBrains Rider 444 | .idea/ 445 | *.sln.iml 446 | 447 | ## 448 | ## Visual Studio Code 449 | ## 450 | .vscode/* 451 | !.vscode/settings.json 452 | !.vscode/tasks.json 453 | !.vscode/launch.json 454 | !.vscode/extensions.json 455 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AppBundle/Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AppBundle/app.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --sat: env(safe-area-inset-top); 3 | --sar: env(safe-area-inset-right); 4 | --sab: env(safe-area-inset-bottom); 5 | --sal: env(safe-area-inset-left); 6 | } 7 | 8 | /* HTML styles for the splash screen */ 9 | 10 | .highlight { 11 | color: white; 12 | font-size: 2.5rem; 13 | display: block; 14 | } 15 | 16 | .purple { 17 | color: #8b44ac; 18 | } 19 | 20 | .icon { 21 | opacity: 0.05; 22 | height: 35%; 23 | width: 35%; 24 | position: absolute; 25 | background-repeat: no-repeat; 26 | right: 0px; 27 | bottom: 0px; 28 | margin-right: 3%; 29 | margin-bottom: 5%; 30 | z-index: 5000; 31 | background-position: right bottom; 32 | pointer-events: none; 33 | } 34 | 35 | #avalonia-splash a { 36 | color: whitesmoke; 37 | text-decoration: none; 38 | } 39 | 40 | .center { 41 | display: flex; 42 | justify-content: center; 43 | align-items: center; 44 | height: 100vh; 45 | } 46 | 47 | #avalonia-splash { 48 | position: relative; 49 | height: 100%; 50 | width: 100%; 51 | color: whitesmoke; 52 | background: #1b2a4e; 53 | font-family: 'Nunito', sans-serif; 54 | background-position: center; 55 | background-size: cover; 56 | background-repeat: no-repeat; 57 | justify-content: center; 58 | align-items: center; 59 | } 60 | 61 | .splash-close { 62 | animation: fadeout 0.25s linear forwards; 63 | } 64 | 65 | @keyframes fadeout { 66 | 0% { 67 | opacity: 100%; 68 | } 69 | 70 | 100% { 71 | opacity: 0; 72 | visibility: collapse; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AppBundle/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanJosipovic/AvaloniaTetris/c515af4d3f95b38d74add7d2a54d4b48967e4f36/src/AvaloniaTetris.Browser/AppBundle/favicon.ico -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AppBundle/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Avalonia Tetris 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 |

20 | Powered by 21 | Avalonia UI 22 |

23 |
24 | Avalonia Logo 25 |
26 |
27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AppBundle/main.js: -------------------------------------------------------------------------------- 1 | import { dotnet } from './dotnet.js' 2 | 3 | const is_browser = typeof window != "undefined"; 4 | if (!is_browser) throw new Error(`Expected to be running in a browser`); 5 | 6 | const dotnetRuntime = await dotnet 7 | .withDiagnosticTracing(false) 8 | .withApplicationArgumentsFromQuery() 9 | .create(); 10 | 11 | const config = dotnetRuntime.getConfig(); 12 | 13 | await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [window.location.search]); -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/AvaloniaTetris.Browser.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net8.0 4 | browser-wasm 5 | AppBundle\main.js 6 | Exe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Versioning; 2 | using System.Threading.Tasks; 3 | 4 | using Avalonia; 5 | using Avalonia.Browser; 6 | 7 | using AvaloniaTetris; 8 | 9 | [assembly: SupportedOSPlatform("browser")] 10 | 11 | internal partial class Program 12 | { 13 | private static async Task Main(string[] args) => await BuildAvaloniaApp() 14 | .WithInterFont() 15 | .StartBrowserAppAsync("out"); 16 | 17 | public static AppBuilder BuildAvaloniaApp() 18 | => AppBuilder.Configure(); 19 | } 20 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "AvaloniaTetris.Browser": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 10 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/debug?browser={browserInspectUri}" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Browser/runtimeconfig.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "wasmHostProperties": { 3 | "perHostConfig": [ 4 | { 5 | "name": "browser", 6 | "html-path": "index.html", 7 | "Host": "browser" 8 | } 9 | ] 10 | } 11 | } -------------------------------------------------------------------------------- /src/AvaloniaTetris.Desktop/AvaloniaTetris.Desktop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | WinExe 4 | 6 | net8.0 7 | enable 8 | true 9 | app.manifest 10 | true 11 | true 12 | true 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Desktop/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Avalonia; 4 | 5 | namespace AvaloniaTetris.Desktop; 6 | 7 | class Program 8 | { 9 | // Initialization code. Don't use any Avalonia, third-party APIs or any 10 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 11 | // yet and stuff might break. 12 | [STAThread] 13 | public static void Main(string[] args) => BuildAvaloniaApp() 14 | .StartWithClassicDesktopLifetime(args); 15 | 16 | // Avalonia configuration, don't remove; also used by visual designer. 17 | public static AppBuilder BuildAvaloniaApp() 18 | => AppBuilder.Configure() 19 | .UsePlatformDetect() 20 | .WithInterFont() 21 | .LogToTrace(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/AvaloniaTetris.Desktop/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/App.axaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/App.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Data.Core.Plugins; 4 | using Avalonia.Markup.Xaml; 5 | 6 | using AvaloniaTetris.ViewModels; 7 | using AvaloniaTetris.Views; 8 | 9 | namespace AvaloniaTetris; 10 | 11 | public partial class App : Application 12 | { 13 | public override void Initialize() 14 | { 15 | AvaloniaXamlLoader.Load(this); 16 | } 17 | 18 | public override void OnFrameworkInitializationCompleted() 19 | { 20 | // Line below is needed to remove Avalonia data validation. 21 | // Without this line you will get duplicate validations from both Avalonia and CT 22 | BindingPlugins.DataValidators.RemoveAt(0); 23 | 24 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 25 | { 26 | desktop.MainWindow = new MainWindow 27 | { 28 | DataContext = new MainViewModel() 29 | }; 30 | } 31 | else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) 32 | { 33 | singleViewPlatform.MainView = new MainView 34 | { 35 | DataContext = new MainViewModel() 36 | }; 37 | } 38 | 39 | base.OnFrameworkInitializationCompleted(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Assets/avalonia-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanJosipovic/AvaloniaTetris/c515af4d3f95b38d74add7d2a54d4b48967e4f36/src/AvaloniaTetris/Assets/avalonia-logo.ico -------------------------------------------------------------------------------- /src/AvaloniaTetris/AvaloniaTetris.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net8.0 4 | enable 5 | latest 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Game.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Threading; 2 | using CommunityToolkit.Mvvm.ComponentModel; 3 | using CommunityToolkit.Mvvm.Input; 4 | using System; 5 | using System.Linq; 6 | 7 | namespace AvaloniaTetris; 8 | 9 | public partial class Game : ObservableObject 10 | { 11 | public Game() 12 | { 13 | for (int y = 0; y <= 19; y++) 14 | { 15 | for (int x = 0; x <= 9; x++) 16 | { 17 | Positions[x, y] = new GridPoint(); 18 | } 19 | } 20 | 21 | for (int y = 0; y <= 1; y++) 22 | { 23 | for (int x = 0; x <= 3; x++) 24 | { 25 | NextPiecePositions[x, y] = new GridPoint(); 26 | } 27 | } 28 | } 29 | 30 | [ObservableProperty] 31 | private GridPoint[,] _positions = new GridPoint[10,20]; 32 | 33 | [ObservableProperty] 34 | private GridPoint[,] _nextPiecePositions = new GridPoint[4, 2]; 35 | 36 | [ObservableProperty] 37 | private int _level; 38 | 39 | [ObservableProperty] 40 | private int _score; 41 | 42 | [ObservableProperty] 43 | private int _lines; 44 | 45 | [ObservableProperty] 46 | private bool _isActive = true; 47 | 48 | [ObservableProperty] 49 | private int _speed; 50 | 51 | private readonly object _lock = new(); 52 | 53 | private DispatcherTimer? timer; 54 | 55 | private Piece? activePiece; 56 | 57 | private Piece? nextPiece; 58 | 59 | private void Timer_Tick(object? sender, EventArgs e) 60 | { 61 | MoveDown(); 62 | } 63 | 64 | readonly Random randomPiece = new(); 65 | 66 | private Piece GetRandom() 67 | { 68 | // Pick random Piece 69 | Piece? newPiece = randomPiece.Next(1, 6) switch 70 | { 71 | 1 => new Straight(), 72 | 2 => new Square(), 73 | 3 => new T(), 74 | 4 => randomPiece.Next(1, 3) switch 75 | { 76 | 1 => new L1(), 77 | 2 => new L2(), 78 | }, 79 | 5 => randomPiece.Next(1, 3) switch 80 | { 81 | 1 => new S1(), 82 | 2 => new S2(), 83 | }, 84 | _ => throw new Exception(), 85 | }; 86 | 87 | return newPiece; 88 | } 89 | 90 | private void AddNewPiece() 91 | { 92 | if (nextPiece == null) 93 | { 94 | nextPiece = GetRandom(); 95 | } 96 | 97 | activePiece = nextPiece; 98 | 99 | nextPiece = GetRandom(); 100 | SetNextPiece(); 101 | } 102 | 103 | private void ClearActivePiece() 104 | { 105 | foreach (var point in activePiece.GetUsedCoords()) 106 | { 107 | var pos = Positions[(int)point.X, (int)point.Y]; 108 | pos.Type = 0; 109 | pos.IsActive = false; 110 | } 111 | } 112 | 113 | private void SetActivePiece(bool isActive = true) 114 | { 115 | int shape = 0; 116 | if (activePiece is Straight) 117 | { 118 | shape = 1; 119 | } 120 | else if (activePiece is Square) 121 | { 122 | shape = 2; 123 | } 124 | else if (activePiece is S1 or S2) 125 | { 126 | shape = 3; 127 | } 128 | else if (activePiece is T) 129 | { 130 | shape = 4; 131 | } 132 | else if (activePiece is L1 or L2) 133 | { 134 | shape = 5; 135 | } 136 | 137 | foreach (var point in activePiece.GetUsedCoords()) 138 | { 139 | var pos = Positions[(int)point.X, (int)point.Y]; 140 | pos.Type = shape; 141 | pos.IsActive = isActive; 142 | } 143 | } 144 | 145 | private void SetNextPiece() 146 | { 147 | int shape = 0; 148 | if (nextPiece is Straight) 149 | { 150 | shape = 1; 151 | } 152 | else if (nextPiece is Square) 153 | { 154 | shape = 2; 155 | } 156 | else if (nextPiece is S1 or S2) 157 | { 158 | shape = 3; 159 | } 160 | else if (nextPiece is T) 161 | { 162 | shape = 4; 163 | } 164 | else if (nextPiece is L1 or L2) 165 | { 166 | shape = 5; 167 | } 168 | 169 | foreach (var item in NextPiecePositions) 170 | { 171 | item.Type = 0; 172 | } 173 | 174 | foreach (var point in nextPiece.GetUsedCoords(-nextPiece.X, -nextPiece.Y)) 175 | { 176 | var pos = NextPiecePositions[(int)point.X, (int)point.Y]; 177 | pos.Type = shape; 178 | } 179 | } 180 | 181 | private void RemoveFullRow() 182 | { 183 | //Check if a row needs to be removed 184 | for (int y = 0; y <= 19; y++) 185 | { 186 | Top: 187 | bool removeRow = true; 188 | 189 | for (int x = 0; x <= 9; x++) 190 | { 191 | var pos = Positions[x, y]; 192 | 193 | if (pos.Type == 0 && !pos.IsActive) 194 | { 195 | removeRow = false; 196 | break; 197 | } 198 | } 199 | 200 | if (removeRow) 201 | { 202 | Lines++; 203 | Level = Lines / 10; 204 | Score += 40 * (Level + 1); 205 | 206 | SetGameSpeed(); 207 | 208 | for (int yy = y + 1; yy <= 19; yy++) 209 | { 210 | for (int x = 0; x <= 9; x++) 211 | { 212 | var old = Positions[x, yy - 1]; 213 | 214 | var newOb = Positions[x, yy]; 215 | 216 | if (!old.IsActive && !newOb.IsActive) 217 | { 218 | old.Type = newOb.Type; 219 | old.IsActive = false; 220 | } 221 | } 222 | } 223 | 224 | goto Top; 225 | } 226 | } 227 | } 228 | 229 | private void SetGameSpeed() 230 | { 231 | timer.Interval = Level switch 232 | { 233 | 0 => TimeSpan.FromMilliseconds(800), 234 | 1 => TimeSpan.FromMilliseconds(716), 235 | 2 => TimeSpan.FromMilliseconds(633.33), 236 | 3 => TimeSpan.FromMilliseconds(550), 237 | 4 => TimeSpan.FromMilliseconds(466.66), 238 | 5 => TimeSpan.FromMilliseconds(383.33), 239 | 6 => TimeSpan.FromMilliseconds(300), 240 | 7 => TimeSpan.FromMilliseconds(216.66), 241 | 8 => TimeSpan.FromMilliseconds(133.33), 242 | 9 => TimeSpan.FromMilliseconds(100), 243 | 10 or 11 or 12 => TimeSpan.FromMilliseconds(85), 244 | 13 or 14 or 15 => TimeSpan.FromMilliseconds(65), 245 | 16 or 17 or 18 => TimeSpan.FromMilliseconds(50), 246 | 19 or 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 => TimeSpan.FromMilliseconds(33.3), 247 | _ => TimeSpan.FromMilliseconds(16.67), 248 | }; 249 | Speed = (int)timer.Interval.TotalMilliseconds; 250 | } 251 | 252 | // Public 253 | 254 | public void Start() 255 | { 256 | if (timer == null) 257 | { 258 | AddNewPiece(); 259 | SetActivePiece(); 260 | 261 | timer = new DispatcherTimer(); 262 | SetGameSpeed(); 263 | timer.Tick += Timer_Tick; 264 | timer.Start(); 265 | } 266 | } 267 | 268 | // Game Controls 269 | 270 | [RelayCommand] 271 | void MoveLeft() 272 | { 273 | if (!IsActive) { return; } 274 | 275 | lock (_lock) 276 | { 277 | var coords = activePiece?.GetUsedCoords(-1, 0); 278 | 279 | // Check for out of bounds 280 | if (coords.Any(point => point.X < 0)) 281 | { 282 | return; 283 | } 284 | 285 | // Check if piece has a conflict 286 | if (coords.Any(pt => Positions[(int)pt.X, (int)pt.Y].Type > 0 && !Positions[(int)pt.X, (int)pt.Y].IsActive)) 287 | { 288 | return; 289 | } 290 | 291 | ClearActivePiece(); 292 | activePiece.MoveLeft(); 293 | SetActivePiece(); 294 | } 295 | } 296 | 297 | [RelayCommand] 298 | void MoveRight() 299 | { 300 | if (!IsActive) { return; } 301 | 302 | lock (_lock) 303 | { 304 | var coords = activePiece?.GetUsedCoords(1, 0); 305 | 306 | // Check for out of bounds 307 | if (coords.Any(point => point.X > 9)) 308 | { 309 | return; 310 | } 311 | 312 | // Check if piece has a conflict 313 | if (coords.Any(pt => Positions[(int)pt.X, (int)pt.Y].Type > 0 && !Positions[(int)pt.X, (int)pt.Y].IsActive)) 314 | { 315 | return; 316 | } 317 | 318 | ClearActivePiece(); 319 | activePiece.MoveRight(); 320 | SetActivePiece(); 321 | } 322 | } 323 | 324 | [RelayCommand] 325 | void MoveDown() 326 | { 327 | if (!IsActive) { return; } 328 | 329 | lock (_lock) 330 | { 331 | // Get coords for one row down 332 | var coords = activePiece.GetUsedCoords(0, -1); 333 | 334 | // Check if we have reached the end or there is a conflict 335 | if (!coords.Any(p => p.Y < 0) && !coords.Any(pt => Positions[(int)pt.X, (int)pt.Y].Type > 0 && !Positions[(int)pt.X, (int)pt.Y].IsActive)) 336 | { 337 | ClearActivePiece(); 338 | activePiece.MoveDown(); 339 | SetActivePiece(); 340 | } 341 | else 342 | { 343 | // Check if piece failed to go to first row 344 | // Means end game 345 | if (activePiece.Y == 19) 346 | { 347 | IsActive = false; 348 | timer?.Stop(); 349 | return; 350 | } 351 | 352 | SetActivePiece(false); 353 | 354 | AddNewPiece(); 355 | SetActivePiece(); 356 | RemoveFullRow(); 357 | } 358 | } 359 | } 360 | 361 | [RelayCommand] 362 | void Rotate() 363 | { 364 | if (!IsActive) { return; } 365 | 366 | lock (_lock) 367 | { 368 | var coords = activePiece?.GetUsedCoords(0, 0, true); 369 | 370 | // Check for out of bounds 371 | if (coords.Any(point => point.X < 0)) 372 | { 373 | return; 374 | } 375 | 376 | if (coords.Any(point => point.X > 9)) 377 | { 378 | return; 379 | } 380 | 381 | if (coords.Any(point => point.Y > 19)) 382 | { 383 | return; 384 | } 385 | 386 | if (coords.Any(point => point.Y < 0)) 387 | { 388 | return; 389 | } 390 | 391 | // Check if piece has a conflict 392 | if (coords.Any(pt => Positions[(int)pt.X, (int)pt.Y].Type > 0 && !Positions[(int)pt.X, (int)pt.Y].IsActive)) 393 | { 394 | return; 395 | } 396 | 397 | ClearActivePiece(); 398 | activePiece.Rotate(); 399 | SetActivePiece(); 400 | } 401 | } 402 | 403 | [RelayCommand] 404 | void Pause() 405 | { 406 | if (timer?.IsEnabled == true) 407 | { 408 | IsActive = false; 409 | timer?.Stop(); 410 | } 411 | else 412 | { 413 | IsActive = true; 414 | timer?.Start(); 415 | } 416 | } 417 | 418 | [RelayCommand] 419 | void Restart() 420 | { 421 | Level = 1; 422 | Score = 0; 423 | Lines = 0; 424 | 425 | IsActive = true; 426 | 427 | timer?.Start(); 428 | 429 | for (int y = 0; y <= 19; y++) 430 | { 431 | for (int x = 0; x <= 9; x++) 432 | { 433 | var pos = Positions[x, y]; 434 | pos.Type = 0; 435 | pos.IsActive = false; 436 | } 437 | } 438 | 439 | AddNewPiece(); 440 | SetActivePiece(); 441 | } 442 | } 443 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/GridPoint.cs: -------------------------------------------------------------------------------- 1 | using CommunityToolkit.Mvvm.ComponentModel; 2 | 3 | namespace AvaloniaTetris; 4 | 5 | public partial class GridPoint : ObservableObject 6 | { 7 | [ObservableProperty] 8 | int _type; 9 | 10 | [ObservableProperty] 11 | bool _isActive; 12 | } 13 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/IntToColorConverter.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Data.Converters; 2 | using Avalonia.Data; 3 | using System; 4 | using System.Globalization; 5 | using Avalonia.Media; 6 | 7 | namespace AvaloniaTetris; 8 | 9 | public class IntToColorConverter : IValueConverter 10 | { 11 | public static readonly IntToColorConverter Instance = new(); 12 | 13 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 14 | { 15 | if (value is int val) 16 | { 17 | switch (val) 18 | { 19 | case 0: 20 | return Brushes.Black; 21 | case 1: 22 | return Brushes.Red; 23 | case 2: 24 | return Brushes.Blue; 25 | case 3: 26 | return Brushes.Green; 27 | case 4: 28 | return Brushes.Orange; 29 | case 5: 30 | return Brushes.Purple; 31 | } 32 | } 33 | 34 | // converter used for the wrong type 35 | return new BindingNotification(new InvalidCastException(), BindingErrorType.Error); 36 | } 37 | 38 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 39 | { 40 | throw new NotSupportedException(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Piece.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using CommunityToolkit.Mvvm.ComponentModel; 3 | using System.Collections.Generic; 4 | 5 | namespace AvaloniaTetris; 6 | 7 | public abstract partial class Piece : ObservableObject 8 | { 9 | [ObservableProperty] 10 | int[,] _shape; 11 | 12 | [ObservableProperty] 13 | int _x; 14 | 15 | [ObservableProperty] 16 | int _y; 17 | 18 | public List GetUsedCoords(double xOffset = 0, double yOffset = 0, bool rotate = false) 19 | { 20 | List coords = []; 21 | 22 | var newShape = Shape; 23 | 24 | if (rotate) 25 | { 26 | newShape = RotateMatrixCounterClockwise(Shape); 27 | } 28 | 29 | int rows = newShape.GetLength(0); 30 | int columns = newShape.GetLength(1); 31 | 32 | for (int x = 0; x < rows; x++) 33 | { 34 | for (int y = 0; y < columns; y++) 35 | { 36 | int currentValue = newShape[x, y]; 37 | 38 | if (currentValue == 1) 39 | { 40 | coords.Add(new Point(X + y + xOffset, Y + x + yOffset)); 41 | } 42 | } 43 | } 44 | 45 | return coords; 46 | } 47 | 48 | static int[,] RotateMatrixCounterClockwise(int[,] oldMatrix) 49 | { 50 | int[,] newMatrix = new int[oldMatrix.GetLength(1), oldMatrix.GetLength(0)]; 51 | int newColumn, newRow = 0; 52 | for (int oldColumn = oldMatrix.GetLength(1) - 1; oldColumn >= 0; oldColumn--) 53 | { 54 | newColumn = 0; 55 | for (int oldRow = 0; oldRow < oldMatrix.GetLength(0); oldRow++) 56 | { 57 | newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn]; 58 | newColumn++; 59 | } 60 | newRow++; 61 | } 62 | return newMatrix; 63 | } 64 | 65 | public void MoveDown() 66 | { 67 | Y--; 68 | } 69 | 70 | public void MoveLeft() 71 | { 72 | X--; 73 | } 74 | 75 | public void MoveRight() 76 | { 77 | X++; 78 | } 79 | 80 | public void Rotate() 81 | { 82 | Shape = RotateMatrixCounterClockwise(Shape); 83 | } 84 | } 85 | 86 | internal class Straight : Piece 87 | { 88 | public Straight() 89 | { 90 | Shape = new int[,] { { 1, 1, 1, 1 } }; 91 | X = 3; 92 | Y = 19; 93 | } 94 | } 95 | 96 | internal class Square : Piece 97 | { 98 | public Square() 99 | { 100 | Shape = new int[,] { { 1, 1 }, 101 | { 1, 1 }}; 102 | X = 4; 103 | Y = 18; 104 | } 105 | } 106 | 107 | internal class T : Piece 108 | { 109 | public T() 110 | { 111 | Shape = new int[,] { { 1, 1, 1 }, 112 | { 0, 1, 0 }}; 113 | X = 3; 114 | Y = 18; 115 | } 116 | } 117 | 118 | internal class L1 : Piece 119 | { 120 | public L1() 121 | { 122 | Shape = new int[,] { { 1, 1, 1 }, 123 | { 0, 0, 1 }}; 124 | X = 4; 125 | Y = 18; 126 | } 127 | } 128 | internal class L2 : Piece 129 | { 130 | public L2() 131 | { 132 | Shape = new int[,] { { 0, 0, 1 }, 133 | { 1, 1, 1 }}; 134 | X = 4; 135 | Y = 18; 136 | } 137 | } 138 | 139 | 140 | internal class S1 : Piece 141 | { 142 | public S1() 143 | { 144 | Shape = new int[,] 145 | { 146 | { 1, 1, 0 }, 147 | { 0, 1, 1 } 148 | }; 149 | X = 4; 150 | Y = 18; 151 | } 152 | } 153 | 154 | internal class S2 : Piece 155 | { 156 | public S2() 157 | { 158 | Shape = new int[,] 159 | { 160 | { 0, 1, 1 }, 161 | { 1, 1, 0 } 162 | }; 163 | X = 4; 164 | Y = 18; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/ViewModels/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AvaloniaTetris.ViewModels; 4 | 5 | public partial class MainViewModel : ViewModelBase 6 | { 7 | public IEnumerable OrderedPoints => OrderPoints(); 8 | public IEnumerable OrderedNextPoints => OrderNextPoints(); 9 | 10 | public Game Game { get; set; } = new Game(); 11 | 12 | public MainViewModel() 13 | { 14 | OrderPoints(); 15 | 16 | Game.Start(); 17 | } 18 | 19 | private IEnumerable OrderPoints() 20 | { 21 | for (int y = 19; y >= 0; y--) 22 | { 23 | for (int x = 0; x <= 9; x++) 24 | { 25 | yield return Game.Positions[x, y]; 26 | } 27 | } 28 | } 29 | 30 | private IEnumerable OrderNextPoints() 31 | { 32 | for (int y = 1; y >= 0; y--) 33 | { 34 | for (int x = 0; x <= 3; x++) 35 | { 36 | yield return Game.NextPiecePositions[x, y]; 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using CommunityToolkit.Mvvm.ComponentModel; 2 | 3 | namespace AvaloniaTetris.ViewModels; 4 | 5 | public class ViewModelBase : ObservableObject 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Views/MainView.axaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Stats 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 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Controls 70 | 71 | 72 | Keyboard: 73 | Left 74 | Right 75 | Up - Rotate 76 | Down 77 | 78 | 79 | 80 | Manual: 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | Next Piece 91 | 92 | 93 | 94 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Views/MainView.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | 3 | namespace AvaloniaTetris.Views; 4 | 5 | public partial class MainView : UserControl 6 | { 7 | public MainView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Views/MainWindow.axaml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/AvaloniaTetris/Views/MainWindow.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | 3 | namespace AvaloniaTetris.Views; 4 | 5 | public partial class MainWindow : Window 6 | { 7 | public MainWindow() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | --------------------------------------------------------------------------------