From 3f03709cea7ceca8b2abc6dff10636894802d441 Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 4 May 2022 10:13:58 +0200 Subject: [PATCH] Add suport of color into Tetrominoe parser --- Models/TetrominoeParser.cs | 14 ++++++++++++-- Resources/tetrominoes.json | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Models/TetrominoeParser.cs b/Models/TetrominoeParser.cs index 80834dc..0291595 100644 --- a/Models/TetrominoeParser.cs +++ b/Models/TetrominoeParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; @@ -18,11 +19,11 @@ public class TetrominoeParser { } } - public static bool[,] Get(String name) { + public static bool[,] GetShape(String name) { if (!content.ContainsKey(name)) throw new Exception("Invalid name"); - String s = content.GetValue(name).ToString(); + String s = content[name]["shape"].ToString(); int width = s.IndexOf('\n'); if (width < 0) @@ -48,6 +49,15 @@ public class TetrominoeParser { return g; } + public static Color GetColor(String name) { + if (!content.ContainsKey(name)) + throw new Exception("Invalid name"); + + String s = content[name]["color"].ToString(); + + return ColorTranslator.FromHtml(s); + } + public static List List() { return content.Properties().Select(p => p.Name).ToList(); } diff --git a/Resources/tetrominoes.json b/Resources/tetrominoes.json index e5b24cd..afe81e9 100644 --- a/Resources/tetrominoes.json +++ b/Resources/tetrominoes.json @@ -1,9 +1,30 @@ { - "I": "xxxx", - "J": "x--\nxxx", - "L": "--x\nxxx", - "O": "xx\nxx", - "S": "-xx\nxx-", - "T": "-x-\nxxx", - "Z": "xx-\n-xx" -} \ No newline at end of file + "I": { + "shape": "xxxx", + "color": "#55ffff" + }, + "J": { + "shape": "x--\nxxx", + "color": "#0000ff" + }, + "L": { + "shape": "--x\nxxx", + "color": "#ff5500" + }, + "O": { + "shape": "xx\nxx", + "color": "#ffff00" + }, + "S": { + "shape": "-xx\nxx-", + "color": "#00ff00" + }, + "T": { + "shape": "-x-\nxxx", + "color": "#ff00ff" + }, + "Z": { + "shape": "xx-\n-xx", + "color": "#aa0000" + } +}