From 6473e22447e6fd6cc82a804eadf25617c6198cfd Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 7 Apr 2022 12:35:51 +0200 Subject: [PATCH] Setup printable Grid with Tetrominoe and color --- Models/Grid.cs | 20 ++++++++++++++++++-- Models/Tetrominoe.cs | 5 +++-- Tetris.csproj | 4 ++++ Tetris.sln | 10 +++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Models/Grid.cs b/Models/Grid.cs index b98cb0c..d48f5f0 100644 --- a/Models/Grid.cs +++ b/Models/Grid.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using Pastel; using Color = System.Drawing.Color; namespace Tetris.Models; @@ -35,10 +36,25 @@ public class Grid { public override string ToString() { String s = ""; for (uint y = 0; y < _grid.GetLength(1); y++) { - for (uint x = 0; x < _grid.GetLength(0); x++) - s += _grid[x,y].Name + "\t"; + for (uint x = 0; x < _grid.GetLength(0); x++) { + s += "x".Pastel(_grid[x, y]); + } s += "\n"; } return s; } + + public string ToString(Tetrominoe t) { + Color[,] grid = (Color[,]) _grid.Clone(); + Boolean[,] shape = t.Shape; + + for (uint x = 0; x < shape.GetLength(0); x++) + for (uint y = 0; y < shape.GetLength(1); y++) { + Point s = t.Coordinates + new Size((int) x, (int) y); + if (shape[x, y]) + grid[s.X, s.Y] = t.Color; + } + + return new Grid(grid).ToString(); + } } diff --git a/Models/Tetrominoe.cs b/Models/Tetrominoe.cs index b793280..2e6977c 100644 --- a/Models/Tetrominoe.cs +++ b/Models/Tetrominoe.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Drawing; +using Pastel; namespace Tetris.Models; @@ -56,7 +57,7 @@ public class Tetrominoe { private Color _color; public Color Color { - get; + get => _color; } public Tetrominoe(Grid grid, bool[,] shape, Point coordinates, short orientation, Color color) { @@ -110,7 +111,7 @@ public class Tetrominoe { for (uint y = 0; y < Shape.GetLength(1); y++) { for (uint x = 0; x < Shape.GetLength(0); x++) if (Shape[x, y]) - s += "x"; + s += "x".Pastel(_color); else s += " "; s += "\n"; diff --git a/Tetris.csproj b/Tetris.csproj index d9bfab2..d01518f 100644 --- a/Tetris.csproj +++ b/Tetris.csproj @@ -7,4 +7,8 @@ net6.0-windows + + + + diff --git a/Tetris.sln b/Tetris.sln index 58649b9..47ba5a3 100644 --- a/Tetris.sln +++ b/Tetris.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris.csproj", "{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTetris", "..\TestTetris\TestTetris\TestTetris.csproj", "{9F341BB7-7176-4DD4-8CE3-528C31F616F4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTetris", "..\TestTetris\TestTetris.csproj", "{2924F978-4A50-4B23-BCEC-6AB822F236AE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -14,9 +14,9 @@ Global {1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.ActiveCfg = Release|Any CPU {1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.Build.0 = Release|Any CPU - {9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Release|Any CPU.Build.0 = Release|Any CPU + {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal