Archived
1
0
Fork 0

Setup printable Grid with Tetrominoe and color

This commit is contained in:
Ethanell 2022-04-07 12:35:51 +02:00
parent 0b5114290e
commit 6473e22447
4 changed files with 30 additions and 9 deletions

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using Pastel;
using Color = System.Drawing.Color; using Color = System.Drawing.Color;
namespace Tetris.Models; namespace Tetris.Models;
@ -35,10 +36,25 @@ public class Grid {
public override string ToString() { public override string ToString() {
String s = ""; String s = "";
for (uint y = 0; y < _grid.GetLength(1); y++) { for (uint y = 0; y < _grid.GetLength(1); y++) {
for (uint x = 0; x < _grid.GetLength(0); x++) for (uint x = 0; x < _grid.GetLength(0); x++) {
s += _grid[x,y].Name + "\t"; s += "x".Pastel(_grid[x, y]);
}
s += "\n"; s += "\n";
} }
return s; 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();
}
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using Pastel;
namespace Tetris.Models; namespace Tetris.Models;
@ -56,7 +57,7 @@ public class Tetrominoe {
private Color _color; private Color _color;
public Color Color { public Color Color {
get; get => _color;
} }
public Tetrominoe(Grid grid, bool[,] shape, Point coordinates, short orientation, Color 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 y = 0; y < Shape.GetLength(1); y++) {
for (uint x = 0; x < Shape.GetLength(0); x++) for (uint x = 0; x < Shape.GetLength(0); x++)
if (Shape[x, y]) if (Shape[x, y])
s += "x"; s += "x".Pastel(_color);
else else
s += " "; s += " ";
s += "\n"; s += "\n";

View file

@ -7,4 +7,8 @@
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Pastel" Version="3.0.0" />
</ItemGroup>
</Project> </Project>

View file

@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris.csproj", "{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris.csproj", "{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.Build.0 = 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 {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F341BB7-7176-4DD4-8CE3-528C31F616F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {2924F978-4A50-4B23-BCEC-6AB822F236AE}.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}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal