Archived
1
0
Fork 0

Add suport of color into Tetrominoe parser

This commit is contained in:
Ethanell 2022-05-04 10:13:58 +02:00
parent 00dd266cf6
commit 3f03709cea
2 changed files with 41 additions and 10 deletions

View file

@ -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<String> List() {
return content.Properties().Select(p => p.Name).ToList();
}

View file

@ -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"
}
"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"
}
}